What is Mean Average Precision (mAP), and how is it calculated for detection?
mAP summarizes detection quality in one number. For each class you rank detections by confidence, use an IoU threshold to label each as correct or not, trace the precision-recall curve, and take its area (the Average Precision). Averaging AP over all classes gives the mAP. 'mAP@0.5' uses a 0.5 IoU cutoff; 'mAP@0.5:0.95' averages over cutoffs from 0.5 to 0.95 for a stricter score.
mAP is the number everyone compares detectors on, so it's worth understanding what it actually measures.
Building it up
- Sort all detections for a class by confidence, high to low.
- Mark each a true positive (IoU with a ground-truth box over the threshold) or a false positive.
- As you walk down the list, plot precision vs recall - that's the PR curve.
- Average Precision (AP) is the area under that curve.
- mAP is the mean of AP across all classes.
The IoU threshold decides how strict 'correct' is. mAP@0.5 (the old PASCAL VOC metric) is forgiving. mAP@0.5:0.95 (the COCO metric) averages ten thresholds and punishes loose boxes, so it's the tougher, more informative number.
from ultralytics import YOLO
model = YOLO("runs/detect/train/weights/best.pt")
metrics = model.val()
print(metrics.box.map) # mAP@0.5:0.95
print(metrics.box.map50) # mAP@0.5
print(metrics.box.maps) # per-class mAP - find the weak classesRelated questions
Stuck on this in a real project?
Book a free call and I’ll give you a straight answer on your specific case.
Book a consultation