MRAD: Zero-Shot Anomaly Detection with Memory-Driven Retrieval
MRAD is a novel approach for zero-shot anomaly detection that leverages memory banks and CLIP features. By building retrieval-augmented memory banks from auxiliary datasets, MRAD achieves strong cross-domain anomaly detection and localization without any target domain training data. This repository provides three model variants with different trade-offs:
| Model | Description | Training | Weights |
|---|---|---|---|
| MRAD-CLIP | Full model with memory bank + CLIP image-text alignment | 6 epochs | patch_proj, image_proj, prompt_learner, prompt_proj |
| MRAD-FT | Fine-tuned model with memory bank projection | 1 epoch | patch_proj, image_proj |
| MRAD-TF | Train-free baseline using raw CLIP features | None | None |
pip install -r requirements.txtDownload the dataset below:
-
Industrial Domain: MVTec, VisA, MPDD, BTAD, DTD-Synthetic
-
Medical Domain: HeadCT, BrainMRI, Br35H, CVC-ClinicDB, CVC-ColonDB, Kvasir, ISIC, Endo
Generate the dataset JSON (same as AnomalyCLIP)
Take MVTec AD for example:
Structure of MVTec Folder:
mvtec/
│
├── meta.json
│
├── bottle/
│ ├── ground_truth/
│ │ ├── broken_large/
│ │ │ └── 000_mask.png
│ │ │ └── ...
│ │ └── ...
│ └── test/
│ ├── broken_large/
│ │ └── 000.png
│ │ └── ...
│ └── ...
│
└── ...
cd generate_dataset_json
python mvtec.pySelect the corresponding script and run it. The generated JSON stores all the information that MRAD needs.
- Quick start with pre-trained weights (MRAD-CLIP, trained on VisA, tested on MVTec):
python test.py \
--model_type mrad-clip \
--checkpoint_path ./checkpoints/test_on_mvtec.pth \
--dataset mvtec \
--data_path ./data/MVTEC \
--cache_dir ./cache \
--save_path ./results/test_on_mvtec \
--device cuda:0- Train your own weights:
python train.py \
--model_type mrad-clip \
--dataset visa \
--data_path ./data/VISA \
--save_path ./checkpoints/mrad_clip \
--cache_dir ./cache \
--device cuda:0Before running the above commands, please download the official memory banks from this link and the corresponding MRAD-CLIP model weights from this link, and place them under ./cache and ./checkpoints respectively.
The ./cache directory stores the memory banks built from MVTec and VisA. If you want to rebuild the memory banks from scratch, please set the load_cache argument of both build_cache_model and build_patch_cache_model to False in train.py.
- End-to-end pipeline (train on VisA + test on MVTec):
If you want to retrain from scratch, you can use the following command as a quick start, but please set the GPU device according to your actual environment.
bash run.sh mrad-clipYou can switch model variants by changing --model_type to mrad-ft or mrad-clip.
We train on VisA and test on all other datasets. For VisA, MRAD is trained on MVTec.
We thank the authors of the following code repositories: AnomalyCLIP, open_clip, CLIP_Surgery.
If you find this paper and repository useful, please cite our paper.
@inproceedings{
xu2026mrad,
title={{MRAD}: Zero-Shot Anomaly Detection with Memory-Driven Retrieval},
author={Chaoran Xu and Chengkan Lv and Qiyu Chen and Feng Zhang and Zhengtao Zhang},
booktitle={The Fourteenth International Conference on Learning Representations},
year={2026}
}