Object Detection Metrics Explained: Precision, Recall, mAP & IoU for Inspection

Object detection metrics for inspection: how IoU, precision, recall, PR curves and mAP work, and how to test a detector on your own defect set before…

Object Detection Metrics Explained: Precision, Recall, mAP & IoU for Inspection
Written by TechnoLynx Published on 11 Jul 2026

Object detection accuracy covers two separate questions: did the model classify the object correctly, and did it localise the box well. IoU decides whether a predicted box counts as a hit. Precision and recall count hits, false alarms and misses at one confidence threshold. The precision-recall curve shows every threshold at once, and AP and mAP compress that curve into a single number. None of these numbers on its own tells you whether a detector is ready for an inspection line. That call rests on results per defect class on your own held-out images, at the confidence threshold you will actually run, with the errors broken down by type.

How IoU Decides Whether a Predicted Box Counts as a Detection

Intersection over Union (IoU) is the area where the predicted box and the ground-truth box overlap, divided by the area the two boxes cover together. An IoU of 1 is a perfect match, and 0 means the boxes do not overlap at all. To score a detector, each prediction’s IoU is compared with a preset threshold, usually 0.5: above it, the object counts as detected; below it, the object counts as missed. In standard benchmarks, an IoU above roughly 0.5 to 0.6 is treated as a correct detection.

The IoU threshold is a parameter the evaluator sets, not a property of the model. A prediction that lands at IoU 0.45 against a 0.5 threshold is counted as a false positive, and the defect it was aimed at is still counted as a false negative. Hoiem et al. (2012) call target-category boxes with an overlap between 0.1 and 0.5 localisation errors.

Small defects make this harsher than it looks. Take a scratch annotated as a 10 × 10 pixel box, with a prediction of the same size shifted 2 pixels sideways: the intersection is 8 × 10 = 80 pixels and the union is 100 + 100 − 80 = 120, so IoU is 0.67. Shift it 2 pixels in both directions and the intersection drops to 64, the union rises to 136, and IoU falls to 0.47, below the usual cut-off.

Which IoU rule your line needs depends on what the box is for. If the line only has to decide “defect present on this part”, a 0.5 rule is a reasonable test of whether the model is looking at the right spot. If the box feeds a measurement (Cognex gives the example of a part failing on one defect over 10 mm² or two over 5 mm²), Cognex notes that a deep learning system does not necessarily give accurate pixel measurements.

Precision or Recall: Which One Matters More for Defect Inspection?

Recall is the share of ground-truth objects the detector finds (true positives divided by all ground-truth boxes). Precision is the share of predicted boxes that are correct (true positives divided by true positives plus false positives). Pushing recall up often means predicting more boxes, adding false positives that lower precision. Which one to favour depends on what a false positive costs compared with a false negative in the application.

On an inspection line, the costs have names. Cognex frames them as overkill and underkill: the cost of scrapping good parts against the cost of defects escaping, weighed together to judge whether a solution is worth having. Roboflow’s guidance points both ways depending on the system: a station that rejects products automatically may need high precision so it does not throw away good items, while missing-component inspection is a case where recall comes first.

Our rule of thumb follows from that. Where a missed defect reaches a customer or a safety-relevant assembly, recall on that defect class should be a floor the model must meet, with as much precision as possible above that floor. Where detections go to a human re-check rather than straight to the scrap bin, a false positive costs operator time rather than a part, so lower precision is easier to live with, though too many false alarms still wear down the people doing the re-checks.

Why Plain Accuracy Is a Misleading Metric for Object Detection

Accuracy needs a count of true negatives, and a detector has no countable set of them: every background region of every image that holds no defect is a potential negative. In sliding-window detectors, the Object Detection in 20 Years survey notes that background windows can outnumber objects by as much as 10⁷ to 1. Precision and recall are built from true positives, false positives and false negatives only.

Accuracy also misleads when inspection is treated as a part-level good/bad decision. If 1% of parts are defective, a model that passes every part scores 99% accuracy and catches no defects at all. Saito and Rehmsmeier (2015) show the same blind spot in a worked example: accuracy reads 0.6 on both a balanced and an imbalanced dataset, while precision falls from 0.6 to 0.33 on the imbalanced one. ROC curves carry a milder version of the problem, since the false positive rate stays low simply because true negatives are plentiful when positives are rare. The precision-recall baseline, by contrast, moves with prevalence: it sits at 0.09 for a 1:10 positive-to-negative ratio, which makes poor performance on the rare class visible.

How inspection pilots over-promise on accuracy is covered in why CV inspection pilots over-promise on accuracy.

Reading a Precision-Recall Curve to Choose a Confidence Threshold

A detector gives every box a confidence score between 0 and 1, and only boxes scoring above the chosen threshold count as detections. Raising the threshold increases precision and lowers recall. Each threshold picks out one point on the precision-recall curve, and lowering the threshold moves along the curve towards higher recall. The movement is not perfectly smooth: lowering the threshold either raises recall or leaves it unchanged, but precision can go up and down along the way.

AP summarises the whole curve, so it does not suggest a confidence threshold for running the detector. The operating point has to be chosen separately, and per class. Oksuz et al. (2018) report that for the “bus” class, whose best threshold was 0.27, per-class thresholds improved AP by 8.7% over a common 0.5 threshold. On an inspection line, a faint hairline crack and an obvious missing screw are unlikely to share one sensible threshold.

One way to choose is to turn the error costs into a business metric, compute it at every possible cut-off, and pick the best. In scikit-learn’s cost-sensitive example, the best threshold lands well below 0.5, accepting much lower precision in exchange for much higher recall. The same documentation warns that this estimate can be unreliable when the minority class has very few examples, and that offline results should ideally be confirmed on live data. Rare defect classes are exactly that situation.

One tooling detail catches people out. In Ultralytics validation, the summary precision and recall are reported at the confidence that maximises F1, so they can differ from the precision and recall at the threshold you will deploy. Read the numbers at your operating threshold, not the ones in the summary line.

[email protected], [email protected]:0.95 and COCO AP Are Not Interchangeable

AP is the area under one class’s precision-recall curve, and mAP averages AP across classes. The COCO evaluation makes no distinction between AP and mAP and expects the meaning to be clear from context. The variants differ in their IoU rule or in how results are split:

Metric IoU rule What it rewards Watch for
[email protected] (PASCAL VOC metric) One threshold, 0.5 Finding objects roughly in the right place Forgiving on box placement
[email protected] One threshold, 0.75 Boxes closer to the ground truth COCO calls it the strict metric
[email protected]:0.95 (COCO primary AP) Mean over 10 thresholds, 0.50 to 0.95 in steps of 0.05 Better localisation Averages over all classes
Size-split mAP (small, medium, large) COCO area ranges Shows whether small objects drag results down Available in Ultralytics through save_json=True
Per-class AP Any of the above, per category Shows the class that matters Ultralytics exposes it as metrics.box.maps

Three caveats apply to all of them. First, the same detections can give different AP values depending on the implementation: Padilla’s toolkit shows 11-point interpolation giving AP = 88.64% against 89.58% for all-point interpolation on identical detections. Padilla et al. (2021) argue that differences in box formats and metric definitions often make comparisons between published results confusing and misleading. A vendor’s mAP and your mAP are only comparable if they were computed the same way.

Second, Oksuz et al. (2018) point out that AP cannot tell apart precision-recall curves that look very different, and that it does not directly measure how tight the boxes are. Third, a model can report a high overall mAP while performing poorly on a rare but important class. When the critical defect is also the rarest one, averaging hides it.

Break the Errors Down Before Trusting a Single mAP

A single mAP tells you how much is wrong; only an error breakdown tells you what is wrong. The COCO evaluation’s own analysis of a ResNet detector shows how much a single number hides. AP at IoU 0.75 was .399, perfect localisation would raise it to .682, removing class confusions would take it only to .713, and removing background false positives would lift it to .870, with the rest being missed detections.

The order in which errors are removed changes the story. Hoiem et al. (2012) found that removing all background false positives gave surprisingly small gains (0.02 AP for animal classes), with better localisation or better separation of similar categories offering the largest gains. The TIDE authors (Bolya et al., 2020) explain one reason for such disagreements: COCO removes errors progressively, and that misrepresents how much each error type weighs. TIDE instead measures each error’s effect on mAP from the original model’s performance. Under progressive removal, once most false positives are fixed, each further change in precision is much larger.

Missed detections deserve their own look. Hoiem et al. set out to explain why detectors of the time missed 30 to 40% of objects even at low confidence thresholds, and found size to be the best single explanation. Labels matter too: in TIDE’s manual review of COCO, half of the sampled background errors traced back to bad annotations. Misannotated ground truth lowers the highest mAP a reasonable model can reach. On a defect set labelled by several inspectors, we would audit the boxes on the test split before reading any metric off it. Hoiem et al. also warn more generally that large improvements in one aspect of recognition can show up as small overall gains and go unnoticed without this kind of analysis.

How to Evaluate an Object Detection Model on Your Own Defect Set Before Release

Public benchmark scores and a vendor’s validation figures describe someone else’s data. The test that matters runs on your parts, your lighting and your defect mix, and the steps below have to run in order. Why models trained elsewhere fall short on that data is covered in why off-the-shelf computer vision models fail in production.

  1. Hold out a test set the model has never seen. Roboflow suggests a 70/20/10 train/validation/test split as a starting point, with the test set reserved for the final evaluation. We would draw it from production images across shifts, batches and camera states, not from the same capture session as the training data.
  2. Audit the test labels. Misannotations cap the achievable mAP, so check them before trusting any score.
  3. Fix the IoU rule to what the line needs. Use 0.5 for presence decisions, and something stricter, or a separate measurement step, where the box drives a size-against-spec decision.
  4. Compute per-class AP, size-split AP and per-class PR curves. Ultralytics exposes per-category mAP50-95 through metrics.box.maps and size-split mAP with save_json=True.
  5. Choose an operating threshold per class from error costs. Compute the cost metric at every cut-off and pick the best, separately for each class.
  6. Re-run at that threshold and read per-image counts. Ultralytics validation stores precision, recall, F1, TP, FP and FN per image at IoU 0.5. Images with false negatives on the critical class are your failure catalogue.
  7. Break the errors down by type. Use defined error types, as TIDE does, to isolate what to improve and show the model’s strengths and weaknesses.
  8. Check real production images and latency on target hardware. Roboflow checks mAP@50-95, per-class AP and predictions on real production images before deploying, and tests latency on the target hardware when comparing models.
  9. Write the pass criteria down as a release gate. Re-run the same harness, with the same split, IoU rule and thresholds, on every model update.

We treat that harness as a reliability artefact in its own right, distinct from the accuracy number: production detectors regress through silent drift after updates and through failures on rare classes, and an evaluation suite with a release gate is what catches those before the line does. Building that kind of task-specific evaluation and validation package for vision workloads is part of our computer vision engineering work.

The threshold itself can stay uncertain. With very few examples of a critical defect, the offline estimate is unreliable and should ideally be confirmed on live data. The figure we would sign off is not mAP. It is recall on the class that must never escape, at the threshold the line actually runs, on images the model has never seen, with every miss explained. What that recall then means for line throughput is a separate question, picked up in how computer vision improves OEE in practice.