Prerequisites
Make sure you have:
- Python 3.8 or higher
- CUDA-compatible GPU (recommended)
- At least 11GB of GPU memory
Quick Setup
Download MVTec AD Dataset
Download the MVTec AD dataset from the official website and extract it.Your dataset structure should look like:
The dataset contains 15 categories: bottle, cable, capsule, carpet, grid, hazelnut, leather, metal_nut, pill, screw, tile, toothbrush, transistor, wood, and zipper.
Train Your First Model
Train PatchCore on a single category (e.g., “bottle”) using WideResNet50:
Understanding the command
Understanding the command
--gpu 0: Use GPU 0--seed 0: Set random seed for reproducibility--save_patchcore_model: Save the trained model-b wideresnet50: Use WideResNet50 backbone (pretrained on ImageNet)-le layer2 -le layer3: Extract features from layer2 and layer3--faiss_on_gpu: Run similarity search on GPU for speed--pretrain_embed_dimension 1024: Backbone feature dimension--target_embed_dimension 1024: Final PatchCore embedding dimension--anomaly_scorer_num_nn 1: Use 1 nearest neighbor for scoring--patchsize 3: Local aggregation neighborhood size-p 0.1: Keep 10% of patches via coreset subsampling--resize 256 --imagesize 224: Resize to 256, then center crop to 224
Expected Output
During training, you’ll see output similar to:Expected Performance (WideResNet50 baseline on 224x224 images):
- Instance AUROC: 99.2% (image-level anomaly detection)
- Pixel-wise AUROC: 98.1% (defect localization)
- PRO Score: 94.4%
Train on All Categories
To train on all 15 MVTec AD categories:Model Output
After training, your results will be saved in:Evaluate a Trained Model
To evaluate your trained model:Next Steps
Installation Guide
Detailed installation instructions and troubleshooting
Model Architecture
Learn how PatchCore works under the hood
Training Options
Explore advanced training configurations
API Reference
Complete API documentation
Common Issues
FAISS not found error
FAISS not found error
If you get “FAISS not found”, install the GPU version:
