Lesson 5.5advanced3 h

Object detection

Where is it, and what is it — IoU, anchors, NMS, mAP and DETR

Detection turns a classifier into something that can count cars, find tumors, read shelves or steer a robot: for every object, a box and a label. It introduces ideas you will reuse everywhere — IoU and non-maximum suppression, multi-scale feature pyramids, the foreground/background imbalance that focal loss fixes, and DETR's set-prediction view that connects vision to transformers (7.1 Attention Is All You Need: the big picture). It is also the task where evaluation (mAP) is subtle enough that computing it by hand once pays off for life.

You'll be able to

  • Compute IoU, run non-maximum suppression and compute average precision by hand
  • Explain the two-stage lineage (R-CNN → Fast → Faster R-CNN with RPN and anchors) and the one-stage family (YOLO, SSD, RetinaNet)
  • Derive why focal loss handles the foreground/background imbalance
  • Describe feature pyramid networks and DETR's bipartite-matching set prediction
  • Train a detector on a custom dataset with a modern library

Key ideas

  1. IoU = |A∩B| / |A∪B| decides whether a detection counts (≥ 0.5 in VOC; averaged over 0.5–0.95 in COCO).
  2. Two-stage: R-CNN (2k proposals, 47 s) → Fast R-CNN (shared features, RoI pooling) → Faster R-CNN (RPN with anchors; box deltas t_x = (x−x_a)/w_a, t_w = log(w/w_a)).
  3. One-stage: YOLO/SSD predict from a grid in a single pass; focal loss FL = −(1−p_t)^γ log p_t removes the easy-background flood (p_t = 0.99 is down-weighted 10⁴× at γ = 2).
Show 4 more key ideas
  1. FPN merges top-down semantics with lateral resolution to detect objects at all scales.
  2. NMS keeps the highest-scoring box and suppresses same-class boxes with IoU above a threshold; DETR avoids it by construction.
  3. AP is the area under the interpolated precision–recall curve over ranked detections; mAP averages over classes (and IoU thresholds for COCO).
  4. DETR treats detection as set prediction: object queries + Hungarian matching, no anchors or NMS; its descendants top COCO, YOLO dominates deployment.

Suggested path through this lesson