🎉 75% of content is free forever — Unlock Premium from $10/mo →
CW
NEWSLIVESearch All Content
💼 Servicesℹ️ About✉️ ContactView Pricing Plansfrom $10

Object Detection — YOLO, Faster R-CNN, Anchor Boxes and mAP

Computer VisionDetection🟢 Free Lesson

Advertisement

Computer Vision

Object Detection — Teaching Computers to Find and Identify Objects

Object detection localizes and classifies objects in images, predicting both bounding boxes and class labels. It is one of the most impactful applications of deep learning.

  • YOLO is Real-Time — Single-shot, grid-based prediction enables real-time detection at 30+ FPS
  • Faster R-CNN is Accurate — Two-stage detector with Region Proposal Network for high-precision detection
  • mAP is the Metric — Mean Average Precision over IoU thresholds is the standard evaluation measure

Object Detection — YOLO, Faster R-CNN, Anchor Boxes and mAP

What You'll Learn

  • 1Compute IoU and trace how a precision-recall curve becomes AP and then mAP
  • 2Encode and decode bounding box offsets from anchor boxes in normalized log space
  • 3Compare one-stage detectors such as YOLO against two-stage detectors such as Faster R-CNN
  • 4Apply non-maximum suppression correctly and read the COCO evaluation metrics

Object detection localizes and classifies objects in images, predicting both bounding boxes and class labels. It is one of the most impactful applications of deep learning. A COCO image holds 7.7 objects on average, so the network must emit a variable length set of boxes, classes and confidences rather than a single label, and the training signal must punish localization error, missed objects and false alarms at the same time.


Detection vs. Classification

Object Detection Pipeline🚗🚶Input ImageBackbone(CNN)FeatureExtractionNeck(FPN)Multi-scaleFeaturesHead(Class + Box)PredictionOutput🚗 (0.95)🚶 (0.88)Bboxes +Classes

IoU (Intersection over Union)

IoU is a ratio, so it is invariant to image resolution: a 320 pixel wide box and its 640 pixel copy score the same as long as the shapes match. Detectors are usually scored as correct when IoU reaches 0.5, while the COCO benchmark also counts detections that clear 0.75 for its "primary" subset.

IoU VisualizationGround TruthPredictedIntersectionUnion = Area(GT) + Area(Pred) - IntersectionIoU = 0.9ExcellentIoU = 0.5AcceptableIoU = 0.1Poor

Anchor Boxes

Positions are divided by the anchor size so the network predicts targets of order 1 regardless of object scale, and sizes are logged so that doubling and halving a box produce targets of opposite sign:

Decoding inverts the transform with one exponential per axis, which is why an anchor free head still has to pick a reference scale somewhere:

The regression term itself uses a robust penalty so that a handful of mis-annotated boxes cannot dominate a batch, with smooth L1 that is quadratic below unit error and linear beyond it:


Non-Maximum Suppression (NMS)

Non-Maximum Suppression (NMS)Before NMSCar (0.9)Car (0.8)Car (0.7)Person (0.85)Person (0.6)After NMSCar (0.9) ✓Person (0.85) ✓→

Two-Stage: Faster R-CNN

Faster R-CNN ArchitectureImageBackbone(CNN)FeatureMapRPNRegion ProposalsRoI PoolFixed sizeClass +Box RegDetsStage 1: RPN (proposals) → Stage 2: Classification + Box RegressionTwo-stage: accurate but slower

Single-Stage: YOLO

Each grid cell also predicts objectness, and the class score shipped to evaluation multiplies that objectness by the class probability, so a box is only confident if both terms are large:

With 80 COCO classes and 3 anchors per cell, a grid emits raw values before NMS trims them to the handful of boxes that survive.

YOLO: Single-Shot Detection🚗🚶Input7×7 GridPredictions🚗 (0.95)🚶 (0.88)DetectionsSpeedYOLO: 30+ FPSFaster RCNN: 5 FPSReal-time!

Two-Stage vs Single-Stage

Two-Stage vs Single-Stage DetectorsTwo-Stage• R-CNN, Fast R-CNN, Faster R-CNN• Higher accuracy (mAP)• Slower (2-5 FPS)• Better for small objects• Complex pipeline• Mask R-CNN adds instance segmentationSingle-Stage• YOLO, SSD, RetinaNet• Faster (30+ FPS)• Lower latency• Real-time applications• Focal loss for class imbalance• YOLOv8: state-of-the-art speed/accuracy

Evaluation: mAP

COCO averages AP over the nine thresholds 0.50 to 0.95 in steps of 0.05, so the headline number rewards tight boxes as well as correct ones. A YOLOv8-nano scores roughly 55 at [email protected] but about 37 on the averaged metric, and the 18 point gap measures how loose the boxes are.


Summary

  • Object detection predicts bounding boxes + class labels + confidence scores
  • IoU measures overlap between predicted and ground truth boxes
  • Anchor boxes provide reference shapes for regression
  • NMS removes duplicate detections
  • Two-stage (Faster R-CNN): accurate but slower
  • Single-stage (YOLO): faster, real-time capable
  • mAP is the standard evaluation metric

Next: Semantic Segmentation

Common Mistakes

Publishing mAP at a single IoU threshold

Fix: Also report [email protected]:0.95, which averages AP over nine thresholds from 0.50 to 0.95.

Sweeping NMS while leaving the confidence threshold fixed

Fix: AP integrates the full precision-recall curve, so sweep confidence from 0.001 upward and keep NMS IoU near 0.5.

Regressing raw pixel widths and heights

Fix: Encode in log space with t_w = log(w / w_a) so scale errors stay symmetric and decoding is one exponential.

Best Practices

  • Run k-means on ground truth widths and heights to pick anchor aspect ratios for your own dataset
  • Apply NMS per class so that two overlapping classes never suppress each other
  • Log the full precision-recall curve and per-class AP instead of a single headline number

Key Takeaways

  • IoU is intersection area over union area, and a detection counts as correct once IoU reaches 0.5 after NMS
  • Anchor offsets are normalized and logged: t_w = log(w / w_a) makes doubling and halving symmetric targets
  • Two-stage Faster R-CNN buys accuracy at about 5 FPS while single-stage YOLO runs above 30 FPS
  • mAP averages AP over classes and, in the COCO variant, over nine IoU thresholds from 0.50 to 0.95

Frequently Asked Questions

Why does non-maximum suppression use an IoU threshold near 0.5?

NMS deletes every box that overlaps a higher scoring box by more than the threshold. At 0.5 the duplicate boxes produced for one object merge into a single detection, while two people standing side by side, whose boxes rarely overlap past 0.2, both survive. Raise the threshold to 0.9 and three or four boxes per object remain; lower it to 0.1 and adjacent real objects are deleted along with the duplicates.

What exactly does [email protected]:0.95 average over?

COCO computes average precision at IoU 0.50, 0.55, 0.60 and so on up to 0.95, then averages those nine AP values into one score. Because half of the thresholds sit above 0.75, the metric punishes loose boxes even when every object is found, which is why a detector can look perfect at [email protected] and mediocre on the full benchmark.

Why integrate precision over recall instead of picking one confidence threshold?

The confidence threshold is a deployment decision that moves with your false positive budget, while AP measures ranking quality: a detector that scores true positives above false positives earns high AP at every operating point. Two models can be identical at 0.5 confidence and still differ by several mAP points because one ranks its detections better.

Interview Questions

Q1: Walk through how mAP is computed for one class.

Sort detections by confidence, match them greedily to ground truths at IoU 0.5, sweep the threshold to trace precision and recall, integrate to obtain AP for that class, then average AP over classes; COCO repeats the whole average over nine IoU thresholds.

Q2: Why encode width and height offsets in log space?

t_w = log(w / w_a) maps doubling to plus 0.69 and halving to minus 0.69, so the regression target is symmetric around zero and unbounded, while decoding costs a single exponential per axis.

Q3: What goes wrong if you run NMS before sorting boxes by confidence?

NMS is greedy and keeps the highest scoring box in each overlap cluster, so an unsorted pass lets a weak duplicate suppress a better box, corrupting the ranked list that the precision-recall curve is built from and costing several mAP points.

—
☆☆☆☆☆
0 ratings

Rate & Feedback

Need Expert Deep Learning Help?

Get personalized tutoring, project support, or professional consulting.

Advertisement