Sub topic 9
COCO-Style mAP: Averaging Over IoU Thresholds and Object Sizes
This chapter assumes you know bounding boxes, confidence scores, IoU, true positives, false positives, precision, recall, and average precision (AP). We will focus on how the COCO evaluation protocol combines these ideas into a set of detection metrics.
Why COCO uses several IoU thresholds
A detector can find the correct object but place its box loosely. An IoU threshold of 0.50 may count that prediction as correct, while a threshold of 0.75 may reject it. Measuring only one threshold hides this difference.
COCO-style AP evaluates IoU thresholds from 0.50 through 0.95 in steps of 0.05:
thresholds = [0.50 + 0.05 * i for i in range(10)]
print(thresholds)
# [0.5, 0.55, 0.6, 0.65, 0.7, 0.75, 0.8, 0.85, 0.9, 0.95]For each threshold, the evaluator:
- Sorts detections by confidence score.
- Matches detections to ground-truth boxes using the threshold.
- Computes precision and recall.
- Builds the precision-recall curve.
- Computes AP.
The final COCO AP is the mean of these AP values. A detector therefore needs both good recognition and accurate localization.
What the reported metrics mean
COCO reports several related metrics. The exact evaluator also averages over object classes and uses a fixed recall sampling procedure.
| Metric | Meaning |
|---|---|
| AP | Mean AP over IoU 0.50 to 0.95, usually with up to 100 detections per image |
| AP50 | AP at IoU = 0.50 |
| AP75 | AP at IoU = 0.75 |
| APs | AP for small objects |
| APm | AP for medium objects |
| APl | AP for large objects |
| AR | Average recall under a specified detection limit |
The main AP value uses 101 recall points from 0.00 through 1.00. At each recall point, the evaluator uses the highest precision observed at that recall or any larger recall. This creates a precision envelope and prevents a later precision drop from lowering an earlier point.
COCO also averages results across classes. If a dataset contains cats, dogs, and cars, it computes AP for each class and then takes their mean. A class with many examples does not automatically receive more weight than a class with few examples.
Object-size ranges
Small objects are harder to detect because a few pixels can change their box overlap substantially. COCO separates objects by their annotated area in pixels:
- Small: area less than \(32^2\)
- Medium: area from \(32^2\) through \(96^2\)
- Large: area greater than \(96^2\)
The area is measured from the ground-truth box, not from the predicted box. A box with width 20 and height 20 has area 400, so it belongs to the small category.
Size-specific metrics help diagnose a model. For example, a model may have strong APl but weak APs because its feature map loses detail at small scales. APs, APm, and APl are separate evaluations, not components that are averaged into the main AP.
Detection limits and ignored annotations
COCO evaluates different maximum detection counts, commonly 1, 10, and 100 detections per image. The headline AP usually uses a maximum of 100. A model that produces many low-confidence boxes cannot improve the score after this limit.
Some annotations can be marked as crowd regions or ignored for a particular evaluation. Detections that overlap ignored regions may be excluded instead of counted as false positives. This behavior is part of the protocol and is one reason a hand-written evaluator may not exactly reproduce an official COCO score.
The complete evaluation can be viewed as a grid:
Pascal VOC versus COCO
Pascal VOC commonly reports AP50, using one IoU threshold of 0.50. Older VOC versions also used an 11-point interpolation rule. COCO uses ten IoU thresholds, 101 recall samples, object-size ranges, and detection limits.
Consequently, a detector can have a high AP50 but a much lower COCO AP. That result usually means it finds the right objects but predicts boxes that are not precise enough at stricter overlaps.
When comparing published numbers, check the dataset split, class set, IoU range, interpolation rule, object-size filter, maximum detections, and evaluation implementation. The label “mAP” alone does not specify these choices.
Exercise
A detector has AP50 = 0.82, AP75 = 0.54, and COCO AP@[.50:.95] = 0.48. What does this pattern suggest?
Show answer
It detects many objects well enough to reach IoU 0.50, but its localization becomes unreliable at stricter IoU thresholds. The lower COCO AP reflects that weakness across thresholds from 0.50 to 0.95.