This repository contains the official PyTorch implementation of our ICLR 2025 paper:
"Mitigating Spurious Negative Pairs for Robust Industrial Anomaly Detection"
by Hossein Mirzaie, Mojtaba Nafez, Jafar Habibi, Mohammad Sabokrou, and Mohammad Hossein Rohban.
For a quick start, try out our training and inference pipeline directly in Google Colab:
👉 Launch Colab Notebook
Below are the datasets used in our experiments:
- MVTec AD Dataset
- ImageNet-30: Train, Test
- VisA Dataset
- DAGM Dataset
- ISIC 2018
Install the required dependencies using:
pip install -r requirements.txt
In the Colab file, you can find the exact arguments used for both high and low-resolution datasets.
To train a one-class anomaly detection model, run:
python train.py --train_time_adv_evaluate --train_time_clean_evaluate \
--one_class_idx $class_num --evaluate_save_step $evaluate_save_step \
--dataset $dataset --model $model --epochs $epochs --batch_size $batch_size \
--epsilon $train_epsilon
Arguments:
one_class_idx
: Specifies the in-distribution class for one-class training.epsilon
: Controls PGD strength during training.
To train our unlabeled multi-class setup (code & example coming soon):
# Coming soon
In the Colab file, you can find the exact arguments used for both high and low-resolution datasets.
- We provide pre-trained checkpoints for the COBRA model:
🔗 Download Checkpoints
python eval.py --out_attack --in_attack \
--one_class_idx $class_num --dataset $dataset --model $model \
--print_score --eps $eval_epsilon --load_path $model_path \
--batch_size $batch_size --test_batch_size $batch_size
Options:
out_attack
: Apply PGD-100 only on anomalous samples.in_attack
: Apply PGD-100 o 62D4 nly on normal samples.one_class_idx
: Specifies the target class for evaluation.- Use
resize_factor
andresize_fix
to control cropping withRandomResizedCrop()
.
# Coming soon
If you find this work helpful, please consider citing:
@inproceedings{
mirzaei2025adversarially,
title={Adversarially Robust Anomaly Detection through Spurious Negative Pair Mitigation},
author={Hossein Mirzaei and Mojtaba Nafez and Jafar Habibi and Mohammad Sabokrou and Mohammad Hossein Rohban},
booktitle={The Thirteenth International Conference on Learning Representations},
year={2025},
url={https://openreview.net/forum?id=t8fu5m8R5m}
}