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

DatasetI-AUROC (%)I-AP (%)P-AUROC (%)P-AP (%)
MVTec-AD95.097.893.441.9
VisA85.488.095.723.4
BTAD93.694.994.642.6
MPDD78.681.197.530.9
DTD-Synthetic95.298.198.458.5

2. Medical Datasets

DatasetI-AUROC (%)I-AP (%)P-AUROC (%)P-AP (%)
HeadCT96.197.1
BrainMRI97.497.6
Br35H98.798.5
ISIC93.885.6
CVC-ColonDB85.637.2
CVC-ClinicDB88.849.9
Kvasir85.851.5
Endo90.058.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.