Skip to content

Latest commit

 

History

History

GANomaly2d

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 

GANomaly2d

This is the implementation of "GANomaly" corresponding to 2-dimensional shape.
Original paper: S. Akçay, A. Atapour-Abarghouei, and T. P. Breckon. Ganomaly: Semi-supervised anomaly detection via adversarial training. In Proceedings of the 14th Asian Conference on Computer Vision, 2018. link

Usage

1. Build

Please build the source file according to the procedure.

$ mkdir build
$ cd build
$ cmake ..
$ make -j4
$ cd ..

2. Dataset Setting

Recommendation

  • MVTec Anomaly Detection Dataset (MVTec AD)
    This is a dataset for benchmarking anomaly detection methods with a focus on industrial inspection.
    Link: official

Setting

Please create a link for the dataset.
The following hierarchical relationships are recommended.

datasets
|--Dataset1
|    |--train
|    |    |--image1.png
|    |    |--image2.bmp
|    |    |--image3.jpg
|    |
|    |--valid
|    |--test_anomaly
|    |--test_normal
|
|--Dataset2
|--Dataset3

You should substitute the path of training normal data for "<training_path>", test anomaly data for "<test_anomaly_path>", test normal data for "<test_normal_path>", respectively.
The following is an example for "MVTecAD".

$ cd datasets
$ mkdir MVTecAD
$ cd MVTecAD
$ ln -s <training_path> ./train
$ ln -s <test_anomaly_path> ./test_anomaly
$ ln -s <test_normal_path> ./test_normal
$ cd ../..

3. Training

Setting

Please set the shell for executable file.

$ vi scripts/train.sh

The following is an example of the training phase.
If you want to view specific examples of command line arguments, please view "src/main.cpp" or add "--help" to the argument.

#!/bin/bash

DATA='MVTecAD'

./GANomaly2d \
    --train true \
    --epochs 300 \
    --dataset ${DATA} \
    --size 256 \
    --batch_size 16 \
    --gpu_id 0 \
    --nc 3

Run

Please execute the following to start the program.

$ sh scripts/train.sh

4. Test

Setting

Please set the shell for executable file.

$ vi scripts/test.sh

The following is an example of the test phase.
If you want to view specific examples of command line arguments, please view "src/main.cpp" or add "--help" to the argument.

#!/bin/bash

DATA='MVTecAD'
HEATMAP_MAX=0.1

./GANomaly2d \
    --test true \
    --dataset ${DATA} \
    --test_dir "test_anomaly" \
    --test_result_dir "test_result_anomaly" \
    --heatmap_max ${HEATMAP_MAX} \
    --size 256 \
    --gpu_id 0 \
    --nc 3
    
./GANomaly2d \
    --test true \
    --dataset ${DATA} \
    --test_dir "test_normal" \
    --test_result_dir "test_result_normal" \
    --heatmap_max ${HEATMAP_MAX} \
    --size 256 \
    --gpu_id 0 \
    --nc 3

Run

Please execute the following to start the program.

$ sh scripts/test.sh

5. Anomaly Detection

Setting

Please set the shell for executable file.

$ vi scripts/anomaly_detection.sh

The following is an example of the anomaly detection phase.
If you want to view specific examples of command line arguments, please view "src/main.cpp" or add "--help" to the argument.

#!/bin/bash

DATA='MVTecAD'

./GANomaly2d \
    --AD true \
    --dataset ${DATA} \
    --anomaly_path "test_result_anomaly/anomaly_score.txt" \
    --normal_path "test_result_normal/anomaly_score.txt" \
    --n_thresh 256

Run

Please execute the following to start the program.

$ sh scripts/anomaly_detection.sh

Acknowledgments

This code is inspired by ganomaly.