FAIR
August 23, 2025 · View on GitHub
This is the official implementation for the paper 'Simple and Effective Frequency-aware Image Restoration for Industrial Visual Anomaly Detection'. If you have any questions, you could contact ltk98633@stu.xjtu.edu.cn
Different data_loader.py files correspond to different high-frequency extractors. Code of FAIRm (using morphological gradient) can be found in https://github.com/liutongkun/EdgRec
Errata
We would like to correct several errors in Table 1 of the paper.
The parameters in our table are expressed in MB, where 1 MB equals 1024 × 1024. For RD++ and DeSTSeg, we mistakenly multiplied the values by 4. The correct values should be 104.2 and 33.5, respectively
The reimplemented segmentation performance of PatchCore on the VisA dataset should be 97.7% (pixel-level, AUROC) rather than 98.8%, and 88.4% (PRO metric) rather than 91.6%.
The FPS of RD4AD is 83.3, rather than the incorrectly reported value of 37.5 in the paper.
For our method, the FPS of FAIRxy should be 64.5 rather than 57.0.
Moreover, in the original code, the Fourier transform implemented with NumPy can be directly replaced with the more efficient CuPy library (by substituting all instances of np.fft with cupy.fft without requiring retraining). With this modification, the FPS of FAIR increases from 57.0 to 60.0, FAIR64 rises from 100.0 to 117.6, FAIR32 rises from 132.0 to 169.5. This is especially important for high-resolution images, as NumPy performs Fourier transforms relatively slowly.
We apologize for these mistakes and any confusion they may have caused.
Preparation
The method is evaluated on:
the MVTec AD dataset: https://www.mvtec.com/company/research/datasets/mvtec-ad
the VisA dataset: https://github.com/amazon-science/spot-diff
Training
#20240828: The dataloader.py with “newaug” introduces NSA as an aditional synthesized anomaly, achieving a 99.1% image-level AUROC on the MVTec AD dataset.
MVTec AD
The original code uses the DTD dataset to create synthesized anomalies, so you first need to download it
:
the DTD dataset (optional): https://www.robots.ox.ac.uk/~vgg/data/dtd/
Then
python train.py --gpu_id 0 --obj_id -1 --lr 0.0001 --bs 8 --epochs 800 --data_path /home/b211-3090ti/Anomaly-Dataset/mvtec_ad/ --anomaly_source_path /home/b211-3090ti/Anomaly-Dataset/dtd/images --log_path /home/b211-3090ti/FAIR/checkpoints_mvtecad/ --checkpoint_path /home/b211-3090ti/FAIR/checkpoints_mvtecad/ --visualize
Change all the involved paths to your own paths
VisA
activate line 16 and line 76 in data_loaderbhpfnoDTD.py
self.images = sorted(glob.glob(root_dir+"/*/*.JPG"))
mask_file_name = file_name.split(".")[0]+".png"
Without extra data
It's also feasible to train it without extra data, just activate line 3 in train.py:
from data_loaderbhpfnoDTD import MVTecTrainDataset
Then
python train.py --gpu_id 0 --obj_id -1 --lr 0.0001 --bs 8 --epochs 800 --data_path /home/b211-3090ti/Anomaly-Dataset/mvtec_ad/ --log_path /home/b211-3090ti/FAIR/checkpoints_mvtecad/ --checkpoint_path /home/b211-3090ti/FAIR/checkpoints_mvtecad/ --visualize
Testing
python test.py --gpu_id 0 --base_model_name FAIR_0.0001_800_bs8 --data_path /home/b211-3090ti/Anomaly-Dataset/mvtec_ad/ --checkpoint_path /home/b211-3090ti/FAIR/checkpoints_mvtecad/
Change all the involved paths to your own paths
If you want to visualize the results, add
--saveimages
Pre-trained models
MVTec AD
https://drive.google.com/file/d/1hbl_k_hKgxo_IejNNu8daEYJkfLN3Wxk/view?usp=sharing #20240828 using new synthesized anomalies
https://drive.google.com/file/d/1uwodfQZSXNq_TToio0r8gflUCg1EwSJv/view?usp=sharing
https://pan.baidu.com/s/1y8eocVy8FKf88nCkyd_4_A jc5j
VisA
https://drive.google.com/file/d/1G2YosWUgJzGWq5S4OsPFHE0jShXmHHhd/view?usp=sharing #20240828 using new synthesized anomalies
https://drive.google.com/file/d/1DKYOqZAE-wbjRamk8xBhKB1Q2qswYxFR/view?usp=sharing
https://pan.baidu.com/s/1uS6etphpGiVDKTGPYjDdCg qecd
Acknowledgment
We use the codes from https://github.com/VitjanZ/DRAEM, https://github.com/taikiinoue45/RIAD, and https://www.mvtec.com/company/research/datasets/mvtec-3d-ad, https://github.com/hmsch/natural-synthetic-anomalies
A big thanks to their great work