A Unified Anomaly Synthesis Strategy with Gradient Ascent for Industrial Anomaly Detection and Localization
Qiyu Chen, Huiyuan Luo, Chengkan Lv*, Zhengtao Zhang
- 📖 Introduction
- 🔧 Environments
- 📊 Data Preparation
- 🚀 Run Experiments
- 📂 Dataset Release
- 🔗 Citation
- 🙏 Acknowledgements
- 📜 License
This repository contains source code for GLASS implemented with PyTorch. GLASS is a unified framework designed to enhance unsupervised anomaly detection by addressing the limitations in coverage and controllability of existing anomaly synthesis strategies, particularly for weak defects that resemble normal regions.
This repository also contains the self-built datasets (WFDD, MAD-man, and MAD-sys) proposed in our paper.
Create a new conda environment and install required packages.
conda create -n glass_env python=3.9.15
conda activate glass_env
pip install -r requirements.txt
Experiments are conducted on NVIDIA Tesla A800 (80GB). Same GPU and package version are recommended.
The public datasets employed in the paper are listed below. DTD is an auxiliary texture dataset used for data augmentation in GLASS, while the other datasets are used for anomaly detection evaluation. These dataset folders/files follow its original structure.
- DTD (Download link)
- MVTec AD (Download link)
- VisA (Download link)
- MPDD (Download link)
We also release the model weights of GLASS-j on MVTec AD reported in the paper. If you want to further explore based on these models, you need to download the results folder (Download link) and move it to the root directory of this repository. Note that you should clear the existing results folder before moving.
Edit ./shell/run-dataset.sh
to configure arguments --datapath
, --augpath
, --classes
, and hyperparameter settings.
Please modify argument --test
to 'ckpt' / 'test' to toggle between training and testing modes.
bash run-dataset.sh
"Note that 'dataset' refers to any dataset.
Currently, the shell
folder contains scripts for six datasets,
such as run-mvtec.sh
for MVTec AD. If you want to train your own dataset,
please create a new run-*.sh
file."
1.WFDD (Download link)
The Woven Fabric Defect Detection (WFDD) dataset includes 4101 woven fabric images categorized into 4 categories: grey cloth, grid cloth, yellow cloth, and pink flower. The first three classes are collected from the industrial production sites of WEIQIAO Textile, while the 'pink flower' class is gathered from the publicly available Cloth Flaw Dataset. Each category contains block-shape, point-like, and line-type defects with pixel-level annotations.
2.MAD-man (Download link)
The MVTec AD-manual (MAD-man) test set is constructed to evaluate weak defect detection. It includes samples independently selected by 5 individuals from all 15 categories of MVTec AD. Each subset contains 2 normal and 6 anomaly samples per category.
3.MAD-sys (Download link)
The MVTec AD-synthesis (MAD-sys) test set is constructed from 5 texture categories of MVTec AD. It includes 4 subsets with varying degrees of weak defects which are adjusted by the transparency coefficient. Each subset contains 320 normal and 946 anomaly samples.
"Note that due to weak defects under β=0.9 which are very close to normal, we did not use the 5th subset in our study. However, we choose to release this subset, sincerely hoping that future work can further address this challenge."
4.Foreground Mask (Download link)
The foreground masks of normal samples from various datasets are obtained through binarization
inspired by BGAD.
If a dataset does not have or require the foreground masks,
please set argument --fg
to '0' in shell script.
Please cite the following paper if the code and dataset help your project:
@article{chen2024unified,
title={A Unified Anomaly Synthesis Strategy with Gradient Ascent for Industrial Anomaly Detection and Localization},
author={Chen, Qiyu and Luo, Huiyuan and Lv, Chengkan and Zhang, Zhengtao},
journal={arXiv preprint arXiv:2407.09359},
year={2024}
}
Thanks for the great inspiration from SimpleNet.
The code and dataset in this repository are licensed under the MIT license.