Skip to content

Commit

Permalink
Updated README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
samet-akcay committed Aug 12, 2019
1 parent 26305aa commit 584a736
Showing 1 changed file with 36 additions and 81 deletions.
117 changes: 36 additions & 81 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

This repository contains PyTorch implementation of the following paper: GANomaly: Semi-Supervised Anomaly Detection via Adversarial Training [[1]](#reference)

## Table of Contents
## 1. Table of Contents
- [GANomaly](#ganomaly)
- [Table of Contents](#table-of-contents)
- [Prerequisites](#prerequisites)
- [Installation](#installation)
- [Experiment](#experiment)
- [Training](#training)
- [Training on MNIST](#training-on-mnist)
Expand All @@ -15,59 +15,65 @@ This repository contains PyTorch implementation of the following paper: GANomaly
- [Reference](#reference)


## Installation
## 2. Installation
1. First clone the repository
```
git clone https://github.com/samet-akcay/ganomaly.git
```
2. Install PyTorch and torchvision from [https://pytorch.org](https://pytorch.org/)
2. Create the virtual environment via conda
```
conda create -n ganomaly python=3.7
```
3. Activate the virtual environment.
```
conda activate ganomaly
```
3. Install the dependencies.
```
pip install -r requirements.txt
pip install --user --requirement requirements.txt
```
## Experiment
## 3. Experiment
To replicate the results in the paper for MNIST and CIFAR10 datasets, run the following commands:
To replicate the results in the paper, run the following commands:

For MNIST experiments:
``` shell
# MNIST
sh experiments/run_mnist.sh
```
For CIFAR experiments:
``` shell
sh experiments/run_cifar.sh
# CIFAR
sh experiments/run_cifar.sh # CIFAR10
```

## Training
## 4. Training
To list the arguments, run the following command:
```
python train.py -h
```

### Training on MNIST
### 4.1. Training on MNIST
To train the model on MNIST dataset for a given anomaly class, run the following:

```
python train.py \
--dataset mnist \
--niter <number-of-epochs> \
--anomaly_class <0,1,2,3,4,5,6,7,8,9>
--dataset mnist \
--niter <number-of-epochs> \
--abnormal_class <0,1,2,3,4,5,6,7,8,9> \
--display # optional if you want to visualize
```

### Training on CIFAR10
### 4.2. Training on CIFAR10
To train the model on CIFAR10 dataset for a given anomaly class, run the following:

```
python train.py \
--dataset cifar10 \
--niter <number-of-epochs> \
--anomaly_class \
<plane, car, bird, cat, deer, dog, frog, horse, ship, truck>
--dataset cifar10 \
--niter <number-of-epochs> \
--abnormal_class \
<plane, car, bird, cat, deer, dog, frog, horse, ship, truck> \
--display # optional if you want to visualize
```

### Train on Custom Dataset
### 4.3. Train on Custom Dataset
To train the model on a custom dataset, the dataset should be copied into `./data` directory, and should have the following directory & file structure:

```
Expand Down Expand Up @@ -98,64 +104,13 @@ Then model training is the same as training MNIST or CIFAR10 datasets explained
python train.py \
--dataset <name-of-the-data> \
--isize <image-size> \
--niter <number-of-epochs>
--niter <number-of-epochs> \
--display # optional if you want to visualize
```

For more training options, run `python train.py -h` as shown below:
```
usage: train.py [-h] [--dataset DATASET] [--dataroot DATAROOT]
[--batchsize BATCHSIZE] [--workers WORKERS] [--droplast]
[--isize ISIZE] [--nc NC] [--nz NZ] [--ngf NGF] [--ndf NDF]
[--extralayers EXTRALAYERS] [--gpu_ids GPU_IDS] [--ngpu NGPU]
[--name NAME] [--model MODEL]
[--display_server DISPLAY_SERVER]
[--display_port DISPLAY_PORT] [--display_id DISPLAY_ID]
[--display] [--outf OUTF] [--manualseed MANUALSEED]
[--anomaly_class ANOMALY_CLASS] [--print_freq PRINT_FREQ]
[--save_image_freq SAVE_IMAGE_FREQ] [--save_test_images]
[--load_weights] [--resume RESUME] [--phase PHASE]
[--iter ITER] [--niter NITER] [--beta1 BETA1] [--lr LR]
[--alpha ALPHA]
optional arguments:
-h, --help show this help message and exit
--dataset folder | cifar10 | mnist (default: cifar10)
--dataroot path to dataset (default: '')
--batchsize input batch size (default: 64)
--workers number of data loading workers (default: 8)
--droplast Drop last batch size. (default: True)
--isize input image size. (default: 32)
--nc input image channels (default: 3)
--nz size of the latent z vector (default: 100)
--ngf Number of features of the generator network
--ndf Number of features of the discriminator network.
--extralayers Number of extra layers on gen and disc (default: 0)
--gpu_ids gpu ids: e.g. 0 0,1,2, 0,2. use -1 for CPU (default: 0)
--ngpu number of GPUs to use (default: 1)
--name name of the experiment (default: experiment_name)
--model chooses which model to use. (default:ganomaly)
--display_server visdom server of the web display (default: http://localhost)
--display_port visdom port of the web display (default: 8097)
--display_id window id of the web display (default: 0)
--display Use visdom. (default: False)
--outf folder to output images and model checkpoints (default: ./output)
--manualseed manual seed (default: None)
--anomaly_class Anomaly class idx for mnist and cifar datasets (default: car)
--print_freq frequency of showing training results on console (default: 100)
--save_image_freq frequency of saving real and fake images (default:100)
--save_test_images Save test images for demo. (default: False)
--load_weights Load the pretrained weights (default: False)
--resume path to checkpoints (to continue training) (default: '')
--phase train, val, test, etc (default: train)
--iter Start from iteration i (default: 0)
--niter number of epochs to train for (default: 15)
--beta1 momentum term of adam (default: 0.5)
--lr initial learning rate for adam (default: 0.0002)
--alpha alpha to weight l1 loss. default=500 (default: 50)
```
For more training options, run `python train.py -h`.

## Citing GANomaly
## 5. Citing GANomaly
If you use this repository or would like to refer the paper, please use the following BibTeX entry
```
@inproceedings{akcay2018ganomaly,
Expand All @@ -168,5 +123,5 @@ If you use this repository or would like to refer the paper, please use the foll
}
```

## Reference
[[1] Akcay S., Atapour-Abarghouei A., Breckon T.P. (2019) GANomaly: Semi-supervised Anomaly Detection via Adversarial Training. In: Jawahar C., Li H., Mori G., Schindler K. (eds) Computer Vision – ACCV 2018. ACCV 2018. Lecture Notes in Computer Science, vol 11363. Springer, Cham
## 6. Reference
[1] Akcay S., Atapour-Abarghouei A., Breckon T.P. (2019) GANomaly: Semi-supervised Anomaly Detection via Adversarial Training. In: Jawahar C., Li H., Mori G., Schindler K. (eds) Computer Vision – ACCV 2018. ACCV 2018. Lecture Notes in Computer Science, vol 11363. Springer, Cham

0 comments on commit 584a736

Please sign in to comment.