Tensorflow implementation of Anomaly GAN (AnoGAN).
This model detect anomaly part in images, after training DCGAN with normal dataset.
(In Korean, H. Kim's detail explanation is here)
Basic model is DCGAN (Deep Convolutional Generative Adversarial Networks).
After learn DCGAN model with normal dataset (not contains anomalies),
When unseen data comes, the model tries to find latent variable z that generates input image using backpropagation. (similar with style transfer)
Anomaly Score is based on residual and discrimination losses.
Total Loss for finding latent variable z is weighted sum of the two. (defualt lambda = 0.1)
First, you "must" have trained DCGAN model with normal dataset.
If you have checkpoint file, the model tries to use it.
(If you want to download and train the model) First, download dataset with:
$ python download.py mnist celebA
To train a model with downloaded dataset:
$ python main.py --dataset mnist --input_height=28 --output_height=28 --train
$ python main.py --dataset celebA --input_height=108 --train --crop
Or, you can use your own dataset (without central crop) by:
$ mkdir data/DATASET_NAME
... add images to data/DATASET_NAME ...
$ python main.py --dataset DATASET_NAME --train
$ python main.py --dataset DATASET_NAME
$ # example
$ python main.py --dataset=eyes --input_fname_pattern="*_cropped.png" --train
After having trained DCGAN model, you have to prepare test images for anomaly detection.
$ mkdir ./test_data
... add test images to ./test_data ...
$ python main.py --dataset DATASET_NAME --input_height=108 --crop --anomaly_test
To valid the model implementation, simple test was proceeded.
Initial generated image by DCGAN in training is conisdered as anomaly.
After learns DCGAN model, compared final and initial images on certain latent varaible z.
Then, anomaly score of initial images was calculated.
Eyes, mouth, and distorted parts in image were detected.