Home

Awesome

REB

official source code for REB:Reducing Biases in Representation for Industrial Anomaly Detection

<details open> <summary>Install</summary>
$ git clone https://github.com/ShuaiLYU/REB
$ cd REB
$ conda create -n reb python==3.10.6
$ conda install pytorch==1.12.1 torchvision==0.13.1 torchaudio==0.12.1 cudatoolkit=11.3 -c pytorch

$ pip install -r requirements.txt
</details> <details open> <summary>Training on Mvtec AD </summary>

Run commands below to reproduce results on Mvtec AD

  1. you are advised to download Mvtec ad dataset with saliency from BaiduNetdisk (code: 1234) or OneDrive.
    you can also generate saliency by yourself with teh EDN saliency model

  2. modify the dataset path and OUTPUT path in global_param.py according to your personal config.
    the best K for Mvtec is 9. set K value in argparse or global_param.py

  3. Run commands below to train

$ cd  REB/projects/reb_mvtec
#  Self-supervied learning  (fine-turning ImageNet-pretrained model with DefectMaker))  Resnet18
python main.py  -exp_name res18_dm_com6_bs1024_epo300   -K 9 -run_name run1  -run_mode 0

# only run LDKNN (after fine-turning ImageNet-pretrained model with DefectMaker)  Resnet18
$ python main.py  -exp_name res18_dm_com6_bs1024_epo300    -K 9 -run_name run1  -run_mode 1


# DefectMaker + LDKNN  (REB)  Resnet18
$ python main.py  -exp_name res18_dm_com6_bs1024_epo300  -K 9  -run_name run1  -run_mode 2
</details> <details open> <summary>Training on Mvtec LOCO </summary>

Run commands below to reproduce results on Mvtec AD LOCO

  1. we don't use saliency for Mvtec LOCO

  2. modify the dataset path and OUTPUT path in global_param.py according to your personal config.
    the best K for Mvtec LOCO is 45. set K value in argparse or global_param.py

  3. Run commands below to train

$ cd  REB/projects/reb_mvtec_loco
#  Self-supervied learning  (fine-turning ImageNet-pretrained model with DefectMaker))  Resnet18
python main.py  -exp_name res18_dm_com6_bs1024_epo300  -K 45 -run_name run1  -run_mode 0

# only run LDKNN (after fine-turning ImageNet-pretrained model with DefectMaker)  Resnet18
$ python main.py  -exp_name res18_dm_com6_bs1024_epo300 -K 45  -run_name run1  -run_mode 1

# only run LDKNN ( directly use ImageNet-pretrained model)   Resnet18
$ python main.py  -exp_name res18_imagenet -K 45 -run_name run1  -run_mode 1

# DefectMaker + LDKNN  (REB)   Resnet18
$ python main.py  -exp_name res18_dm_com6_bs1024_epo300  -K 45 -run_name run1  -run_mode 2


# only run LDKNN ( directly use ImageNet-pretrained model)  Resnet18  
$ python main.py  -exp_name res18_imagenet   -K 45 -run_name run1  -run_mode 1

# only run LDKNN ( directly use ImageNet-pretrained model)  wideRes50 
$ python main.py  -exp_name wr50_imagenet   -K 45 -run_name run1  -run_mode 1

# only run LDKNN ( directly use ImageNet-pretrained model)  wideRes101 
$ python main.py  -exp_name wr101_imagenet   -K 45  -run_name run1  -run_mode 1

</details>

Tutorials

Bezier_gen

DefectMaker