By Guansong Pang, Choubo Ding, Chunhua Shen, Anton van den Hengel
Official PyTorch implementation of "Explainable Deep Few-shot Anomaly Detection with Deviation Networks".
This implementation is for handling image data. For tabular data, the official implementation is available at deviation-network.
This code is written in Python 3.6 and requires the packages listed in requirements.txt. Install with pip install -r requirements.txt preferably in a virtualenv.
Download the Anomaly Detection Dataset and convert it to MVTec AD format. (For datasets we used in the paper, we provided the convert script.) The dataset folder structure should look like:
DATA_PATH/
subset_1/
train/
good/
test/
good/
defect_class_1/
defect_class_2/
defect_class_3/
...
ground_truth/
defect_class_1/
defect_class_2/
defect_class_3/
...
...
NOTE: The ground_truth folder only available when the dataset has pixel-level annotation.
python train.py --dataset_root=./data/mvtec_anomaly_detection \
--classname=carpet \
--experiment_dir=./experiment \
--epochs=50 \
--n_anomaly=10 \
--n_scales=2dataset_rootdenotes the path of the dataset.classnamedenotes the subset name of the dataset.experiment_dirdenotes the path to store the experiment setting and model weight.epochsdenotes the total epoch of training.n_anomalydenotes the amount of the know outliers.n_scalesdenotes the total scales of multi-scales module.
Visualize the localization result of the trained model by the following command:
python localization.py --dataset_root=./data/mvtec_anomaly_detection \
--classname=carpet \
--experiment_dir=./experiment \
--n_anomaly=10 \
--n_scales=2NOTE: use same argument as the training command.
@article{pang2021explainable,
title={Explainable Deep Few-shot Anomaly Detection with Deviation Networks},
author={Pang, Guansong and Ding, Choubo and Shen, Chunhua and Hengel, Anton van den},
journal={arXiv preprint arXiv:2108.00462},
year={2021}
}