Skip to main content

PatchCore Industrial Anomaly Detection

State-of-the-art anomaly detection for industrial inspection achieving up to 99.6% AUROC on the MVTec AD benchmark using pretrained feature extractors and coreset subsampling

99.6%
Image-level AUROC
98.4%
Pixel-level AUROC
50+
Backbone networks

Quick start

Get started with PatchCore in minutes

1

Install dependencies

Clone the repository and install required packages:
git clone https://github.com/amazon-science/patchcore-inspection.git
cd patchcore-inspection
pip install -r requirements.txt
2

Download MVTec AD dataset

Download the MVTec AD benchmark dataset and organize it with the expected structure:
# Download from https://www.mvtec.com/company/research/datasets/mvtec-ad
# Organize as: mvtec/bottle/{train,test,ground_truth}
The dataset should contain 15 subdatasets: bottle, cable, capsule, carpet, grid, hazelnut, leather, metal_nut, pill, screw, tile, toothbrush, transistor, wood, and zipper.
3

Train your first model

Train PatchCore on a single category:
env PYTHONPATH=src python bin/run_patchcore.py \
  --gpu 0 --seed 0 --save_patchcore_model \
  results patch_core -b wideresnet50 -le layer2 -le layer3 \
  --faiss_on_gpu --pretrain_embed_dimension 1024 \
  --target_embed_dimension 1024 --anomaly_scorer_num_nn 1 \
  --patchsize 3 sampler -p 0.1 approx_greedy_coreset \
  dataset --resize 256 --imagesize 224 -d bottle mvtec /path/to/mvtec
4

Evaluate the model

Load and evaluate your trained model:
env PYTHONPATH=src python bin/load_and_evaluate_patchcore.py \
  --gpu 0 --seed 0 results/evaluation \
  patch_core_loader -p results/models/mvtec_bottle --faiss_on_gpu \
  dataset --resize 256 --imagesize 224 -d bottle mvtec /path/to/mvtec
Image-level AUROC: 99.2%
Pixel-level AUROC: 98.1%
PRO Score: 94.4%

Key features

Everything you need for industrial anomaly detection

State-of-the-art accuracy

Achieve up to 99.6% image-level AUROC and 98.4% pixel-level AUROC on MVTec AD

Memory efficient

Coreset subsampling reduces memory footprint while maintaining detection accuracy

50+ backbone networks

Choose from ResNet, WideResNet, EfficientNet, Vision Transformers, and more

Ensemble support

Combine multiple backbones and feature layers for even better performance

FAISS acceleration

GPU-accelerated nearest neighbor search for fast inference

Pretrained models

Ready-to-use models for all 15 MVTec AD categories

Ready to start detecting anomalies?

Get up and running with PatchCore in minutes. Train your first model or explore our pretrained models for the MVTec AD benchmark.