For the complete documentation index, see llms.txt. This page is also available as Markdown.

Anomaly Detection

Flag defects you have few or no pictures of by training on normal images, then deploy your own anomaly detection model on Roboflow.

What is anomaly detection?

Anomaly detection learns what a normal image looks like from normal images only, then flags images that differ. For each image, the model returns a "normal" or "anomalous" verdict, an anomaly score, and a heatmap of where the image differs. You do not need pictures of every defect, so it fits problems where defects are rare or vary a lot.

A blemished orange outlined in red and tagged Anomaly, with a heatmap over the blemish

Supported anomaly detection models

Roboflow supports these anomaly detection models. See the Anomaly Detection models table for export and deployment support per model.

Model
License
Trainable on Roboflow
Latest release

Apache 2.0 (free for commercial use)

2021

Choosing an anomaly detection model

FoundAD is more accurate, especially when you only have a few normal images. More normal images help both models, and PatchCore the most.

Image AUROC of PatchCore and FoundAD on four VisA categories, trained on 4 normal images and on all of them
Results on four categories of the VisA dataset (CC BY 4.0).

FoundAD takes the same time per image at any training set size. PatchCore slows down as you add normal images or raise the image size (see PatchCore inference speed). Which one is faster depends on your hardware and settings.

Average image AUROC against mean inference time per image for PatchCore and FoundAD on a Jetson AGX Orin, a Jetson Orin NX 16GB, and Roboflow Serverless
Mean server execution time over 100 requests per model, measured with inference benchmark api-speed on Roboflow Inference 1.8 (the public Jetson 6.2 image on both Jetsons). PatchCore at 224×224, FoundAD at 512×512.

PatchCore trains in minutes. FoundAD takes longer, up to hours on large datasets.

These results come from one benchmark: both models trained at their default image sizes on four categories of the VisA dataset, and scored on its test split. Accuracy and speed on your data depend on your images, defects, image size, and hardware, so test both models before you choose.

Fine-tuning an anomaly detection model

The PatchCore and FoundAD pages cover the split and preprocessing rules for this task.

1

Create an anomaly detection project

Create a Project and pick "Anomaly Detection" as the project type.

Create project form with Anomaly Detection selected as the project type and a preview of an anomaly detection example
2

Upload and label images

Upload images, then label each image "normal" or "anomalous" in the annotation editor. Most of your images should be normal. The model trains on normal images only. Anomalous images set the decision threshold and measure accuracy, so they go to the valid and test splits only.

Annotation editor on an egg image with the class picker open and normal selected over anomalous
3

Generate a dataset version

Generate a dataset version with only the auto-orient and "Stretch to" resize preprocessing steps, and no augmentation.

4

Train an anomaly detection model

Click "Train" and pick PatchCore or FoundAD. See Train a Model for every option.

Select Architecture step on the Train page listing PatchCore and FoundAD

Deploy an anomaly detection model

After training, deploy your anomaly detection model with the Serverless Cloud API, a Dedicated Deployment, or on your own hardware with Roboflow Inference. See Choosing a Deployment to compare the options.

Last updated

Was this helpful?