Skip to main content

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

1

Visit MVTec Website

Go to the official MVTec AD dataset page:Fill out the download form to access the dataset.
2

Download and Extract

Download the complete dataset (approximately 4.9 GB compressed).
Extract Dataset
3

Verify Directory Structure

Ensure the extracted folder follows the correct structure (see below).

Required Directory Structure

The dataset must be organized with the following structure for PatchCore to load it correctly:
Directory Tree
The directory structure must match this layout exactly. PatchCore expects:
  • train/good/ for training images
  • test/ with subdirectories for each defect type
  • ground_truth/ with pixel-level masks for defects

Dataset Categories

MVTec AD includes 15 categories across objects and textures:
Objects (rigid items with consistent appearance):
  • bottle - Glass bottles
  • cable - Power cables
  • capsule - Pharmaceutical capsules
  • hazelnut - Hazelnuts
  • metal_nut - Metal nuts
  • pill - Pharmaceutical pills
  • screw - Screws
  • toothbrush - Toothbrushes
  • transistor - Electronic transistors
  • zipper - 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:
1

Locate Category

For each specified category (e.g., bottle), PatchCore looks for:
2

Apply Transformations

Each image is:
  1. Resized to --resize (default: 256)
  2. Center-cropped to --imagesize (default: 224)
  3. Converted to tensor
  4. Normalized with ImageNet mean/std
Normalization
3

Create DataLoader

Images are batched with:
  • batch_size: Default 2 (configurable)
  • num_workers: Default 8 (parallel loading)
  • shuffle: False (deterministic order)

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

Problem: Dataset path is incorrect or structure doesn’t match expected format.Solution:
  1. Verify the path exists: ls /path/to/mvtec
  2. Check category exists: ls /path/to/mvtec/bottle
  3. Verify train folder: ls /path/to/mvtec/bottle/train/good
Problem: Training images not in correct location.Solution:
  • All training images must be in {category}/train/good/
  • Check for .png or .jpg files in that directory
  • Verify file permissions (readable)
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