About MVTec AD
The MVTec Anomaly Detection (MVTec AD) dataset is the standard benchmark for industrial anomaly detection. It contains high-resolution images of 15 different object and texture categories with various types of defects.Dataset Statistics
- 15 product categories
- 5,354 images total (3,629 training + 1,725 testing)
- Training images: only defect-free (“good”) samples
- Test images: defect-free and various anomaly types
- Ground truth masks for pixel-level evaluation
Download the Dataset
Visit MVTec Website
Go to the official MVTec AD dataset page:Fill out the download form to access the dataset.
MVTec AD Downloadhttps://www.mvtec.com/company/research/datasets/mvtec-ad
Download and Extract
Download the complete dataset (approximately 4.9 GB compressed).
Extract Dataset
Required Directory Structure
The dataset must be organized with the following structure for PatchCore to load it correctly:Directory Tree
Dataset Categories
MVTec AD includes 15 categories across objects and textures:- Object Categories
- Texture Categories
Objects (rigid items with consistent appearance):
bottle- Glass bottlescable- Power cablescapsule- Pharmaceutical capsuleshazelnut- Hazelnutsmetal_nut- Metal nutspill- Pharmaceutical pillsscrew- Screwstoothbrush- Toothbrushestransistor- Electronic transistorszipper- Zippers
Verify Installation
Check that your dataset is properly structured:Configure Dataset Path
Once the dataset is ready, you’ll reference it in training commands:Dataset Loading Process
When you run training, PatchCore loads the dataset as follows:Apply Transformations
Each image is:
- Resized to
--resize(default: 256) - Center-cropped to
--imagesize(default: 224) - Converted to tensor
- Normalized with ImageNet mean/std
Normalization
Training on Subset of Categories
You don’t have to train on all 15 categories. Specify only the ones you need:Train Single Category
Train Multiple Categories
Common Issues
FileNotFoundError: No such file or directory
FileNotFoundError: No such file or directory
Problem: Dataset path is incorrect or structure doesn’t match expected format.Solution:
- Verify the path exists:
ls /path/to/mvtec - Check category exists:
ls /path/to/mvtec/bottle - Verify train folder:
ls /path/to/mvtec/bottle/train/good
Empty dataset or zero training images
Empty dataset or zero training images
Problem: Training images not in correct location.Solution:
- All training images must be in
{category}/train/good/ - Check for
.pngor.jpgfiles in that directory - Verify file permissions (readable)
Ground truth masks not found during testing
Ground truth masks not found during testing
Problem: Mask files missing or in wrong location.Solution:
- Masks should be in
{category}/ground_truth/{defect_type}/ - Mask filenames must match test image filenames
- Only defect images have masks (good samples don’t need masks)
Next Steps
Train Single Model
Start training with WideResNet50 backbone
Configuration Guide
Learn about all training parameters
