Home

Awesome

AnomalyDetection-SoftPatch/SoftPatch+

This repository contains codes for the official implementation in PyTorch of NeurIPS 2022 paper "SoftPatch: Unsupervised Anomaly Detection with Noisy Data" and its improved version SoftPatch+.

softpatch_intuition

Quick Start

Requirement

Our results were computed using Python 3.8 with packages and respective version noted in requirements.txt.

MVTec-AD

datapath=/path_to_mvtec_folder/mvtec 
datasets=('bottle' 'cable' 'capsule' 'carpet' 'grid' 'hazelnut'
'leather' 'metal_nut' 'pill' 'screw' 'tile' 'toothbrush' 'transistor' 'wood' 'zipper')
dataset_flags=($(for dataset in "${datasets[@]}"; do echo '-d '$dataset; done))

python main.py --dataset mvtec --data_path ../../MVTec --noise 0.1  "${dataset_flags[@]}" --gpu 0

The default setting in run_mvtec.sh runs with 224x224 image size using a WideResNet50-backbone pretrained on ImageNet.

Row Namesimage_aurocpixel_auroc
mvtec_bottle1.00000.9878
mvtec_cable0.99040.9862
mvtec_capsule0.96540.9883
mvtec_carpet0.99650.9920
mvtec_grid1.00000.9939
mvtec_hazelnut1.00000.9906
mvtec_leather1.00000.9931
mvtec_metal_nut0.99870.9845
mvtec_pill0.95620.9798
mvtec_screw0.95260.9944
mvtec_tile0.98660.9645
mvtec_toothbrush0.99310.9860
mvtec_transistor0.99740.9064
mvtec_wood0.98540.9714
mvtec_zipper0.97530.9892
Mean0.98650.9805

To choose other noise discriminator, use the --weight_method argument with 'lof', 'nearest', 'gaussian' or 'lof_gpu'. 'lof_gpu' supports computing LOF using the GPU which usually faster.

To

BTAD

To train SoftPatch on BTAD, run:

datapath=/path_to_btad_folder/BTAD
datasets=('01' '02' '03')
dataset_flags=($(for dataset in "${datasets[@]}"; do echo '-d '$dataset; done))

python main.py --dataset btad --data_path ../../BTAD --noise 0  "${dataset_flags[@]}" --seed 0 \
--gpu 1 --resize 512 --imagesize 512 --sampling_ratio 0.01

The default setting in run_btad.sh runs with 512x512 image size using a WideResNet50-backbone pretrained on ImageNet.

Row Namesimage_aurocpixel_auroc
btad_010.99810.9761
btad_020.93430.9662
btad_030.99690.9935
Mean0.97640.9786

Comments

Citation

Please cite the following paper if this dataset helps your project:

@misc{xisoftpatch,
  title={SoftPatch: Unsupervised Anomaly Detection with Noisy Data},
  author={Xi, Jiang and Liu, Jianlin and Wang, Jinbao and Nie, Qiang and Kai, WU and Liu, Yong and Wang, Chengjie and Zheng, Feng},
  booktitle={Advances in Neural Information Processing Systems}
}

License

This project is licensed under the Apache-2.0 License.