This repository contains a Jupyter notebook implementation of an anomaly detection pipeline using the MVTec AD dataset. The goal is to identify visual defects in industrial products using deep learning techniques. This notebook provides a streamlined approach to training and evaluating models on multiple object categories.
The notebook, Anomaly_Detection_MVTecAD_public.ipynb, walks through the following stages:
- Data Loading: Fetching and organizing the MVTec AD dataset.
- Preprocessing: Image resizing, normalization, and augmentation.
- Model Architecture: A CNN-based encoder-decoder architecture for unsupervised anomaly detection.
- Training: Training the model only on normal images to learn healthy patterns.
- Evaluation: Detecting anomalies and evaluating performance using metrics like AUC and IoU.
- Visualization: Displaying anomaly maps and defect segmentation.
Install the necessary packages using pip:
pip install -r requirements.txtTypical requirements include:
- Python 3.8+
- PyTorch
- torchvision
- numpy
- matplotlib
- scikit-learn
- opencv-python
- tqdm
Note: A
requirements.txtfile is included for full reproducibility.
Download the MVTec AD dataset from the official site and place it in a directory structure like:
data/
└── mvtec_anomaly_detection/
├── bottle/
├── cable/
├── capsule/
└── ...
You may need to adjust the dataset path in the notebook accordingly.
- Clone the repository:
git clone https://github.com/<your-username>/anomaly-detection-mvtec.git
cd anomaly-detection-mvtec-
Install dependencies.
-
Launch the Jupyter Notebook:
jupyter notebook Anomaly_Detection_MVTecAD_public.ipynbFollow the cells step-by-step to train and evaluate the model.
The core architecture uses an autoencoder or feature-based method (such as pretrained CNN backbones) to learn normal data patterns. During inference, deviations from this learned distribution are flagged as anomalies.
Performance is measured using:
- ROC AUC for classification
- Pixel-wise IoU or AUC for segmentation
- Qualitative visualization of defect localization
- GPU acceleration is recommended for training.
- Make sure to verify the dataset structure before running.
- This notebook is intended for research and educational purposes.
This project is licensed under the MIT License.
Contributions are welcome! Feel free to open issues or submit pull requests for improvements.