Home

Awesome

CFA for Target-Oriented Anomaly Localization

PWC

PyTorch implementation of CFA: Coupled-hypersphere-based Feature Adaptation for Target-Oriented Anomaly Localization (CFA).

Getting Started

Install packages with:

$ pip install -r requirements.txt

Dataset

Prepare industrial image as:

train data:
    dataset_path/class_name/train/good/any_filename.png
    [...]

test data:
    dataset_path/class_name/test/good/any_filename.png
    [...]

    dataset_path/class_name/test/defect_type/any_filename.png
    [...]

How to train

Example

python trainer_cfa.py --class_name all --data_path [/path/to/dataset/] --cnn wrn50_2 --size 224 --gamma_c 1 --gamma_d 1

Performance

WideResNet-50

R : resize. C : crop

R+CRCFA++
bottle100 / 98.6100 / 98.9100 / 98.9
cable99.8 / 98.799.8 / 99.099.8 / 99.0
capsule97.3 / 98.999.2 / 99.199.2 / 99.1
carpet99.5 / 98.799.4 / 99.099.5 / 99.0
grid99.2 / 97.899.9 / 98.199.9 / 98.1
hazelnut100 / 98.6100 / 98.9100 / 98.9
leather100 / 99.1100 / 99.3100 / 99.3
metalnut100 / 98.8100 / 99.1100 / 99.1
pill97.9 / 98.697.9 / 98.897.9 / 98.8
screw97.3 / 99.093.5 / 98.897.3 / 99.0
tile99.4 / 95.8100 / 96.3100 / 96.3
toothbrush100 / 98.897.2 / 99.1100 / 99.1
transistor100 / 98.3100 / 98.4100 / 98.4
wood99.7 / 94.899.2 / 95.099.7 / 95.0
zipper99.6 / 98.699.5 / 99.099.6 / 99.0
avg.99.3 / 98.299.0 / 98.599.5 / 98.5

Reference

[1] https://github.com/byungjae89/SPADE-pytorch

[2] https://github.com/xiahaifeng1995/PaDiM-Anomaly-Detection-Localization-master

[3] https://github.com/pytorch/vision/tree/main/torchvision/models

[4] https://github.com/lukasruff/Deep-SVDD-PyTorch

Citation

@article{lee2022cfa,
  title={CFA: Coupled-hypersphere-based Feature Adaptation for Target-Oriented Anomaly Localization},
  author={Lee, Sungwook and Lee, Seunghyun and Song, Byung Cheol},
  journal={arXiv preprint arXiv:2206.04325},
  year={2022}
}