#319mAP for Object DetectionHardComputer VisionEvaluation MetricsAsked atMeta · Google · Apple
mAP for Object Detection
Background
Mean Average Precision (mAP) at IoU threshold is the standard object-detection eval. For each class, walk the predicted boxes in score order, match each to the highest-IoU unmatched ground-truth box if , otherwise mark as a false positive. AP is the area under the resulting precision-recall curve; mAP is the average AP across classes.
Problem statement
Implement map_detection(detections, golds, iou_threshold=0.5):
- Group
detectionsandgoldsby class. - For each class:
- Sort detections by score descending.
- Walk through, computing IoU to each gold; if a match and that gold is unmatched, count as TP and mark gold as matched; else FP.
- Compute precision and recall after each row; AP = .
- Return the mean of class APs.
Input
detections—list[tuple[class, score, box]].box = (x1, y1, x2, y2).golds—list[tuple[class, box]].iou_threshold—floatin (default0.5).
Output
Returns a Python float in .
Examples
Example 1 — perfect detection
Input: one detection that exactly matches a single gold box
Output: 1.0
Example 2 — no detections
Input: detections=[], gold present
Output: 0.0
Example 3 — IoU below threshold → no match
Input: detection and gold of same class but disjoint boxes
Output: 0.0
Constraints
- A gold box can be matched at most once across all detections (greedy).
- If a class has no gold, its AP is
0.0. - Returns Python
float.
Notes
- mAP@0.5 vs mAP@[.5:.95]. COCO reports the average mAP across IoU thresholds from 0.5 to 0.95; this kernel implements one fixed threshold.
- Greedy matching. Strict bipartite matching would be optimal but slower; greedy is the standard approximation.
Python
Loading...
▶ Run executes the 3 visible sample tests below in your browser. Submit runs the full suite — including hidden tests — on the server for an official verdict.
- •reference example: perfect detection scores 1.0
- •sample: greedy match uses each gold once
- •reference example: precision-recall curve area