Skip to content
elevatedevco

Cheat sheet · Computer Vision

Object Detection & Segmentation cheat sheet

The key ideas on one page — plus common pitfalls and interview tips. Skim it before an interview, or print it for revision.


Cheat sheet

A dense, current (2026) reference covering detection paradigms (two-stage, one-stage, DETR/query-based), segmentation types (semantic, instance, panoptic), the metrics that matter (IoU, mAP, PQ, mIoU, Dice), and the loss, post-processing, label-assignment, and deployment details interviewers probe.

Task Taxonomy & Core Concepts

  • Detection = localize + classify objects via bounding boxes; output is a variable-length set of (box, class, score).
  • Semantic segmentation: per-pixel class label, no instance separation (all 'car' pixels share one mask).
  • Instance segmentation: a per-pixel mask PER object instance (separates two overlapping cars); typically detection + masks.
  • Panoptic segmentation: unifies semantic ('stuff' — sky, road, amorphous regions) and instance ('things' — car, person — countable) into one labeling where every pixel gets (class, instance_id).
  • Anchor-based vs anchor-free: anchors are pre-defined box priors at each location (Faster R-CNN, RetinaNet, SSD); anchor-free predicts boxes directly from points/centers (FCOS, CenterNet, YOLOX).
  • Canonical decomposition: Backbone (feature extractor) → Neck (FPN/PAN for multi-scale fusion) → Head (classification + box and/or mask).

Detection Architectures

  • Two-stage (Faster R-CNN): RPN proposes regions → RoIAlign pools fixed-size features → classify + refine. High accuracy, slower; RoIAlign fixes RoIPool's quantization misalignment via bilinear sampling at floating-point coordinates.
  • One-stage (YOLO family, SSD, RetinaNet): dense prediction over feature-map locations in a single pass. RetinaNet's Focal Loss addressed the extreme foreground/background imbalance that hurt dense detectors.
  • Modern YOLO (v8–v12 era, Ultralytics): anchor-free, decoupled head, task-aligned label assignment; strong real-time speed/accuracy tradeoff and a common production baseline.
  • DETR & Deformable DETR: transformer encoder-decoder with learned object queries + bipartite (Hungarian) matching — NO NMS, NO anchors; end-to-end set prediction. Deformable attention and DINO-style denoising fixed DETR's slow convergence and weak small-object performance.
  • Open-vocabulary / promptable: SAM / SAM 2 (promptable segmentation, incl. video), Grounding DINO, YOLO-World, OWL-ViT enable text-prompted, zero-shot detection/segmentation — a standard 2026 interview topic.
  • FPN gives multi-scale features: small objects use high-resolution shallow maps, large objects use deep semantic maps; PAN adds a bottom-up path for better low-level signal flow.

Segmentation Architectures

  • FCN: first fully-convolutional per-pixel net; replaced FC layers with conv + learned upsampling (transposed conv).
  • U-Net: encoder-decoder with skip connections concatenating low-level detail into upsampled features; dominant in medical/limited-data settings.
  • DeepLab v3+: atrous (dilated) convolution + ASPP (atrous spatial pyramid pooling) to capture multi-scale context without downsampling away resolution.
  • Mask R-CNN: Faster R-CNN + a parallel FCN mask branch on RoIAlign features; long-standing instance-segmentation baseline.
  • MaskFormer / Mask2Former: reframe semantic, instance, and panoptic as MASK CLASSIFICATION with transformer queries (masked attention) — one architecture, all three tasks, state of the art.
  • SAM / SAM 2: promptable, class-agnostic segmentation across images and video with a memory module; pair with a classifier or grounding model to assign labels.

Metrics & Evaluation

  • IoU (Jaccard) = area(intersection)/area(union) — core overlap metric for both boxes and masks.
  • A prediction is a TP if IoU >= threshold AND class is correct; precision-recall is built by sweeping the confidence threshold.
  • AP = area under the precision-recall curve for one class; mAP = mean AP over classes.
  • COCO mAP (the headline 'AP') averages over 10 IoU thresholds 0.50:0.05:0.95; also reports AP50, AP75, and AP_small/medium/large.
  • Panoptic Quality PQ = SQ × RQ = (Σ_TP IoU / |TP|) × (|TP| / (|TP| + 0.5|FP| + 0.5|FN|)); matches require IoU > 0.5.
  • Semantic segmentation: mean IoU (mIoU) over classes (primary), plus pixel accuracy and Dice/F1 = 2|A∩B|/(|A|+|B|), common in medical imaging.
  • AP is matching-sensitive: predictions are sorted by confidence and greedily matched to GT; a 2nd detection on an already-matched GT counts as a FP (penalizing duplicates).

Losses & Post-processing

  • Classification: Cross-Entropy; Focal Loss FL = -alpha * (1 - p_t)^gamma * log(p_t) down-weights easy examples (gamma≈2, alpha≈0.25) for dense detectors.
  • Box regression: Smooth L1 / L1, or IoU-family losses (GIoU, DIoU, CIoU) that optimize overlap directly and give gradients even for non-overlapping boxes.
  • Segmentation losses: per-pixel CE, Dice loss (robust to class imbalance), Lovász-Softmax (directly optimizes IoU), and combos (CE + Dice) for small-foreground/medical tasks.
  • NMS removes duplicate boxes: sort by score, keep the top box, drop others with IoU > threshold; run it PER class. Soft-NMS decays overlapping scores instead of hard removal for crowded scenes.
  • Label assignment decides positives: IoU thresholds (anchor-based), center sampling (FCOS), or dynamic/optimal-transport assignment (SimOTA in YOLOX, TaskAligned in modern YOLO).
  • DETR/Mask2Former skip NMS — Hungarian one-to-one matching enforces uniqueness at training time, so each object is predicted once.

Training, Data & Deployment

  • Augmentation: mosaic, mixup, random scale/crop, color jitter, and copy-paste (especially powerful for instance seg) boost robustness and small-object recall.
  • Class imbalance is structural in detection (background dominates): handle via focal loss, hard-negative mining, or balanced/OHEM sampling.
  • Transfer learning: backbone pretrained on ImageNet/COCO, then fine-tune on target domain. Self-supervised backbones (DINOv2, MAE) are strong 2026 defaults.
  • Inference speed: benchmark latency at a fixed input size and batch; use ONNX/TensorRT, FP16/INT8 quantization, and model scaling (nano→x) for edge vs server.
  • Test-time: multi-scale testing and TTA raise mAP at a compute cost; confidence and NMS IoU thresholds are deployment knobs trading precision vs recall.
  • Production eval pitfalls: domain shift, label noise, and tiny/occluded objects — monitor per-class AP and small-object AP, not just headline mAP.