Skip to content

Visual Anomaly Detection

Training a visual anomaly model

Choose the normal classes, train, and use the Anomaly explorer to read the results and set the threshold.

Try it in Studio
On this page

Goal

By the end of this page you will have a trained visual anomaly model and a threshold you understand.

Open Visual Anomaly Detection in the left menu. The page has three parts: Visual anomaly settings on the left, Training output on the right, and the Anomaly explorer below once a run has finished.

Choose the scoring function

The Scoring function box shows the method the model uses to tell normal from unusual.

  • Gaussian Mixture Model (GMM) is the default. It is small, trains in seconds and can run as INT8.
  • PatchCore keeps a memory of real normal image patches. It finds smaller defects on complex parts, but is larger, slower and Float32 only.

Select Change to switch. The new choice applies to the next run; your current model stays available until it finishes.

More: Which scoring function should I choose?

Choose the normal classes

Under Normal classes, tick every label that shows good parts. Each chip shows how many training and test images it has.

The line underneath tells you what will happen, for example Training on 137 normal images · 24 held out to set the threshold · Test set: 43 normal, 10 anomalous. Images of the classes you leave unticked are left out of training and count as anomalies in the test set.

Check the training settings

SettingScoring functionWhat it does
Capacity (Low, Medium, High)GMMHow varied the normal images may be. Higher follows more variety, and is a little slower and larger.
Memory detail (Compact, Balanced, Detailed)PatchCoreHow much of normal is remembered. More detail catches finer defects but makes a larger, slower model.

Open Advanced settings for the backbone, how the image score is taken, how many normal images are held out to set the threshold, and whether background images count as normal. The defaults suit most projects. Every setting is explained in What settings can I configure?

Start training

Select Start Training in the Training output card. The status chip shows Queued, Running and then Completed, and you can select Stop Training at any time.

  • Console Logs shows each step: extracting features, fitting the model, calibrating on the held-out images, scoring the test images, exporting, and the INT8 accuracy check.
  • Dataset lists how many images were fitted, held out and scored, and the input and heatmap size.

When the run finishes, the card shows the AUROC and the threshold, and the model size.

Read the Anomaly explorer

The summary

NumberWhat it tells you
AUROCHow well the scores separate anomalous from normal test images, whatever the threshold. 1.0 is perfect, 0.5 is guessing. The ring and the words (Excellent, Strong, Fair, Weak separation) say the same at a glance.
ThresholdThe current threshold and where it came from (Calibrated, Best F1, Youden's J or Set by you).
Normal flaggedFalse alarms: normal test images at or above the threshold. The red bar shows the share.
Anomalies caughtAnomalous test images at or above the threshold, and the recall. The green bar shows the share.
ModelThe model size and scoring function.

AUROC needs anomalous images in the testing set. Without them it shows a dash.

Score distribution and threshold

The Score distribution chart shows normal images in blue and anomalous images with red stripes. Everything right of the dashed line is flagged; that area is tinted red.

Drag the Threshold slider to trade false alarms against missed anomalies. The line on the chart, the summary numbers and the counts under the slider follow as you drag, and the new value is saved when you let go. No retraining is needed.

  • Reset to calibrated goes back to the default, where about 1 in 100 normal images is flagged.
  • Best F1 and Youden's J are tuned on your test images. They flatter the result, so check them against new images before you rely on them.

Test images and heatmaps

Test images lists the scored images, highest score first. Filter with All, Flagged or Wrong. A wrong call has a red outline and a False alarm or Missed tag, so it does not depend on colour alone.

Select an image to open its Heatmap: each cell of the grid shows how unusual that spot is, so you can see where the model thinks the defect is.

If the results are not good enough

  • Normal images get flagged: add more varied photos of good parts, raise Capacity, or check that the lighting and camera position match.
  • Defects are missed: try PatchCore, or a larger image size, so small defects cover more cells.
  • AUROC is low: check that no defect classes are ticked as normal, and that defect photos are in the testing set.

More: Image troubleshooting.

Next step

Evaluating a visual anomaly model.