Skip to content

xcyao00/FOD

Repository files navigation

PyTorch implementation and for ICCV2023 paper, Focus the Discrepancy: Intra- and Inter-Correlation Learning for Image Anomaly Detection.


Installation

Install all packages (the same version with ours) by the following command:

$ pip3 install -r requirements.txt

Download Datasets

Please download MVTecAD dataset from MVTecAD dataset, BTAD dataset from BTAD dataset, and MVTec3D dataset from MVTec3D dataset.

Creating Distance Maps

Please run the following code for creating distance maps used in target correlations.

python create_distance_maps.py 

Creating Reference Features

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

Training and Evaluating

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

Citation

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}
}

About

Pytorch Implementation for ICCV2023 paper: Focus the Discrepancy: Intra- and Inter-Correlation Learning for Image Anomaly Detection

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages