Sub topic 10
Pitfalls: thresholds, duplicates, class imbalance, and comparing numbers
This chapter assumes that you know basic Python, can read detector outputs containing boxes, class labels, and confidence scores, and understand classification precision and recall. The focus here is interpreting mAP correctly rather than computing it from scratch.
A detector's mAP is useful only when you know how it was produced. Small evaluation choices can change the score without changing the model. The most common sources of confusion are confidence thresholds, duplicate detections, class imbalance, and incompatible protocols.
Confidence thresholds and IoU thresholds
Two different thresholds often appear in object detection:
- The confidence threshold decides which predicted boxes are kept.
- The IoU threshold decides whether a kept box matches a ground-truth box.
These thresholds have different jobs. A confidence threshold controls the detector's operating point. Raising it usually removes low-confidence predictions, which can improve precision but reduce recall. Lowering it usually increases recall while also allowing more false positives.
Average precision normally evaluates a ranked list of detections across many confidence thresholds. Therefore, filtering detections before calculating AP can make the result lower than expected. If you keep only predictions with confidence above 0.7, the evaluator cannot see correct predictions that had scores between 0.3 and 0.7.
The IoU threshold controls localization quality. At IoU 0.5, a prediction may count as correct even when its box is fairly loose. At IoU 0.75, the same prediction may become a false positive.
Duplicate detections
A detector can produce several boxes around one object. During matching, one ground-truth box can usually be matched to only one prediction. The highest-scoring matching prediction becomes a true positive. The remaining predictions become false positives, even if they overlap the object well.
Non-maximum suppression, or NMS, reduces these duplicates before evaluation. Standard NMS keeps the highest-scoring box and removes nearby boxes whose IoU with it exceeds an NMS threshold. This threshold is separate from the IoU threshold used to score detections.
NMS can also remove valid nearby objects. For example, two people standing close together may have highly overlapping boxes. Class-aware NMS suppresses boxes only within the same class. Class-agnostic NMS compares boxes from all classes and can incorrectly suppress different objects with different labels.
Duplicate annotations in the ground truth cause a related problem. If the same object is labeled twice, a detector may appear to have a false negative or an unusual matching pattern. Validate annotations before comparing models.
Class imbalance and averaging
mAP is usually a macro average. It gives each class equal weight:
mAP = \frac{1}{C}\sum_{c=1}^{C} AP_cA rare class therefore affects mAP as much as a common class. This is useful when every class matters, but it can hide the system's performance on the classes that occur most often.
Suppose a dataset has two classes:
| Class | Number of objects | AP |
|---|---|---|
| Common object | 1,000 | 0.95 |
| Rare object | 10 | 0.40 |
The mAP is 0.675. That value treats both classes equally. A production system might need a weighted result based on object frequency, but a weighted average answers a different question. Report per-class AP, object counts, and mAP together.
A class with few examples can also have an unstable AP. One missed object may cause a large change in recall. Use a sufficiently large validation set or confidence intervals when making decisions about rare classes.
Comparing mAP numbers
Two mAP values are comparable only when their evaluation settings match. Check these details:
- dataset split and annotation version
- class list and ignored regions
- box coordinate format and image scaling
- confidence filtering and maximum detections per image
- IoU thresholds
- handling of crowd or difficult objects
- object-size categories
- AP interpolation method
Pascal VOC commonly reports AP at IoU 0.5, often written as AP50. COCO-style evaluation averages AP over IoU thresholds from 0.50 through 0.95 in steps of 0.05. COCO mAP therefore penalizes imprecise localization more strongly. A model can have a high AP50 and a much lower COCO-style mAP.
Training losses such as GIoU, DIoU, and CIoU are also not interchangeable with reported mAP. They are box-regression objectives. The evaluator still needs a defined matching protocol, usually based on ordinary IoU.
A safe reporting pattern
When publishing or reviewing a result, include the protocol beside the number:
result = {
"metric": "mAP",
"protocol": "COCO",
"iou_thresholds": "0.50:0.05:0.95",
"max_detections_per_image": 100,
"confidence_filter": "none before evaluation",
}
print(result)This prevents a bare statement such as “the model reaches 42 mAP” from being mistaken for a universal measurement.
Exercise
Exercise
A detector has AP50 = 0.82 and COCO-style mAP = 0.48. Is this necessarily an error, and what should you inspect first?
Show answer
No. COCO-style mAP averages stricter IoU thresholds, so loose boxes can score well at 0.50 but poorly at higher thresholds. First inspect the IoU protocol, confidence filtering, maximum detections, dataset split, and annotation handling.