Level 0: Foundation
★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.Clean up, then keep score
A detector usually fires several boxes on the same object. Non-maximum suppression keeps the most confident box and throws away others that overlap it too much. To grade the detector, we then sort all its boxes by confidence and walk down the list, checking each against the true objects: a hit if it overlaps an unclaimed object enough, a miss otherwise. Precision (how many of our boxes are right) and recall (how many objects we found) trace a curve, and the area under it is the average precision. Averaging that over object classes gives mAP.
Every reported detector number is a mAP, and every deployed detector has an NMS threshold. Choosing them badly hides or creates errors, for example in crowded scenes such as traffic, crowds or parked aircraft.
- 1. NMS removes…
- 2. Average precision is the area under…
- 3. mAP averages AP over…
Level 1: Beginner
★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.By hand
-
IoU: for (0, 0, 4, 4) and (2, 2, 6, 6) the intersection is 4 and the union 28, so IoU = 4/28 ≈ 0.143.
-
Greedy NMS:
- Sort the boxes by score.
- Keep the top one.
- Remove every remaining box with IoU above the threshold (usually 0.5) with it.
- Repeat.
Soft-NMS instead multiplies overlapping scores by exp(−IoU²/σ).
-
Precision and recall: with 8 true positives, 2 false positives and 10 objects, P = 0.8 and R = 0.8.
-
AP (all-point interpolation):
- Rank the detections.
- Compute P and R after each one.
- Make precision monotone, the maximum to its right.
- Sum the area over the recall steps.
Hit, miss, hit, hit with 4 objects gives recall 0.25, 0.25, 0.5, 0.75 and AP = 0.25·1 + 0.25·0.75 + 0.25·0.75 = 0.625.
-
COCO metrics:
- AP is averaged over IoU 0.50, 0.55, …, 0.95 (10 thresholds);
- AP50 and AP75 are reported separately;
- AP_S, AP_M and AP_L cover object areas below 32², from 32² to 96², and above 96²;
- at most 100 detections per image.
- 1. COCO AP averages over how many IoU thresholds?
- 2. A COCO 'small' object has area…
- 3. Precision with 8 TP and 2 FP:
Level 2: Intermediate
★★★☆☆ Intermediate⏱ 25 minUndergraduate students and practising engineers.NMS and AP in code
Exercise 1.
- NMS kept two of four boxes at threshold 0.5 and all four at 0.9.
- The precision–recall curve and AP matched the hand calculation (0.625).
Practice.
- torchvision has
torchvision.ops.nmsandbatched_nms, which apply NMS per class. pycocotools(COCOeval) computes the official COCO metrics; VOC’s metric is AP at IoU 0.5 with all-point interpolation (11-point interpolation before 2010).- Report AP_S, AP_M and AP_L as well as the overall AP. A detector can look fine overall while failing on small objects.
- NMS threshold: 0.5 is typical. Raise it for crowded scenes (pedestrians often use 0.6 to 0.7), or use Soft-NMS or learned NMS-free detectors (DETR, YOLOv10).
- Evaluation pitfalls: “difficult” or “crowd” annotations are ignored, the detection cap is 100 per image, and duplicates count as false positives.
keep = torchvision.ops.batched_nms(boxes, scores, labels, iou_threshold=0.5)
from pycocotools.cocoeval import COCOeval
E = COCOeval(coco_gt, coco_dt, "bbox"); E.evaluate(); E.accumulate(); E.summarize() # AP, AP50, AP75, AP_S, AP_M, AP_L- 1. Per-class NMS in torchvision:
- 2. Official COCO evaluation library:
- 3. A duplicate detection of a matched object counts as…
Level 3: Advanced
★★★★☆ Advanced⏱ 25 minGraduate level, with full derivations and proofs.Theory
Why NMS, and its failure in crowds. Dense detectors fire on many nearby anchors, and NMS keeps local maxima of score. It is a heuristic with one global threshold:
- too low, and it deletes genuinely different objects that overlap (people in a crowd, parked cars);
- too high, and duplicates survive as false positives.
Soft-NMS keeps overlapping boxes with reduced scores, so a real neighbour can still be ranked above false positives. That usually raises AP by about 1 to 2 points on COCO. Learned alternatives remove NMS entirely.
What AP measures.
- AP summarises the trade-off between precision and recall over all score thresholds, so it does not depend on choosing one threshold.
- Interpolation (taking the maximum precision to the right) removes the sawtooth of the raw curve.
- AP at one IoU threshold ignores how precise the boxes are beyond that threshold; averaging over IoU 0.5–0.95 rewards precise localisation. Exercise 2 shows a detector can lose little AP50 but half its COCO AP.
Anchors and IoU, revisited.
- Anchors (E9-4) are matched to objects by IoU thresholds.
- Box losses based on IoU (E9-9) align training with evaluation.
- Evaluation’s IoU threshold sets how strict “correct” is; for safety-critical systems the operating point (precision at a needed recall) matters more than mAP.
- 1. A too-low NMS threshold in crowds…
- 2. Soft-NMS…
- 3. COCO AP rewards…
Level 4: Expert
★★★★★ Expert⏱ 30 minResearchers: original papers and open problems.How do NMS and the metric interact?
History.
- M. Everingham et al. (2010) defined the PASCAL VOC challenge and its AP at IoU 0.5.
- T.-Y. Lin et al. (2014) introduced COCO, with AP averaged over IoU 0.5–0.95 and size categories.
- N. Bodla, B. Singh, R. Chellappa and L. Davis (2017) introduced Soft-NMS.
- J. Hosang, R. Benenson and B. Schiele (2017) proposed learning NMS.
Exercise 2. The data are 30 synthetic images, each with 8 objects in overlapping pairs (offset by 30–60% of their width). The detector output has 3 noisy detections per object with falling scores, plus false positives. We apply NMS at three thresholds and Soft-NMS (σ = 0.5), and compute AP at IoU 0.5 and COCO-style AP. We also repeat NMS at 0.5 with less precise boxes (jitter 5 instead of 2 pixels).
| post-processing | AP at IoU 0.5 | COCO AP (0.5:0.95) |
|---|---|---|
| NMS 0.3 | 0.725 | 0.523 |
| NMS 0.5 | 0.996 | 0.724 |
| NMS 0.7 | 0.965 | 0.710 |
| Soft-NMS | 0.992 | 0.744 |
| NMS 0.5, less precise boxes | 0.887 | 0.356 |
- A low threshold deletes real neighbours (AP50 0.73), and a high one keeps duplicates.
- Soft-NMS had the best COCO AP in all three seeds (0.744, 0.737, 0.737 against 0.724, 0.729, 0.723 for NMS 0.5), a small but consistent gain.
- Localisation matters for COCO AP: less precise boxes lost only 0.11 of AP50 but half of COCO AP. Two detectors with similar AP50 can differ greatly in box quality.
Evaluation in AI, robotics and aerospace
- Crowded scenes: pedestrian, vehicle and aircraft-apron detection need higher NMS thresholds, Soft-NMS or NMS-free detectors.
- Operating points: for a safety system, report recall at the precision you can tolerate, and per-size AP, not only overall mAP.
- Aerial imagery: small objects dominate, so AP_S and the IoU threshold matter; a 1-pixel shift is a big IoU change for a 10-pixel car.
References
- M. Everingham, L. Van Gool, C. K. I. Williams, J. Winn, A. Zisserman (2010). “The PASCAL visual object classes (VOC) challenge.” IJCV 88.
- T.-Y. Lin et al. (2014). “Microsoft COCO: common objects in context.” Proc. ECCV.
- N. Bodla, B. Singh, R. Chellappa, L. S. Davis (2017). “Soft-NMS: improving object detection with one line of code.” Proc. ICCV.
- J. Hosang, R. Benenson, B. Schiele (2017). “Learning non-maximum suppression.” Proc. CVPR.