Samet Hicsonmez#, Abd El Rahman Shabayek#, Djamila Aouada#
#Interdisciplinary Centre for Security, Reliability, and Trust (SnT), University of Luxembourg,
Zero-shot Visual Anomaly Detection (ZSAD) aims to detect and localize anomalies without access to any normal training samples. While recent ZSAD approaches leverage additional modalities such as language to generate fine-grained prompts for localization, vision-only methods remain limited to image-level classification, lacking spatial precision. In this work, we introduce a simple yet effective training-free vision-only ZSAD framework that circumvents the need for fine-grained prompts by leveraging the inversion of a pretrained Denoising Diffusion Implicit Model (DDIM). Specifically, given an input image and a generic text description (e.g., "an image of an [object class]"), we invert the image to obtain latent representations and initiate the denoising process from a fixed intermediate timestep to reconstruct the image. Since the underlying diffusion model is trained solely on normal data, this process yields a normal-looking reconstruction. The discrepancy between the input image and the reconstructed one highlights potential anomalies. Our method achieves performance on par with state-of-the-art ZSAD techniques, demonstrating strong localization capabilities without auxiliary modalities and facilitating a shift away from prompt dependence for anomaly detection research.
This repository contains the official implementation of the paper:
Training Free Zero-Shot Visual Anomaly Localization via Diffusion Inversion
git clone https://gitlab.com/uniluxembourg/snt/cvi2/open/space/divad
cd divad
conda create -n divad python=3.10
conda activate divad
conda install pytorch==2.1.0 torchvision==0.16.0 pytorch-cuda=11.8 -c pytorch -c nvidia
pip install -r requirements.txt
Download and organize the dataset as follows (e.g., MVTec-AD):
|-- /path/to/data/dir
|-- mvtec_anomaly_detection
|-- bottle
|-- ground_truth
|-- broken_large
|-- 000_mask.png
|-- broken_small
|-- 000_mask.png
|-- contamination
|-- 000_mask.png
|-- test
|-- broken_large
|-- 000.png
|-- broken_small
|-- 000.png
|-- contamination
|-- 000.png
|-- good
|-- 000.png
|-- train
|-- good
|-- 000.png
python ddim_inversion.py --data_set mvtec --data_path /path/to/data/mvtec_anomaly_detection --save_inverted_image --nis 50 --inf_step 100 --ss 40 --sd_version 21
Optionally extract foreground masks from CutLER for the test images:
python demo_batch_mvtec_visa.py --opts "MODEL.WEIGHTS" "../cutler_cascade_final.pth"
Run the inference and metric calculation:
python test.py --data_set mvtec --data_path /path/to/data/mvtec_anomaly_detection --use_dino --dino_version v1s8 --save_visuals --mask_dir /path/to/cutler_masks_mvtec --res_dir /path/to/save/results --input_dir /path/to/ddim_results
| Dataset | ROCI | ROCP | PROR | APP | F1-maxP |
|---|---|---|---|---|---|
| MVTec-AD | 75.9 | 88.0 | 72.5 | 31.2 | 35.5 |
| VISA | 69.7 | 93.4 | 78.2 | 19.5 | 24.0 |
| MPDD | 63.4 | 94.9 | 82.0 | 22.9 | 27.0 |
| BTAD | 79.8 | 68.4 | 29.1 | 13.1 | 19.1 |
If you find this work useful, please cite:
@misc{hicsonmez2026training,
title={Training Free Zero-Shot Visual Anomaly Localization via Diffusion Inversion},
author={Samet Hicsonmez and Abd El Rahman Shabayek and Djamila Aouada},
year={2026},
eprint={2601.08022},
archivePrefix={arXiv},
primaryClass={cs.CV},
url={https://arxiv.org/abs/2601.08022},
}
This repository is licensed under the Apache License. See the LICENSE file for details.
This repo builds upon open-source contributions from:
4 commits
Python
100.0%
Samet Hicsonmez#, Abd El Rahman Shabayek#, Djamila Aouada#
#Interdisciplinary Centre for Security, Reliability, and Trust (SnT), University of Luxembourg,
Zero-shot Visual Anomaly Detection (ZSAD) aims to detect and localize anomalies without access to any normal training samples. While recent ZSAD approaches leverage additional modalities such as language to generate fine-grained prompts for localization, vision-only methods remain limited to image-level classification, lacking spatial precision. In this work, we introduce a simple yet effective training-free vision-only ZSAD framework that circumvents the need for fine-grained prompts by leveraging the inversion of a pretrained Denoising Diffusion Implicit Model (DDIM). Specifically, given an input image and a generic text description (e.g., "an image of an [object class]"), we invert the image to obtain latent representations and initiate the denoising process from a fixed intermediate timestep to reconstruct the image. Since the underlying diffusion model is trained solely on normal data, this process yields a normal-looking reconstruction. The discrepancy between the input image and the reconstructed one highlights potential anomalies. Our method achieves performance on par with state-of-the-art ZSAD techniques, demonstrating strong localization capabilities without auxiliary modalities and facilitating a shift away from prompt dependence for anomaly detection research.
This repository contains the official implementation of the paper:
Training Free Zero-Shot Visual Anomaly Localization via Diffusion Inversion
git clone https://gitlab.com/uniluxembourg/snt/cvi2/open/space/divad
cd divad
conda create -n divad python=3.10
conda activate divad
conda install pytorch==2.1.0 torchvision==0.16.0 pytorch-cuda=11.8 -c pytorch -c nvidia
pip install -r requirements.txt
Download and organize the dataset as follows (e.g., MVTec-AD):
|-- /path/to/data/dir
|-- mvtec_anomaly_detection
|-- bottle
|-- ground_truth
|-- broken_large
|-- 000_mask.png
|-- broken_small
|-- 000_mask.png
|-- contamination
|-- 000_mask.png
|-- test
|-- broken_large
|-- 000.png
|-- broken_small
|-- 000.png
|-- contamination
|-- 000.png
|-- good
|-- 000.png
|-- train
|-- good
|-- 000.png
python ddim_inversion.py --data_set mvtec --data_path /path/to/data/mvtec_anomaly_detection --save_inverted_image --nis 50 --inf_step 100 --ss 40 --sd_version 21
Optionally extract foreground masks from CutLER for the test images:
python demo_batch_mvtec_visa.py --opts "MODEL.WEIGHTS" "../cutler_cascade_final.pth"
Run the inference and metric calculation:
python test.py --data_set mvtec --data_path /path/to/data/mvtec_anomaly_detection --use_dino --dino_version v1s8 --save_visuals --mask_dir /path/to/cutler_masks_mvtec --res_dir /path/to/save/results --input_dir /path/to/ddim_results
| Dataset | ROCI | ROCP | PROR | APP | F1-maxP |
|---|---|---|---|---|---|
| MVTec-AD | 75.9 | 88.0 | 72.5 | 31.2 | 35.5 |
| VISA | 69.7 | 93.4 | 78.2 | 19.5 | 24.0 |
| MPDD | 63.4 | 94.9 | 82.0 | 22.9 | 27.0 |
| BTAD | 79.8 | 68.4 | 29.1 | 13.1 | 19.1 |
If you find this work useful, please cite:
@misc{hicsonmez2026training,
title={Training Free Zero-Shot Visual Anomaly Localization via Diffusion Inversion},
author={Samet Hicsonmez and Abd El Rahman Shabayek and Djamila Aouada},
year={2026},
eprint={2601.08022},
archivePrefix={arXiv},
primaryClass={cs.CV},
url={https://arxiv.org/abs/2601.08022},
}
This repository is licensed under the Apache License. See the LICENSE file for details.
This repo builds upon open-source contributions from:
4 commits
Python
100.0%