Littlebai12138 / f-AnoGAN

Implementation of f-AnoGAN with PyTorch

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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.

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 the MNIST dataset

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

Colaboratory

f-AnoGAN_MNIST.ipynb
f-AnoGAN_MVTecAD.ipynb

About

Implementation of f-AnoGAN with PyTorch

License:MIT License


Languages

Language:Python 100.0%