• Stars
    star
    272
  • Rank 151,235 (Top 3 %)
  • Language
    Python
  • License
    MIT License
  • Created almost 7 years ago
  • Updated over 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Unofficial Tensorflow Implementation of AnoGAN (Anomaly GAN)

AnoGAN in tensorflow

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).

  • (Anomaly Detection of MNIST is not yet available)

Model Description

After learn DCGAN model with normal dataset (not contains anomalies),

  • Anomaly Detector calculates anomaly score of unseen images.

Model Structure

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.

  • Residual loss: L1 distance between generated image by z and unseen test image.
  • Discrimination loss: L1 distacne between hidden representations of generated and test image, extracted by discriminators.

Res_Loss

Discrimination Loss

Total Loss for finding latent variable z is weighted sum of the two. (defualt lambda = 0.1)

Total Loss

File Descriptions

  • main.py : Main function of implementations, contained argument parsers, model construction, and test.
  • model.py : DCGAN class (containing anomaly detection function. Imple core)
  • download.py : Files for downloading celebA, LSUN, and MNIST.
  • ops.py : Some operation functions with tensorflow.
  • utils.py : Some functions dealing with image preprocessing.

Prerequisites (my environments)

Usage

First, you "must" have trained DCGAN model with normal dataset.

If you have checkpoint file, the model tries to use it.

Model Preparation

(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

Anomaly Detection

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

Results

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.

result

Related works

To Do

You can always request pull requests with feeling free.

  • Threshold Setting Function (Manual/Automatic)
  • Add performance measures of anomaly detection with labels (ROC AUC)
  • Visaulization of anomaly detection results (t-SNE)

Acknowledgement

  • Thanks for @carpedm20 's implementation of DCGAN. I implemented AnoGAN based on his implementation.

More Repositories

1

RobustSTL

Unofficial Implementation of RobustSTL: A Robust Seasonal-Trend Decomposition Algorithm for Long Time Series (AAAI 2019)
Jupyter Notebook
270
star
2

FixMatch-pytorch

Unofficial Pytorch code for "FixMatch: Simplifying Semi-Supervised Learning with Consistency and Confidence" in NeurIPS'20. This repo contains reproduced checkpoints.
Python
190
star
3

DeblurGAN-tf

Unofficial tensorflow (tf) implementation of DeblurGAN: Blind Motion Deblurring Using Conditional Adversarial Networks
Python
68
star
4

TGGNet-keras

Official implementation of Temporal-Guided Networks
Jupyter Notebook
48
star
5

bottom-up-attention-tf

Unofficial tensorflow implementation of "Bottom-up and Top-down attention for VQA" (TF v. 1.13)
Python
39
star
6

Deep-Learning-Tensorflow-Basic

Seminar Materials
Jupyter Notebook
13
star
7

CapsNet-tf

Unofficial implementation of Capsule Networks, Dynamic Routing between capsules (by tensorflow)
Python
11
star
8

Anomaly-Detection-with-K-means

Python
8
star
9

Contrastive_Regularization_for_SSL

Official Pytorch Implementation of "Contrastive Regularization for Semi-Supervised Learning"
8
star
10

Gaussian-Process-Gpy

Gaussian Process Regression with Gpy
Jupyter Notebook
7
star
11

Layer-Recurrent-Neural-Networks-LRNN-tf

Layer Recurrent Neural Network-LRNN-tensorflow-tf
Python
5
star
12

awesome-active-learning

To be released !
3
star
13

Blast_Furnace_Diagonosis

Python
2
star
14

Graph-Convolutional-Networks

related model with GCN
Jupyter Notebook
2
star
15

ML_Implementations

Jupyter Notebook
2
star
16

Anomaly_Detection_VQA

Official implementation of "Regularizing Attention Networks for Anomaly Detection in VQA"
2
star