Home

Awesome

Anomaly Detection with Conditioned Denoising Diffusion Models.

Official implementation of DDAD

PWC PWC

Framework

Requirements

This repository is implemented and tested on Python 3.8 and PyTorch 2.1. To install requirements:

pip install -r requirements.txt

Train and Evaluation of the Model

You can download the model checkpoints directly from Checkpoints

To train the denoising UNet, run:

python main.py --train True

Modify the settings in the config.yaml file to train the model on different categories.

For fine-tuning the feature extractor, use the following command:

python main.py --domain_adaptation True

To evaluate and test the model, run:

python main.py --detection True

Dataset

You can download MVTec AD: MVTec Software and VisA Benchmarks. For preprocessing of VisA dataset check out the Data preparation section of this repository.

The dataset should be placed in the 'datasets' folder. The training dataset should only contain one subcategory consisting of nominal samples, which should be named 'good'. The test dataset should include one category named 'good' for nominal samples, and any other subcategories of anomalous samples. It should be made as follows:

Name_of_Dataset
|-- Category
|-----|----- ground_truth
|-----|----- test
|-----|--------|------ good
|-----|--------|------ ...
|-----|--------|------ ...
|-----|----- train
|-----|--------|------ good

Results

Running the code as explained in this file should achieve the following results for MVTec AD:

Anomaly Detection (Image AUROC) and Anomaly Localization (Pixel AUROC, PRO)

Expected results for MVTec AD:

CategoryCarpetGridLeatherTileWoodBottleCableCapsuleHazel nutMetalnutPillScrewToothbrushTransistorZipperAverage
Detection99.3%100%100%100%100%100%99.4%99.4%100%100%100%99.0%100%100%100%99.8%
Localization(98.7%,93.9%)(99.4%,97.3%)(99.4%,97.7%)(98.2%,93.1%)(95.0%,82.9%)(98.7%,91.8%)(98.1%,88.9%)(95.7%,93.4%)(98.4%,86.7%)(99.0%,91.1%)(99.1%,95.5%)(99.3%,96.3%)(98.7%,92.6%)(95.3%,90.1%)(98.2%,93.2%)(98,1%,92.3%)

The settings used for these results are detailed in the table.

CategoriesCarpetGridLeatherTileWoodBottleCableCapsuleHazelnutMetal nutPillScrewToothbrushTransistorZipper
(w)041141133857920010
Training epochs250020002000100020001000300015002000300010002000200020001000
FE epochs0680165083144206

Following is the expected results on VisA Dataset.

CategoryCandleCapsulesCashewChewing gumFryumMacaroni1Macaroni2PCB1PCB2PCB3PCB4Pipe fryumAverage
Detection99.9%100%94.5%98.1%99.0%99.2%99.2%100%99.7%97.2%100%100%98.9%
Localization(98.7%,96.6%)(99.5%,95.0%)(97.4%,80.3%)(96.5%,85.2%)(96.9%,94.2%)(98.7%,98.5%)(98.2%,99.3%)(93.4%,93.3%)(97.4%,93.3%)(96.3%,86.6%)(98.5%,95.5%)(99.5%,94.7%)(97.6%,92.7%)

The settings used for these results are detailed in the table.

CategoriesCandleCapsulesCashewChewing gumFryumMacaroni1Macaroni2PCB1PCB2PCB3PCB4Pipe fryum
(w)650645295668
Training epochs10001000175012501000500500500500500500500
FE epochs1300371185116

Framework

Citation

@article{mousakhan2023anomaly,
  title={Anomaly Detection with Conditioned Denoising Diffusion Models},
  author={Mousakhan, Arian and Brox, Thomas and Tayyub, Jawad},
  journal={arXiv preprint arXiv:2305.15956},
  year={2023}
}

Feedback

For any feedback or inquiries, please contact arian.mousakhan@gmail.com