/anomaly-detection-mvtec

Anomaly detection in industrial dataset(MVTEC) like capsules, texture, bottle tec... with simple layers and high performance

Primary LanguagePython

Anomaly-Detection

Pytorch implemetation of Anomaly Detection which detect not normal images in industrial datasets mvtec
It has only simple layers but if you want to look out mvtec paper click here.
Actually mvtecAD didn't work well due to finding automatic threshold in finetune stage in my guess. And there is another anomaly detection that is called anoGAN. Anogan use medical images that has 64x64 resolution. And it's too slow because they have to train in testing stage for training z vector. Even if the fast-anogan came out, they use wgan that use linear layers. Using linear layers make constraints that don't make high resolution, and the constraint make networks can't detect small detected parts.
So I use AutoEncoder and AAE. I use conv2d layers in both of them and can make high resolution images(256x256x3). And I use MSE loss in AutoEncoder. But only MSE loss make output images blur. So I make decision to use discriminator to make image clear. That's why I use AAE. There is one weekness in this code, which is we have to use manualy fixed threshold.

Tensorflow version

Tensorflow implementation of MVTEC-AD which is implemetation in mvtec paper linked above.

Simple CNN models(AutoEncoder)

Adversary Variational AutoEncoder

Prerequisites

  • Linux or macOS
  • python3+
  • Pytorch 0.4+

Installation

git clone https://github.com/CY-Jeong/anomaly-detection-mvtec.git
cd anomaly-detection-mvtec
  • Pip users, pip install -r requirements.txt
  • Conda users, conda env create -f environment.yml

Usage

First, download MVTEC datasets.

mkdir [data location]
cd [data location]
wget ftp://guest:GU%2E205dldo@ftp.softronics.ch/mvtec_anomaly_detection/mvtec_anomaly_detection.tar.xz
tar Jxvf mvtec_anomaly_detection.tar.xz

To train a model

python train.py --data_dir [data location] --save_dir [save location] --model [aae | cae]

If you choose CAE, the n_epochs should be 1000 more, or 60 epochs in aae. To test a model

python test.py --data_dir [data location] --save_dir [save location] --model [aae | cae]

Results

Related Projects

Anogan|VAE-Anomaly-Detection Deep Anomaly Detection Using Geometric Transformations
Out-of-Distribution NN|Out-of-Distribution GAN