Giter Club home page Giter Club logo

f-anogan's Introduction

f-AnoGAN

f-AnoGAN is a GAN for anomaly detection. One of the features of this GAN is that two adversarial networks (Generator and Discriminator) and Encoder are trained separately. In addition, an anomaly score is computed by both a discriminator feature residual error and an image reconstruction error.

Japanese version

References

Papar

Github

mnist/model.py, fanogan/train_wgangp.py and fanogan/train_encoder_izif.py are modified eriklindernoren's wgan_gp.py for f-AnoGAN.
mvtec_ad/model.py is modified eriklindernoren's dcgan.py for f-AnoGAN.

Requirements

Python 3.6 or later
PyTorch 1.x

Matplotlib
Numpy
pandas
Pillow
scikit-learn

Usage for training and test a dataset

MNIST

Please run below in order on the CPU.

Step: 0

python setup.py install
cd mnist

Step: 1

python train_wgangp.py --training_label 1 --seed 2 --n_epochs 20

Step: 2

python train_encoder_izif.py --training_label 1 --seed 2 --n_epochs 20

Step: 3

python test_anomaly_detection.py --training_label 1

After Step: 3, score.csv will be generated in the directory results.

See f-AnoGAN_MNIST.ipynb about data visualization for score.csv.

Step: 4

python save_compared_images.py --seed 4 --n_iters 0 --n_grid_lines 10

Compared images are saved under f-AnoGAN/mnist/results/images_diff.

Visualization

ROC AUC PR AUC Anomaly Scores Compared Images

Your own dataset

Please run below in order.

Step: 0

python setup.py install
cd your_own_dataset

Add your own dataset under f-AnoGAN/your_own_dataset

Step: 1

Please replace your_own_dataset_dir_name/train_dir_name with a relative path of your own training data.

python train_wgangp.py "your_own_dataset_dir_name/train_dir_name"

Step: 2

Please replace your_own_dataset_dir_name/train_dir_name with a relative path of your own training data.

python train_encoder_izif.py "your_own_dataset_dir_name/train_dir_name"

Step: 3

Please replace your_own_dataset_dir_name/test_dir_name with a relative path of your own test data.

python test_anomaly_detection.py "your_own_dataset_dir_name/test_dir_name"

After Step: 3, score.csv will be generated in the directory results.

Step: 4

Please replace your_own_dataset_dir_name/test_dir_name with a relative path of your own test data.

python save_compared_images.py "your_own_dataset_dir_name/test_dir_name" --n_iters 0 --n_grid_lines 10

Compared images are saved under f-AnoGAN/your_own_dataset/results/images_diff.

Colaboratory

f-AnoGAN_MNIST.ipynb
f-AnoGAN_MVTecAD.ipynb

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.