/differnet

This is forked from the official repository (https://github.com/marco-rudolph/differnet) to the WACV 2021 paper "Same Same But DifferNet: Semi-Supervised Defect Detection with Normalizing Flows" by Marco Rudolph, Bastian Wandt and Bodo Rosenhahn.

Primary LanguagePython

DifferNet

This is forked from the official repository to the WACV 2021 paper "Same Same But DifferNet: Semi-Supervised Defect Detection with Normalizing Flows" by Marco Rudolph, Bastian Wandt and Bodo Rosenhahn.

Changes:

  • config.py
  • dataset (MVTec AD, Class = Screw)
  • training details are saved to a log file and can be converted to csv

PWC

PWC

Results

I have tested the effect of different number of input images (hyperparameters are same with the original paper) on AUROC. Here are the results:

auroc_vs_inputimages

Dataset Structure

The dataset is the Screw Class from the MVTec AD dataset.

Set the variables dataset_path and class_name in config.py to run experiments on a dataset of your choice. The structure of the data is as follows:

train data:

        dataset_path/class_name/train/good/any_filename.png
        dataset_path/class_name/train/good/another_filename.tif
        dataset_path/class_name/train/good/xyz.png
        [...]

test data:

    'normal data' = non-anomalies

        dataset_path/class_name/test/good/name_the_file_as_you_like_as_long_as_there_is_an_image_extension.webp
        dataset_path/class_name/test/good/did_you_know_the_image_extension_webp?.png
        dataset_path/class_name/test/good/did_you_know_that_filenames_may_contain_question_marks????.png
        dataset_path/class_name/test/good/dont_know_how_it_is_with_windows.png
        dataset_path/class_name/test/good/just_dont_use_windows_for_this.png
        [...]

    anomalies - assume there are anomaly classes 'crack' and 'curved'

        dataset_path/class_name/test/crack/dat_crack_damn.png
        dataset_path/class_name/test/crack/let_it_crack.png
        dataset_path/class_name/test/crack/writing_docs_is_fun.png
        [...]

        dataset_path/class_name/test/curved/wont_make_a_difference_if_you_put_all_anomalies_in_one_class.png
        dataset_path/class_name/test/curved/but_this_code_is_practicable_for_the_mvtec_dataset.png
        [...]

Getting Started

You will need Python 3.6 and the packages specified in requirements.txt. We recommend setting up a virtual environment with pip and installing the packages there.

Install packages with:

$ pip install -r requirements.txt

Configure and Run

All configurations concerning data, model, training, visualization etc. can be made in config.py. The default configuration will run a training with paper-given parameters on the screw dataset.

To start the training, just run main.py! But I recommend the command below:

$ python main.py | tee $(date +%Y%m%d).log

There's a script log_to_csv.py to convert the log file into a csv file with the training loss, test loss, and AUROC per epoch.

If you have issues when using the code, please report to the main repo.

Credits

Most of the code is from the official repository and some of the implementation of Normalizing Flows are from the FrEIA framework . Follow their tutorial if you need more documentation about it.

Citation

Please cite the original paper in your publications if it helps your research.

@inproceedings { RudWan2021,
author = {Marco Rudolph and Bastian Wandt and Bodo Rosenhahn},
title = {Same Same But DifferNet: Semi-Supervised Defect Detection with Normalizing Flows},
booktitle = {Winter Conference on Applications of Computer Vision (WACV)},
year = {2021},
month = jan
}

Another paper link because you missed the first one:

License

This project is licensed under the MIT License.