CSE445Computer Vision
Tutorials/Object Detection/Bounding Boxes, IoU, NMS & mAP
OD-02Beginner 75 min

Bounding Boxes, IoU, NMS & mAP

Build the complete evaluation toolkit from scratch: box format conversions, IoU computation, Non-Maximum Suppression, Precision-Recall curves, and mean Average Precision.

PythonNumPyMatplotlib

Code Structure Note

These notes are provided only to help students understand the code structure. Students should review, optimize, and adapt the code before using it in assignments, projects, or experiments.

Topics Covered
  1. 1Bounding box representation: (x1, y1, x2, y2) vs. (cx, cy, w, h) vs. normalised
  2. 2Intersection over Union (IoU): derivation, edge cases, vectorised computation
  3. 3Confidence thresholding and Non-Maximum Suppression (greedy and Soft-NMS)
  4. 4Precision, Recall, F1 — definitions and the detection-specific TP/FP/FN rules
  5. 5Average Precision (AP), mAP@50, mAP@50-95, and COCO area buckets (S/M/L)

Learning Objectives

  • Convert between all three bounding box formats without looking up the formulas
  • Implement vectorised IoU that processes N×M box pairs in a single NumPy call
  • Write greedy NMS from scratch and explain every hyperparameter
  • Compute AP for a single class by integrating a Precision-Recall curve, then extend to mAP

Key Takeaways

  • IoU ≥ 0.5 is the standard TP threshold in PASCAL VOC; COCO averages over 0.50–0.95
  • NMS requires two separate thresholds: confidence (pre-filter) and IoU (overlap suppression)
  • AP is the area under the 11-point interpolated PR curve; mAP averages AP over all classes
  • APs (small objects, area < 32²) is the hardest COCO metric — most models score under 30

Tutorial Infographic

Notebook Resources

Jupyter Notebook

Student action area

Use this section to practice the tutorial code. Kaggle opens the prepared notebook, Colab lets you experiment in your own runtime, and the .ipynb download is best for local editing or submission.

Kaggle: follow the official tutorial notebook.
Colab: modify and rerun quickly.
IPYNB: keep a local copy.

Hands-On Exercises

  1. 1Implement `compute_iou(boxesA, boxesB)` with NumPy broadcasting for N×M inputs
  2. 2Write `nms(boxes, scores, iou_thresh, score_thresh)` and test on 1 000 synthetic boxes
  3. 3Load COCO val predictions JSON, compute AP for the 'person' class, and plot the PR curve
  4. 4Compare greedy NMS vs. Soft-NMS on an image with overlapping crowd detections

Tools & Libraries

PythonNumPyMatplotlib