PatchCore
Train PatchCore anomaly detection models on normal images in Roboflow and run them through the Serverless Cloud API
PatchCore finds defects without needing pictures of them. It learns what a normal part looks like from normal images only, then flags any image that departs from it. It stores features of small image patches from your normal images (from a WideResNet50 backbone) and scores a new image by its most unusual patch. Each prediction returns a "normal" or "anomalous" verdict, a raw anomaly score, and a heatmap of where the image differs. At the default 224×224, scoring is light, so PatchCore runs well on CPU.

Try FoundAD if PatchCore misses subtle defects or you only have a few normal images. It uses a larger DINOv3 encoder and runs best on a GPU. See Choosing an anomaly detection model to compare the two.
Train PatchCore
Label normal and anomalous images
Create an Anomaly Detection Project, upload images, and label each one "normal" or "anomalous". 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.
Start a training
Train a model and pick PatchCore. When training finishes, Roboflow reports precision, recall, and F1 on the test set, using the threshold it saved during training.
Inference speed
PatchCore compares each patch of an image with a memory bank of patches from your normal training images. More training images make the memory bank bigger. A larger image size makes both the number of patches and the memory bank bigger, so image size matters most. At large image sizes with a few hundred training images or more, FoundAD can be faster.

PatchCore API
Get your API Key
Find your key on the Roboflow API settings page and make it available to your shell:
Install the dependencies
Install the Inference SDK:
Run the model
Call your trained model by its ID (see Versions, Trainings, and Models).
The response has these fields:
top: the verdict, "normal" or "anomalous".anomaly_score: the raw score. Larger means more anomalous. The score has no fixed range.anomaly_threshold: the score at which an image becomes anomalous, saved during training.confidenceandpredictions: the confidence of the verdict, and of each class. The "anomalous" confidence grows with the score and is exactly 0.5 at the threshold, so it is not a defect probability.anomaly_map: the heatmap, returned only when you setinclude_anomaly_map=True. It is a square array at the model's input size, so stretch it to your image's width and height to overlay it.
Use PatchCore in a Workflow
Add the Anomaly Detection Model block to a Workflow to score images, then connect its anomaly_map output to the Anomaly Heatmap Visualization block to draw the heatmap. Self-hosted Workflows need Inference 1.8.2 or later for these blocks. Change the block's confidence to trade missed defects for false alarms without retraining: lower it to flag more images as anomalous.
License
PatchCore follows amazon-science/patchcore-inspection and is licensed under Apache 2.0. See Model Licenses.
Last updated
Was this helpful?