Article sections
Why does the unit of measurement matter?The confusion matrix and its four fundamental countsWhen should F1 and F-beta be used?The difference between ROC-AUC and PR-AUCIoU and matching in object detectionWhat exactly do AP and mAP mean?Segmentation and anomaly metricsHow should results be reported?Field scenarioFour conclusions from the same confusion matrixFrequently asked questionsReferencesWhy does the unit of measurement matter?
First, we must establish which decision we are counting: classification per image, a defect decision per part, the location of a defect object, or a pixel mask. On the same dataset, a model may look good at the pixel level while having a high false rejection rate per product. To interpret the score, the definition of the positive class, the matching rule, and the unit of measurement must therefore be stated explicitly.
In industrial quality control, if 'defective' is the positive class, a false negative means a missed defect. If the label definition is reversed, the same FP/FN symbols describe different operational events. Reports must not leave this semantic ambiguity unresolved.
The confusion matrix and its four fundamental counts
A True Positive (TP) is the correct detection of a defective product; a False Positive (FP) is a non-defective product flagged as defective; a False Negative (FN) is a missed defect; and a True Negative (TN) is a non-defective product correctly accepted. The metrics are calculated as Accuracy=(TP+TN)/N, precision=TP/(TP+FP), recall=TP/(TP+FN), and specificity=TN/(TN+FP).
If only 100 out of 10,000 products have defects, labeling every product as non-defective yields 99% accuracy but catches no defects at all. Accuracy alone is therefore misleading when classes are imbalanced. Particularly at low defect rates, the reliability of positive predictions, or precision, becomes important in terms of operational cost.
When should F1 and F-beta be used?
F1=2×precision×recall/(precision+recall) combines the two using their harmonic mean. F-beta changes the relative priority of recall and precision through beta: beta>1 gives more weight to recall, while beta<1 gives more weight to precision. However, F1 does not directly account for true negatives; two systems with the same F1 can incur different costs at different volumes of non-defective products.
On an automatic rejection line, a recall-focused objective may be appropriate if missed defects are very costly; if reinspection is expensive, precision also becomes important. This decision should be based not just on a number, but on an explicit account of error costs.
The difference between ROC-AUC and PR-AUC
The ROC curve shows the relationship between the True Positive Rate and the False Positive Rate; the precision-recall curve shows the relationship between precision and recall. When the positive class is very rare, even a low FPR can produce many false alarms. The PR curve is therefore more informative for many rare-defect problems. However, class prevalence in different datasets affects the PR baseline, so comparisons must be made under the same conditions.
AUC does not select a single decision threshold. The threshold to be used in production must be determined separately, and the expected error volume at that threshold must be reported. Trapezoidal integration for PR-AUC and average precision calculations are not equivalent in every implementation.
Interactive calculator: confusion matrix and basic metrics
Compare metrics by changing hypothetical TP, FP, FN, and TN values.
This tool is for binary classification. Detection mAP and segmentation IoU additionally require box/mask matching protocols.
IoU and matching in object detection
Intersection over Union (IoU) is the ratio of the intersection area of a predicted box and a ground-truth box to their union area. It is 0 when the two boxes do not overlap and 1 when they are identical. Changing IoU thresholds allows localization accuracy to be evaluated more strictly. When there are multiple predictions and ground-truth objects, the protocol must specify which boxes are matched and how duplicate boxes are counted.
For small defects, a shift of just a few pixels can sharply reduce IoU. We cannot assume that product-level decisions have improved simply because IoU has increased; the physical size of the detected defect and the acceptance tolerance also matter.
What exactly do AP and mAP mean?
Average Precision (AP) summarizes precision-recall behavior across different confidence thresholds in a single value. In the COCO protocol, the main AP metric is calculated by averaging over IoU thresholds from 0.50 to 0.95. [email protected] and COCO AP are not the same thing; thresholds and protocols must be stated when comparing results. mAP denotes the average across classes, although micro/macro weighting conventions may vary between tools.
If one of two defect classes in production is both highly critical and very rare, the macro average alone is insufficient. AP, recall, and the number of critical misses must also be tracked for each class.
Segmentation and anomaly metrics
In segmentation, IoU/Jaccard and Dice measure the overlap between a predicted mask and the ground-truth mask. For surface defects, small scratches and large stain regions cover very different pixel areas; pixel-level metrics can be more strongly influenced by large regions. Some applications require boundary distance or an object-level detection rate.
In anomaly detection, image-level AUROC and pixel-level AUROC do not answer the same question. Region-based metrics such as PRO address anomaly localization. Prevalence and the cost of product-level decisions must still be evaluated separately.
How should results be reported?
At a minimum, a report should include data coverage, the positive class, the data-splitting strategy, metric definitions, the threshold, the confusion matrix, confidence intervals, critical subgroups, and example failures. Showing results for the night shift, different product types, or new batches alongside the average score makes the report genuinely useful for decision-making.
To determine whether a small improvement matters in production, translate it into weekly defect counts, human review capacity, and the accepted risk of missed defects. Metrics are not the goal; they are evidence supporting a decision.
Practical field scenario: product-level decisions versus box accuracy
If a detector identifies small scratches with the correct class but its box boundaries cover too little of each defect, [email protected] may be reasonable while [email protected] is low. If the product only requires a presence/absence decision, precise box localization may have a limited operational impact; if a repair robot will use the location, it becomes critical. The metric must match the task.
Product-level example: the same result, different operations
Consider two detectors. The first model produces a single defect box per product with high IoU; the second more often produces two overlapping boxes but does not miss the actual defect. During box matching, duplicate predictions may count as FP, reducing AP. Yet if the production decision is 'does this product have a defect?', consolidating duplicate boxes at the product level may present a different picture of operational success. This example explains why object detection and product-level decisions should be reported separately.
To calculate AP, results are sorted by score, each detection is marked as TP or FP according to the matching rule, and a precision-recall curve is then constructed. Reporting only mAP without specifying the threshold and interpolation method is incomplete. Using the COCO [email protected]:0.95 protocol rewards more precise box localization, but it is not a standard that directly matches operational tolerances.
Risks in segmentation measurement
If a thin scratch is only 6 pixels wide, a two-pixel boundary shift can substantially affect the Dice score. On a large stain, the same shift may have little impact. For surface defects, the scratch presence/absence decision, defect area, or boundary deviation can therefore be reported in addition to the mask score. If the acceptance tolerance per product is specified in micrometers, the pixel-matching score must be translated into a physical measurement.
Metrics checklist
Document the positive class, the actual number of units, evaluation thresholds, subgroups, and confidence intervals together. Pay particular attention to how recall varies across defect types. Even if two models have the same F1, they may not incur the same cost at different product volumes. Average results must not obscure the number of missed critical defects.
Points to check in the field
- Data source: Clearly define the product, batch, camera, shift, and sampling method.
- Decision unit: Do not conflate measurements at the image, defect, product, and production-line levels.
- Success criteria: Document the metric target together with latency, throughput, cost, and tolerance for critical errors.
- Alternatives: Evaluate whether simpler methods and improvements to the physical setup can meet the same need.
- Validation: Use a test protocol that is independent of the training data and representative of production conditions.
- Change log: When the model, threshold, optical settings, or label definition changes, archive the rationale for the decision and its consequences.
Four conclusions from the same confusion matrix
Consider an illustrative test of 10,000 independent parts containing 100 defective parts. The system detects 90 defects and falsely rejects 99 of the 9,900 good parts. TP=90, FN=10, FP=99 and TN=9,801. Accuracy is 98.91%, but precision is about 47.62%: only 90 of 189 alerts are actual defects. Recall is 90% and F1 is 180/289, about 62.28%. High accuracy and substantial false-alert workload can coexist.
Here the positive class is a defective part; changing that definition changes metric interpretation. The 99 false rejections are 0.99% of all parts but 1% of good parts, so an unspecified denominator is ambiguous. State the decision unit, positive class, sample count and threshold. Precision measured on an artificially balanced test set cannot be transferred directly to production prevalence.
Detection AP instead requires score-ranked detections and an explicit matching rule. IoU thresholds and duplicate detections affect the result. The part-level matrix above is not mAP, and mAP alone does not report rejected-product counts. Keeping both task-level metrics and part decisions distinguishes improvements in box localisation from improvements in the actual quality decision.
Frequently asked questions
Are mAP and accuracy the same?
No. mAP considers class/localization matching of detections and different score thresholds, whereas accuracy is a basic classification rate.
What should the IoU threshold be?
The required threshold depends on the task and tolerance; COCO evaluation uses multiple IoU thresholds together.
References and further reading
The primary sources below explain the methods and evaluation protocols. Numerical scenarios in this article are educational examples, not measured results from a facility or model.