Skip to main content

Object Detection Metrics: Precision, Recall, AP, and mAP

Match detections to objects, inspect precision–recall curves, calculate average precision, and distinguish confidence thresholds from IoU thresholds.

A detector can miss an object, predict the wrong class, draw an inaccurate box, or report the same object several times. Counting “correct images” hides these different errors. Detection metrics instead compare individual predictions with labeled objects and examine how the result changes as more predictions are accepted.

Match before counting

In this example, predictions are processed by decreasing score within each class. Each prediction can match the best still-unmatched ground-truth box of that class if IoU reaches the chosen threshold. A match is a true positive (TP); an unmatched prediction is a false positive (FP). A labeled object without a match is a false negative (FN).

Start with cars at IoU 0.50. Prediction B overlaps the first car, but A has already claimed it. Lower the confidence threshold to include E: recall improves because the second car finally receives a match.

Matching, ranking and one operating point
Evaluation class
0.50
0.50
A 0.95B 0.85D 0.70

Dashed: ground truth. Teal: matched prediction. Amber: unmatched prediction. Only the selected class is evaluated below.

TP / FP / FN
1 / 2 / 1
Precision
0.333
Recall
0.500
car AP@0.50
0.752
Mean AP · two classes
0.876
RecallP1010
Line: interpolated precision envelope. Dot: selected score threshold. AP averages the line at 101 recall levels.
A · 0.95TP → car-a
B · 0.85FP · no unused match
D · 0.70FP · no unused match
E · 0.40TP → car-b · filtered

Authored predictions, calculated metrics. Changing confidence moves the operating point; AP still uses the full ranking. This single-image example omits crowd/ignore handling, area ranges and detection caps. It is not the full COCO evaluation protocol.

Precision and recall describe one operating point

Precision⁡=TPTP+FP,Recall⁡=TPTP+FN\operatorname{Precision}=\frac{TP}{TP+FP},\qquad \operatorname{Recall}=\frac{TP}{TP+FN}

At the initial car settings, three predictions are retained: A is correct, B is a duplicate, and D is misplaced. There are two labeled cars. Precision is therefore 1/3, recall is 1/2, and one car is missed.

Lowering the score threshold to 0.40 adds E. Precision becomes 2/4 = 0.5, and recall reaches 1. Lowering a threshold does not guarantee that precision always decreases; this example adds a true positive after two false positives.

With no retained predictions, precision has a zero denominator and the explorer displays a dash. Recall is zero because the selected class has labeled objects. Handling a class with no ground truth is a different edge case; define that policy before aggregating metrics.

Average precision summarizes a ranking

Sweeping the confidence cutoff traces precision against recall. The explorer constructs an interpolated precision envelope: for each requested recall level, take the best precision achieved at that recall or higher, or zero if it is unreachable. AP is the mean of this envelope at 101 levels from 0 to 1.

For the car ranking at IoU 0.50, the TP/FP sequence is TP, FP, FP, TP. The envelope is 1 through recall 0.5 and 0.5 above it. This gives:

AP=51×1+50×0.5101≈0.752AP = \frac{51\times1 + 50\times0.5}{101} \approx 0.752

The 51 samples include both 0 and 0.5. This discrete convention explains why the value is slightly above the continuous area 0.75. Moving the confidence slider changes the operating point, not the full ranking used for AP.

State which mean you report

At one fixed IoU threshold, the explorer averages car AP and person AP. This is a two-class mean AP for one synthetic image. Raising the IoU threshold can turn a loose match into a false positive, changing both the curve and AP.

COCO's main detection AP additionally averages over IoU thresholds 0.50 through 0.95 in steps of 0.05. Its evaluator also handles crowd/ignored annotations, object-area ranges, and detection caps. The explorer omits those cases and is not a replacement for the benchmark evaluator. COCO evaluation implementation

Compare models without hiding the errors

Report the dataset split, classes, IoU protocol, score filtering, and evaluation implementation with any AP number. For deployment, also examine the chosen operating point: how many objects are missed, and how many false alarms remain under the conditions that matter?

Inspect errors by object size, crowding, lighting, and class. A single mean can hide poor recall for small objects or a class with very few examples. The next useful question is often about the error pattern, not another decimal place in mAP.

If you found this explanation helpful, consider sharing it with others.

Mastodon