CoPS
June 2, 2026 · View on GitHub

CoPS: Conditional Prompt Synthesis for Zero-Shot Anomaly Detection
Qiyu Chen, Zhen Qu, Wei Luo, Haiming Yao, Yunkang Cao, Yuxin Jiang, Yinan Duan,
Huiyuan Luo, Chengkan Lv*, Zhengtao Zhang
CVPR DOI Link &
IEEE DOI Link &
ArXiv Preprint Link
Introduction
This repository provides PyTorch-based source code for CoPS (Accepted by CVPR 2026 Findings), a zero-shot anomaly detection framework that dynamically synthesizes visually conditioned prompts to adapt CLIP for more effective anomaly-aware prompt learning. Here, we present a brief summary of CoPS's performance across 5 industrial and 8 medical datasets.
1. Industrial Datasets
| Dataset | I-AUROC (%) | I-AP (%) | P-AUROC (%) | P-AP (%) |
|---|---|---|---|---|
| MVTec-AD | 95.0 | 97.8 | 93.4 | 41.9 |
| VisA | 85.4 | 88.0 | 95.7 | 23.4 |
| BTAD | 93.6 | 94.9 | 94.6 | 42.6 |
| MPDD | 78.6 | 81.1 | 97.5 | 30.9 |
| DTD-Synthetic | 95.2 | 98.1 | 98.4 | 58.5 |
2. Medical Datasets
| Dataset | I-AUROC (%) | I-AP (%) | P-AUROC (%) | P-AP (%) |
|---|---|---|---|---|
| HeadCT | 96.1 | 97.1 | – | – |
| BrainMRI | 97.4 | 97.6 | – | – |
| Br35H | 98.7 | 98.5 | – | – |
| ISIC | – | – | 93.8 | 85.6 |
| CVC-ColonDB | – | – | 85.6 | 37.2 |
| CVC-ClinicDB | – | – | 88.8 | 49.9 |
| Kvasir | – | – | 85.8 | 51.5 |
| Endo | – | – | 90.0 | 58.7 |
Demo App
We provide an online demo app on Hugging Face Spaces: CoPS-demo. As shown below, the demo supports uploading an input image, selecting a checkpoint trained on VisA or MVTec, running inference online, and visualizing the predicted anomaly heatmap together with the anomaly score. Since the Hugging Face Space runs inference on CPU, processing a single image usually takes about 30 seconds.
Environments
Create a new conda environment and install required packages.
conda create -n cops_env python=3.10.19
conda activate cops_env
pip install -r requirements.txt
Experiments were conducted on NVIDIA GeForce RTX 3090 (24GB). Same GPU and package version are recommended.
Data Preparation
The download links for the datasets are provided in the introduction table above.
These dataset folders/files follow its original structure.
The ./datasets/json directory contains the code files used to generate JSON annotations for each industrial and medical dataset. After executing the corresponding file,
a meta.json file will be created in the root directory of each dataset.
Run Experiments
- Testing and visualizing on the unseen categories (use the pre-trained weights)
cd ./shell
bash test.sh 0 10 VisA MVTec # gpu_id=0, epoch=10, trained on VisA, test on MVTec
bash test.sh 0 10 VisA MPDD # gpu_id=0, epoch=10, trained on VisA, test on MPDD
bash test.sh 0 10 VisA HeadCT # gpu_id=0, epoch=10, trained on VisA, test on HeadCT
......
bash test.sh 0 5 MVTec VisA # gpu_id=0, epoch=5, trained on MVTec, test on VisA
- Training on the seen categories of auxiliary datasets (train your own weights)
cd ./shell
bash train.sh 0 10 VisA; bash test.sh 0 10 VisA MVTec # train on VisA, test on MVTec
bash train.sh 0 5 MVTec; bash test.sh 0 5 MVTec VisA # train on MVTec, test on VisA
Visualization
The visualization results and model files are saved in ./results.
Some qualitative visualization results on several datasets are shown below.

Citation
Please cite the following paper if the code help your project:
@InProceedings{chen2026cops,
author = {Chen, Qiyu and Qu, Zhen and Luo, Wei and Yao, Haiming and Cao, Yunkang and Jiang, Yuxin and Duan, Yinan and Luo, Huiyuan and Lv, Chengkan and Zhang, Zhengtao},
title = {CoPS: Conditional Prompt Synthesis for Zero-Shot Anomaly Detection},
booktitle = {Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR) Findings},
month = {June},
year = {2026},
pages = {8554-8563}
}
Acknowledgements
Thanks for the great inspiration from AnomalyCLIP, AdaCLIP, and Bayes-PFL.
License
The code in this repository is licensed under the MIT license.