Object detection
Boxes, IoU, anchors and queries, a one-stage vs two-stage sketch, detection losses and mAP.
The task: boxes and classes
The topic Convolutional architectures built backbones that turn an image into one label. A street photograph holds many objects, and a detector must list them all: which classes, how many, and where. The answer is a set of bounding boxes with class scores. The set length changes per image, so a fixed-output classifier cannot produce it. Detectors keep the backbones and change the head.
Three things make this harder than classification: the output is a set of unknown size; localization is continuous, so “correct” needs an overlap tolerance; objects span scales from tens to hundreds of pixels, and most of the image is background. Sliding a classifier over every window is correct in principle and hopeless in cost (~ full forward passes per image).
Key idea. Replace “find the objects” by many fixed questions about reference boxes — proposals or anchors. Label each by overlap with the ground truth; classify and regress; remove duplicates.
Intersection over union
Whether a predicted box matches a true one is measured by intersection over union
Axis-aligned intersection has corners and area zero when empty. IoU is for identical boxes and for disjoint ones; it is scale-free.
Worked example: and both have area 16; intersection area 6; . A same-size box shifted by a fraction of its side along one axis has , so threshold allows a third of a side and only a seventh. A 2-pixel error hurts a box () far more than a one ().
Two-stage detectors
The R-CNN line applies the two rescues one at a time.
R-CNN runs ~2000 selective-search proposals, warps each to a fixed size, and classifies with a CNN — accurate for 2014, ~13 s/image on GPU because every proposal is a separate forward pass.
Boxes are predicted as corrections to a reference :
Shifts are relative to the reference size; the log keeps decoded widths positive. Training often uses smooth L1 (Huber) per coordinate.
Fast R-CNN runs the backbone once and RoI-pools each proposal to a fixed grid from the shared feature map; a multi-task loss combines softmax over classes with box regression (off for background).
Faster R-CNN learns proposals with a region proposal network: at each feature location, anchors (3 scales × 3 aspect ratios) get an objectness score and offsets. Anchors with IoU (or best for an object) are positive; IoU negative; the rest ignored. With VGG-16 the system ran ~5 FPS and reached 73.2% mAP on VOC 2007. Feature pyramids later became standard for small objects.
One-stage detectors
A one-stage detector skips the proposal stage and predicts final classes and boxes on the feature map directly.
YOLO divides a image into an grid; each cell predicts boxes (coordinates + confidence) and one set of class probabilities. For VOC, , , → a tensor ( numbers, 98 boxes). Fast (45 FPS) but weaker on localization and on multiple small centres in one cell.
SSD predicts from several feature maps of decreasing resolution with default boxes (anchors) at each cell — fine maps for small objects, coarse for large — and mines hard negatives so background does not dominate.
The shared obstacle: – candidates per image, almost all easy background whose tiny losses still sum to own the gradient.
Focal loss
Focal loss (Lin et al., 2017) reshapes cross-entropy. With the probability of the true class,
At and the factor cuts the loss a hundredfold; at it is only smaller. Easy negatives stop drowning hard positives. RetinaNet applies this to all ~100k anchors on a ResNet feature pyramid (positives at IoU ≥ 0.5, negatives below 0.4), with no sampling, and matched two-stage detectors of its time on COCO.
NMS and mAP
Overlapping predictions for one object are removed by non-maximum suppression per class: sort by score; keep the top box; drop every remaining box with IoU ; repeat. At in the note’s six-box example the survivors are A, D and F. Lower kills crowds; higher leaves duplicates.
Average precision walks detections of one class by decreasing score. A detection is a true positive if its IoU with an unmatched ground-truth box of that class is at least ; a second hit on the same object is a false positive. Precision and recall after each detection form a curve; AP is the area under the interpolated curve; mAP averages AP over classes. VOC uses ; COCO averages and reports that mean as AP. Tight boxes matter for the COCO metric; AP50 alone does not.
Boxes remain a coarse description: a thin pole or an outstretched arm fills little of its rectangle. The next topic, Semantic segmentation, labels every pixel instead — dense prediction with encoder–decoders, skips and mIoU.
Check your understanding
The same questions as in Pulse. Answers are shared between modes.
Go deeper — optional
Code and labs do not count toward the main percentage or the certificate.
- IoU in codeoptional
Compute Intersection over Union for xyxy boxes — the match measure in detection.
~15 min · easier on a computer · The Object detection topic, IoU block.
Answers are saved on the server and tied to this browser until you sign in.