Skip to content

About

Machine Learning-Based Anomaly Detection for Images

Resources

Stars

0 stars

Watchers

1 watching

Forks

Latest commit

 

History

2 Commits

Folders and files

Repository files navigation

Anomaly Detection using MVTec AD Dataset

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.

📘 Notebook Overview

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.

🛠️ Requirements

Install the necessary packages using pip:

pip install -r requirements.txt

Typical requirements include:

  • Python 3.8+
  • PyTorch
  • torchvision
  • numpy
  • matplotlib
  • scikit-learn
  • opencv-python
  • tqdm

Note: A requirements.txt file is included for full reproducibility.

📂 Dataset

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.

🚀 Running the Notebook

  1. Clone the repository:
git clone https://github.com/<your-username>/anomaly-detection-mvtec.git
cd anomaly-detection-mvtec
  1. Install dependencies.

  2. Launch the Jupyter Notebook:

jupyter notebook Anomaly_Detection_MVTecAD_public.ipynb

Follow the cells step-by-step to train and evaluate the model.

🧠 Model Details

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.

📈 Results

Performance is measured using:

  • ROC AUC for classification
  • Pixel-wise IoU or AUC for segmentation
  • Qualitative visualization of defect localization

📌 Notes

  • GPU acceleration is recommended for training.
  • Make sure to verify the dataset structure before running.
  • This notebook is intended for research and educational purposes.

📄 License

This project is licensed under the MIT License.

🤝 Contributions

Contributions are welcome! Feel free to open issues or submit pull requests for improvements.

About

Machine Learning-Based Anomaly Detection for Images

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages