Visual Anomaly Detection
Evaluating a visual anomaly model
Read AUROC and the curves, pick a threshold, test the model on your testing images and try it live.
Try it in StudioOn this page
Goal
By the end of this page you will know how well your anomaly model separates good parts from defects, which threshold to use, and how it behaves on new images.
Three pages in the left menu do this: Evaluation, Model testing and Live classification.
Read the scores on the Evaluation page
The top line says which images were used, for example Evaluated on the test set: 43 normal and 10 anomalous images. When the scores also use the normal images held out for calibration, the line says so (test set and calibration holdout).
| Metric | What it means | Depends on the threshold? |
|---|---|---|
| AUROC | How well the scores separate anomalous from normal images. 1.0 is perfect, 0.5 is guessing. | No |
| AUPRC | Area under the precision-recall curve. Useful when anomalies are rare. | No |
| F1 | The balance of precision and recall at the saved threshold. | Yes |
| Precision | Of the images flagged, the share that really are anomalies. | Yes |
| Recall | Of the anomalies, the share that were flagged. | Yes |
| Specificity | Of the normal images, the share that passed. | Yes |
| Region hit rate | Shown when anomalous test images have boxes: the share where the most unusual cell falls inside the box. | Yes |
AUROC leads because an anomaly detector is judged by how well its scores separate the two groups. Accuracy is not shown: with few anomalies it would look high even for a model that flags nothing.
Read the curves
- ROC curve: the catch rate (true positive rate) against the false-alarm rate at every threshold. The closer it hugs the top-left corner, the better. The dashed diagonal is random guessing.
- Precision-recall curve: how precise the flags stay as more anomalies are caught. A curve that stays high to the right is good.
The red dot on each curve marks the saved threshold, so you can see where on the trade-off you are.
Check the confusion matrix
The 2 × 2 matrix counts the evaluation images at the saved threshold:
| Predicted normal | Predicted anomaly | |
|---|---|---|
| Actual normal | True normal | False alarm |
| Actual anomaly | Missed anomaly | Caught anomaly |
Correct cells are tinted green; mistakes are tinted rose and have a dashed edge.
Choose the threshold
The Threshold card shows the saved threshold and where it came from. Select a suggestion to save it; the metrics, curves and matrix update without retraining.
- Calibrated (the default, 1.00): about 1 in 100 normal images is flagged.
- Max F1: the threshold with the best F1 on the evaluation images.
- Youden: the threshold that maximises recall plus specificity.
Max F1 and Youden are tuned on the same images they are measured on, so they look better here than they will on new images. Each suggestion that cannot be computed, for example without anomalous images, says why.
For a finer choice, drag the threshold slider in the training page's Anomaly explorer.
The Score distribution at the bottom shows normal and anomalous images against the saved threshold.
Model testing
Model testing runs the model on every image in your testing set.
- Open Model testing and select Classify all.
- Each row shows the image, its expected label, the score vs threshold (for example 1.42 ≥ 1.00) and a status:
- Pass: the decision matches the label.
- Fail: the decision is wrong.
- Uncertain: the score is within 10% of the threshold, so a small change in light could flip it.
- Pending: not classified yet.
- Select a row to open the Sample inspector with the anomaly map.
The summary above the table shows AUROC and the other scores for the testing set, and the confusion matrix at the threshold.
Live classification
Live classification scores one new image at a time. Choose the Image source:
- Upload image: an image file from your computer.
- Test sample: an image from your testing set.
- Webcam: frames from your camera.
- Device: results streamed from a connected device running the deployed package.
The result card says Anomaly, Normal or Uncertain, with an icon as well as a colour, and shows the score against the threshold and the timings. Switch the View between Image, Heatmap and Overlay, and set the Overlay opacity. Cells at or above the threshold are outlined.