Unsupervised anomaly detection using PatchCore on the MVTec AD dataset. Trained only on normal images — no defect labels needed during training.
| Defect Type | AUROC |
|---|---|
| Broken large | 95.0% |
| Broken small | 91.0% |
| Contamination | 99.0% |
| Overall | 99.1% |
- Loads 209 normal bottle images from MVTec AD dataset
- Extracts patch features using pretrained ResNet50 (ImageNet)
- Builds a memory bank of normal feature vectors
- At test time, computes nearest-neighbor distance to flag anomalies
- Generates pixel-level heatmaps showing exactly where defects are
- Achieves 99.1% AUROC with no anomaly labels during training
MVTec Anomaly Detection Dataset Bottle category: 209 normal training images, 83 test images across 3 defect types.
PatchCore — memory bank based anomaly detection using pretrained ResNet50 features. No fine-tuning required. Test images are scored by their distance to the nearest neighbor in the normal feature memory bank.
- Python, PyTorch, torchvision
- ResNet50 (pretrained on ImageNet)
- scikit-learn (AUROC evaluation)
- NumPy, Matplotlib, PIL
- Kaggle (T4 GPU)
- Download MVTec AD bottle category from the official website
- Open the notebook in Kaggle
- Run all cells top to bottom

