This is the final project for CS-172 Computer Version class.
The aim of this project is to apply anomaly detection in MVTev_AD dataset.
Among current SOTA algorithms involves GAN, CAEs, CNN feature dictionary and variation model have been suggested to tackle the problem.
In this project, we use CNN dictionary based model to assess their performance for segmentation and classification of images in MVTev_AD dataset.
And comparing it with f-AnoGAN, which has already exist pytorch code
Our team members:
Chenyu Wang (wangchy3@shanghaitech.edu.cn)
Yunhao Hu (huyh@shanghaitech.edu.cn)
YiZhou Zhang (zhangyzh@shanghaitech.edu.cn)
Yifeng Li (liyf1@shanghaitech.edu.cn)
Zheng Shu (shuzheng@shanghaitech.edu.cn)
git clone https://github.com/stch-zhangyzh/CV_project
cd CV_project/
pip install -r requires.txt
Go to run the CNN feature:
cd CNN_feature_dictioinary/
python cnn_feature2.py [dataset_name]
The dataset_name can be select from the MVTev_AD dataset:
bottle, cable, capsule, carpet, grid, hazelnut, leather, metal_nut, pill, screw, tile, toothbrush, transistor, wood, zipper
We generat the dictionary vectors in ./dic.npz.
python detection.py [dataset_name]
We generate the threshold for patch and acceptable rate for image in ./thres.npz
We generate the list of detection result of each patch in ./AD_result.npz
The exist pytorch code has been modified to be easy to run.
Go to run the AnoGAN:
cd AnoGAN/
python step1_train_gan.py [dataset_name]
The dataset_name can be select from the MVTev_AD dataset:
bottle, cable, capsule, carpet, grid, hazelnut, leather, metal_nut, pill, screw, tile, toothbrush, transistor, wood, zipper
(The program will help you download dataset_name data in MVTev_AD dataset if you don't have this dataset)
The detailed process is shown in this picture from this paper f-AnoGAN: Fast unsupervised anomaly detection with generative adversarial networks
You can find the output of generator in {dataset_name}_results/images/ to check the training processes of the generator.
The trained generator and discriminator will be saved in {dataset_name}_results/generator and {dataset_name}_results/discriminator
python step2_train_encoder.py [dataset_name]
The detailed process is shown in this picture from this paper f-AnoGAN: Fast unsupervised anomaly detection with generative adversarial networks
You can find the output of the reconfigurated pictures in {dataset_name}_results/images_e/ to check the training processes of the auto-encoder.
The trained encoder will be saved in {dataset_name}_results/encoder.
python step3_anomaly_detection.py [dataset_name]
The test result will be saved in {dataset_name}_results/score.csv in label, img_distance, anomaly_score, z_distance format.
python step4_save_img.py [dataset_name]
The compared images will be saved in {dataset_name}_results/images_diff/ with format (real_img, fake_img, real_img - fake_img).
Start the jupyter notebook:
jupyter notebook
Open the AnoGAN.ipynb file, modify the path to the file {dataset_name}_results/score.csv. And then simply run the hole file.
You can get the roc-auc curve and PR curve.
The dataset and paper:
f-AnoGAN: Fast unsupervised anomaly detection with generative adversarial networks
The reference code of this project is here:
https://github.com/LeeDoYup/AnoGAN-tf

