PyTorch implementation and for ICCV2023 paper, Focus the Discrepancy: Intra- and Inter-Correlation Learning for Image Anomaly Detection.
Install all packages (the same version with ours) by the following command:
$ pip3 install -r requirements.txt
Please download MVTecAD dataset from MVTecAD dataset, BTAD dataset from BTAD dataset, and MVTec3D dataset from MVTec3D dataset.
Please run the following code for creating distance maps used in target correlations.
python create_distance_maps.py
Please run the following code for generating external reference features (based on wide_resnet50
).
# For MVTecAD
python create_ref_features.py --dataset mvtec --data_path /path/to/your/dataset --backbone_arch wide_resnet50_2 --save_path rfeatures_w50
# For BTAD
python create_ref_features.py --dataset btad --data_path /path/to/your/dataset --backbone_arch wide_resnet50_2 --save_path rfeatures_w50
# For MVTec3D-RGB
python create_ref_features.py --dataset mvtec3d --data_path /path/to/your/dataset --backbone_arch wide_resnet50_2 --save_path rfeatures_w50
In this repository, we use wide_resnet50
as the feature extractor by default.
As we find this can get slightly better results than efficientnet-b6
reported in the paper.
- Run code for training and evaluating MVTecAD
python main.py --dataset mvtec --data_path /path/to/your/dataset --backbone_arch wide_resnet50_2 --rfeatures_path rfeatures_w50 --with_intra --with_inter --save_prefix mvtec
- Run code for training and evaluating BTAD
python main.py --dataset btad --data_path /path/to/your/dataset --backbone_arch wide_resnet50_2 --rfeatures_path rfeatures_w50 --with_intra --with_inter --save_prefix btad
- Run code for training and evaluating MVTec3D-RGB
python main.py --dataset mvtec3d --data_path /path/to/your/dataset --backbone_arch wide_resnet50_2 --rfeatures_path rfeatures_w50 --with_intra --with_inter --save_prefix mvtec3d
If you find this repository useful, please consider citing our work:
@article{FOD,
title={Focus the Discrepancy: Intra- and Inter-Correlation Learning for Image Anomaly Detection},
author={Xincheng Yao and Ruoqi Li and Zefeng Qian and Yan Luo and Chongyang Zhang},
year={2023},
booktitle={International Conference on Computer Vision 2023},
url={https://arxiv.org/abs/2308.02983},
primaryClass={cs.CV}
}
If you are interested in our work, you can also follow our other works: BGAD (CVPR2023), PMAD (AAAI2023), ResAD (NeurIPS2024), HGAD (ECCV2024). Or, you can follow our github page xcyao00.