Home

Awesome

Hierarchical Gaussian Mixture Normalizing Flows Modeling for Unified Anomaly Detection

PyTorch implementation for ECCV2024 paper, Hierarchical Gaussian Mixture Normalizing Flows Modeling for Unified Anomaly Detection.

<img src="./HGAD-framework.png" width="800">

Installation

Install all packages with this command:

$ python3 -m pip install -U -r requirements.txt

Download Datasets

Please download MVTecAD dataset from MVTecAD dataset, BTAD dataset from BTAD dataset, MVTecAD-3D dataset from MVTecAD-3D dataset, and VisA dataset VisA dataset.

Training

python main.py --dataset mvtec --seed 0 --gpu 0

Normally, you can obtain the following results:

CategoryImage/Pixel AUCCategoryImage/Pixel AUCCategoryImage/Pixel AUC
Carpet1.000/0.994Bottle1.000/0.986Pill0.966/0.988
Grid0.997/0.991Cable0.970/0.959Screw0.961/0.993
Leather1.000/0.996Capsule0.988/0.992Toothbrush0.911/0.990
Tile1.000/0.961Hazelnut0.998/0.988Transistor0.977/0.913
Wood0.996/0.959Metal nut1.000/0.981Zipper0.999/0.990
Mean0.984/0.979
python main.py --dataset btad --seed 0 --gpu 0

Normally, you can obtain the following results:

CategoryImage/Pixel AUCCategoryImage/Pixel AUCCategoryImage/Pixel AUC
011.000/0.976020.859/0.973030.987/0.990
Mean0.949/0.980
python main.py --dataset mvtec3d --seed 0 --gpu 0

Normally, you can obtain the following results:

CategoryImage/Pixel AUCCategoryImage/Pixel AUCCategoryImage/Pixel AUC
Bagel0.977/0.988Cable gland0.963/0.995Carrot0.889/0.988
Cookie0.734/0.966Dowel0.960/0.992Foam0.811/0.917
Peach0.829/0.994Potato0.690/0.950Rope0.976/0.992
Tire0.876/0.986Mean0.871/0.977
python main.py --dataset visa --seed 0 --gpu 0

Normally, you can obtain the following results:

CategoryImage/Pixel AUCCategoryImage/Pixel AUCCategoryImage/Pixel AUC
Candle0.988/0.995Capsules0.956/0.990Cashew0.910/0.991
Chewinggum0.999/0.996Fryum0.984/0.949Macaroni10.991/0.998
Macaroni20.926/0.997Pcb10.976/0.995Pcb20.956/0.983
Pcb30.986/0.994Pcb40.979/0.987Pipe fyrum0.996/0.993
Mean0.971/0.989
python main.py --dataset union --seed 0 --gpu 0

We also report the detailed results on the Union dataset as follows:

CategoryImage/Pixel AUCCategoryImage/Pixel AUCCategoryImage/Pixel AUC
Bottle1.000/0.982Cable0.951/0.860Capsule0.934/0.990
Carpet1.000/0.993Grid0.986/0.983Hazelnut1.000/0.985
Leather1.000/0.995Metal nut0.997/0.981Pill0.969/0.984
Screw0.812/0.986Tile0.999/0.936Toothbrush0.961/0.992
Transistor0.996/0.901Wood0.994/0.957Zipper0.999/0.992
010.997/0.974020.838/0.969030.995/0.997
Bagel0.983/0.991Cable gland0.886/0.990Carrot0.815/0.990
Cookie0.792/0.972Dowel0.896/0.978Foam0.798/0.913
Peach0.856/0.993Potato0.625/0.958Rope0.929/0.994
Tire0.835/0.965
Candle0.989/0.996Capsules0.939/0.975Cashew0.928/0.987
Chewinggum0.996/0.996Fryum0.976/0.938Macaroni10.975/0.997
Macaroni20.903/0.995Pcb10.964/0.992Pcb20.966/0.972
Pcb30.964/0.990Pcb40.981/0.981Pipe fyrum0.991/0.992
Mean0.935/0.975

Note: You need to set the root directory of your dataset in the main.py by setting args.data_path. For Union dataset, the dataset path can be set in the datasets/union.py script.

Citation

If you find this repository useful, please consider citing our work:

@article{HGAD,
      title={Hierarchical Gaussian Mixture Normalizing Flows Modeling for Unified Anomaly Detection}, 
      author={Xincheng Yao and Ruoqi Li and Zefeng Qian and Lu Wang and Chongyang Zhang},
      year={2024},
      booktitle={European Conference on Computer Vision 2024},
      url={https://arxiv.org/abs/2403.13349},
      primaryClass={cs.CV}
}

If you are interested in our work, you can also follow our other works: BGAD (CVPR2023), PMAD (AAAI2023), FOD (ICCV2023), ResAD (NeurIPS2024). Or, you can follow our github page xcyao00.