Sub topic 12
Evaluating a Detector with Precision, Recall and mAP
Assume you know bounding boxes, intersection over union (IoU), confidence scores, and the basic YOLO inference workflow. This chapter focuses on measuring detector quality, not training the model.
Matching predictions to ground truth
A detector returns predicted boxes, classes, and confidence scores. A labeled validation image contains ground-truth boxes. To evaluate one prediction, match it with an unmatched ground-truth box of the same class when their IoU reaches a chosen threshold.
For example, at IoU 0.5:
- A matching prediction is a true positive (TP).
- A prediction with no matching object is a false positive (FP).
- A ground-truth object with no matching prediction is a false negative (FN).
- A ground-truth object cannot match multiple predictions. Extra overlapping predictions become false positives.
The matching process depends on the confidence threshold and the IoU threshold.
Precision and recall
Precision measures how trustworthy the accepted predictions are:
Precision = TP / (TP + FP)
Recall measures how many real objects the detector finds:
Recall = TP / (TP + FN)
A detector with high precision makes few false alarms. A detector with high recall misses few objects. Raising the confidence threshold usually removes weak predictions, which can increase precision but reduce recall.
| Metric | Question answered | Common failure |
|---|---|---|
| Precision | When the model predicts, how often is it correct? | Too many false alarms |
| Recall | Of all real objects, how many did it find? | Too many missed objects |
| F1 score | How well are precision and recall balanced? | Hides the cost difference between error types |
Average precision and mAP
A single confidence threshold gives only one precision and recall pair. Average precision (AP) evaluates the whole precision–recall curve. The model sorts predictions from highest to lowest confidence, then progressively accepts more predictions. At each point, it records precision and recall. AP summarizes the resulting curve as one number.
Mean average precision (mAP) averages AP across classes. It can also average across multiple IoU thresholds.
Common reports include:
- mAP50: AP averaged over classes at IoU 0.50.
- mAP50-95: AP averaged over IoU thresholds from 0.50 through 0.95, usually in steps of 0.05.
mAP50 is more forgiving about box placement. mAP50-95 rewards both finding the object and placing a tight box around it. Therefore, a large gap between these values often indicates poor localization.
Reading results and finding errors
Inspect per-class AP instead of relying only on one overall number. A low AP for a rare class may result from too little training data. A low recall may indicate small objects, missing labels, or an overly high confidence threshold. A low precision may indicate confusing background patterns or visually similar classes.
Use a validation set that represents real deployment conditions. Keep it separate from training images. After changing the model or dataset, compare the same validation split and evaluation settings.
Exercise
A detector has TP = 80, FP = 20, and FN = 40. What are its precision and recall?
Show answer
Precision = 80 / 100 = 0.80, or 80%. Recall = 80 / 120 = 0.667, or about 66.7%.