Zero-Shot Anomaly Segmentation With Class-Specific Text Prompts
Junyeong Son1*, Woojun Lee2*, Siyul Sung1, Pilsung Kang2†
1Korea University, 2Seoul National University · DSBA Lab
*Equal contribution, †Corresponding author
IEEE Transactions on Automation Science and Engineering, 2026
Paper · Project page · Weights
ZSAS segments anomalies in classes it has never seen. A multimodal large language model (MLLM) writes text prompts for each class, and a frozen CLIP compares them with the patch features of the image. Only small adapters in the first layers of the two CLIP encoders are trained, on an auxiliary dataset that shares no class with the test data.
- Class-specific text prompts. From the class name and one reference image, the MLLM writes 20 sentences about the normal appearance of the class and 20 about its anomalies. This costs about $0.007 per class with GPT-5, and the prompts are reused for every image of the class.
- Residual adapters with alternating learning. Adapters are added to image layers 1-6 and text layers 1-3 through residual connections. The text and image adapters are updated in alternate epochs, and CLIP itself stays frozen.
- Eleven industrial and medical datasets. Among the compared methods, ZSAS has the highest mAD on the average of the two domains (57.7) and on the medical datasets (56.1), at 218 ms and 2,280 MB of GPU memory per image.
Python 3.9 (tested with 3.9.16, PyTorch 2.3.1 and CUDA 12.1) and a CUDA GPU. Inference needs about 2.3 GB of GPU memory, and training was run on one 32 GB GPU. Run the commands below from the repository root.
git clone https://github.com/dsba-lab/ZSAS.git && cd ZSAS
pip install -r requirements.txt
hf download dsba-lab/ZSAS --repo-type dataset --local-dir ./weightsThe backbone is CLIP ViT-L/14@336px with the OpenAI weights, which the bundled open_clip/ downloads on first use.
The released weights are in the dataset repository dsba-lab/ZSAS on
Hugging Face. They contain only the adapters, about 45 MB per checkpoint and about 2 GB in total. They are stored as
weights/<MLLM>/<aux>_seed<seed>.pth, where <aux> is the auxiliary training dataset (mvtec or visa), and as
weights/paper/<dataset>.pth for the runs reported in the paper. To download a part of them, add
--include "gpt-5/*" or --include "paper/*".
bash scripts/test.sh visa # one dataset
bash scripts/test.sh all 500 # all eleven datasets with the prompt set of test seed 500
SAVE_VIS=1 bash scripts/test.sh mvtecThe first argument is one of mvtec visa mpdd btad dtd isic colondb clinicdb endo kvasir tn3k, or all. The second
is the test seed, 500 by default, which selects the prompt set test_seed_<seed>. The datasets are read from ./data,
prepared as described in DATA.md.
MVTec AD is evaluated with the weights trained on VisA, and every other dataset with the weights trained on MVTec AD,
so the training and test classes never overlap. The script uses gpt-5/mvtec_seed400.pth and gpt-5/visa_seed500.pth.
These environment variables change its defaults.
| Variable | Default | Meaning |
|---|---|---|
GPU |
0 |
GPU index |
DATA_ROOT |
./data |
Folder that contains the dataset folders |
WEIGHT_ROOT |
./weights |
Folder that contains the weights |
PROVIDER, LLM |
openai, gpt-5 |
MLLM whose prompts and weights are used |
MVTEC_CKPT, VISA_CKPT |
see above | Weights trained on MVTec AD and on VisA |
SAVE_VIS |
unset | Set to any value to save the anomaly maps |
The script calls test.py once per dataset. The same call for one dataset is
python test.py --data_path ./data/VisA --test_dataset visa --domain industrial \
--ckp_path ./weights/gpt-5/mvtec_seed400.pth --seed 500Medical datasets take --domain medical. Keep --batch_size at 1. The metrics are written to
results/logs/<folder>/<checkpoint>/<dataset>_test/test_seed_<seed>/results.csv, where <folder>/<checkpoint> are the
parent folder and the file name of the checkpoint, gpt-5/mvtec_seed400 for the call above. With --save_vis the
anomaly maps are saved under results/images/ with the same sub-path.
-
Download the datasets and install their file lists, as described in DATA.md.
python tools/install_meta.py --data_root ./data
-
Download the weights of the reported runs.
hf download dsba-lab/ZSAS --repo-type dataset --local-dir ./weights --include "paper/*" -
Run the evaluation.
bash scripts/reproduce_paper.sh all # or one dataset, e.g. visaFor each dataset the script evaluates
weights/paper/<dataset>.pthwith the prompts intext_descriptions/paper/<dataset>.json. No API key is needed.
Pixel-level metrics in percent. R is AUROC, F is F1-max, A is AP, P is AUPRO and I is IoU-max. mAD is the mean of the five. The best value of each column is in bold.
Industrial datasets, mean of MVTec AD, VisA, MPDD, BTAD and DTD-Synthetic.
| Method | R | F | A | P | I | mAD |
|---|---|---|---|---|---|---|
| WinCLIP | 75.8 | 16.8 | 12.1 | 46.5 | 1.4 | 30.5 |
| AnoVL | 85.0 | 26.7 | 22.4 | 63.1 | 16.9 | 42.8 |
| AnomalyCLIP | 93.7 | 38.7 | 36.3 | 84.1 | 26.6 | 55.9 |
| AdaCLIP | 94.5 | 34.2 | 45.3 | 41.0 | 22.7 | 47.5 |
| Bayes-PFL | 95.1 | 45.4 | 43.8 | 88.4 | 32.3 | 61.0 |
| ZSAS (ours) | 93.9 | 45.3 | 42.2 | 82.7 | 32.2 | 59.2 |
Medical datasets, mean of ISIC, ColonDB, ClinicDB, ENDO, Kvasir and TN3K.
| Method | R | F | A | P | I | mAD |
|---|---|---|---|---|---|---|
| WinCLIP | 63.9 | 31.7 | 23.8 | 27.3 | 2.9 | 29.9 |
| AnoVL | 80.3 | 43.8 | 39.8 | 49.9 | 29.6 | 48.7 |
| AnomalyCLIP | 82.2 | 46.6 | 42.7 | 62.1 | 31.4 | 53.0 |
| AdaCLIP | 80.8 | 33.1 | 40.3 | 34.0 | 20.0 | 41.6 |
| Bayes-PFL | 82.7 | 47.7 | 42.9 | 62.3 | 32.4 | 53.6 |
| ZSAS (ours) | 84.6 | 50.6 | 46.7 | 63.5 | 35.2 | 56.1 |
Mean of the two domains.
| Method | R | F | A | P | I | mAD |
|---|---|---|---|---|---|---|
| WinCLIP | 69.8 | 24.3 | 17.9 | 36.9 | 2.1 | 30.2 |
| AnoVL | 82.6 | 35.3 | 31.1 | 56.5 | 23.3 | 45.7 |
| AnomalyCLIP | 88.0 | 42.7 | 39.5 | 73.1 | 29.0 | 54.5 |
| AdaCLIP | 87.7 | 33.6 | 42.8 | 37.5 | 21.4 | 44.6 |
| Bayes-PFL | 88.9 | 46.6 | 43.4 | 75.4 | 32.4 | 57.3 |
| ZSAS (ours) | 89.3 | 48.0 | 44.5 | 73.1 | 33.7 | 57.7 |
ZSAS on each dataset. The last column is the mean and standard deviation of mAD over 30 independent prompt sets.
| Dataset | R | F | A | P | I | mAD | mAD, 30 prompt sets |
|---|---|---|---|---|---|---|---|
| MVTec AD | 90.4 | 42.6 | 40.3 | 77.0 | 28.4 | 55.7 | 54.7 ± 0.6 |
| VisA | 94.9 | 31.9 | 25.6 | 88.0 | 20.6 | 52.2 | 51.8 ± 0.3 |
| MPDD | 96.2 | 36.9 | 32.0 | 89.2 | 26.2 | 56.1 | 55.1 ± 0.6 |
| DTD-Synthetic | 96.0 | 71.5 | 72.9 | 89.4 | 56.2 | 77.2 | 76.6 ± 0.3 |
| BTAD | 91.8 | 43.5 | 40.2 | 69.8 | 29.7 | 55.0 | 54.0 ± 0.7 |
| ISIC | 93.0 | 78.2 | 84.9 | 86.6 | 64.2 | 81.4 | 80.2 ± 0.5 |
| ColonDB | 80.5 | 35.2 | 24.8 | 72.4 | 21.4 | 46.9 | 44.6 ± 0.7 |
| ClinicDB | 83.1 | 40.9 | 31.8 | 61.5 | 25.7 | 48.6 | 47.3 ± 0.8 |
| ENDO | 87.1 | 54.4 | 50.9 | 68.6 | 37.4 | 59.7 | 57.2 ± 1.3 |
| Kvasir | 82.6 | 50.5 | 45.4 | 48.8 | 33.7 | 52.2 | 51.0 ± 0.8 |
| TN3K | 81.0 | 44.5 | 42.4 | 43.2 | 28.6 | 47.9 | 46.0 ± 1.0 |
scripts/reproduce_paper.sh reproduces the first six columns of the last table, and the ZSAS rows of the three tables
above are their averages. The prompts are written by an MLLM, so another prompt set gives slightly different numbers.
The last column shows this spread. A run of scripts/test.sh uses other weights and another prompt set than the
reported runs, so its numbers differ slightly from the table as well.
The class-specific text prompts (CSTPs) of all experiments are released in text_descriptions/, so the evaluation and
the training above need no API key.
| Path | Content |
|---|---|
text_descriptions/<provider>/<MLLM>/<dataset>_train/train_seed_<seed>/<dataset>.json |
Prompts used for training |
text_descriptions/<provider>/<MLLM>/test_seed_<seed>/<test_dataset>.json |
Prompts used for evaluation |
text_descriptions/paper/<test_dataset>.json |
Prompt sets of the reported runs |
Each file maps a class name to its sentences, {"hazelnut": {"Normal": ["...", ...], "Abnormal": ["...", ...]}}.
test.py --desc_file <json> reads the prompts from the given file instead of the cache.
| MLLM | --provider |
--LLM_model_name |
Weights, training seeds | Prompt sets, test seeds |
|---|---|---|---|---|
| GPT-5 | openai |
gpt-5 |
100, 200, 300, 400, 500 | 100 to 6000 in steps of 100 |
| Claude-Opus-4.1 | anthropic |
claude-opus-4-1-20250805 |
100 to 500 | 100 to 500 |
| Gemini-2.5-Pro | google |
gemini-2.5-pro |
100 to 500 | 100 to 500 |
| Gemma-4-31B | gemma |
gemma-4-31b-it |
100 | 100 to 500 |
| Qwen-3-VL-32B-Instruct | qwen |
qwen3-vl-32b-instruct |
100 | 100 to 500 |
The weights of each MLLM are in weights/<--LLM_model_name>/, for both auxiliary datasets. To evaluate another MLLM,
set PROVIDER and LLM, and name the checkpoints if the default seeds are not released for it.
PROVIDER=anthropic LLM=claude-opus-4-1-20250805 bash scripts/test.sh all 500
PROVIDER=qwen LLM=qwen3-vl-32b-instruct \
MVTEC_CKPT=./weights/qwen3-vl-32b-instruct/mvtec_seed100.pth \
VISA_CKPT=./weights/qwen3-vl-32b-instruct/visa_seed100.pth bash scripts/test.sh all 100If a prompt file is missing, it is generated with the MLLM on first use and cached at the same path. This is the case
for a new seed, a new MLLM or a new dataset, and it needs an API key. Copy .env.example to .env and fill in only the
provider you use.
--provider |
Variables |
|---|---|
openai |
OPENAI_API_KEY, OPENAI_ORG_ID |
anthropic |
ANTHROPIC_API_KEY |
google |
GOOGLE_API_KEY |
gemma, qwen |
OPENAI_COMPATIBLE_API_KEY, OPENAI_COMPATIBLE_BASE_URL, OPENAI_COMPATIBLE_MODEL |
gemma and qwen work with any OpenAI-compatible endpoint, such as vLLM or OpenRouter. OPENAI_COMPATIBLE_MODEL is
the model id that the endpoint expects, and defaults to --LLM_model_name. Prompts are generated once per class.
One class costs about $0.007 with GPT-5 or Gemini-2.5-Pro, $0.05 with Claude-Opus-4.1 and $0.0003 with the two open
models at a hosted endpoint.
bash scripts/train.sh mvtec 100 # weights for every dataset except MVTec AD
bash scripts/train.sh visa 100 # weights for MVTec ADThe second argument is the seed, 100 by default. The checkpoint is written to
results/checkpoints/<provider>/<MLLM>/<dataset>_seed<seed>.pth, and GPU, DATA_ROOT, PROVIDER and LLM are read
as in scripts/test.sh. To evaluate it, pass its path as MVTEC_CKPT or VISA_CKPT.
Training runs for 16 epochs with AdamW, a learning rate of 1e-3, betas of (0.5, 0.999), a batch size of 5 and
518 x 518 inputs, with focal and Dice losses on the patch tokens of layers 6, 12, 18 and 24. Only the test split of the
auxiliary dataset is used. We trained on one NVIDIA Tesla V100 with 32 GB. If the GPU runs out of memory, set
PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True.
Checkpoints hold only the adapters. A checkpoint of an older version of this code, which also stored the CLIP backbone (1.7 GB), is converted with
python tools/slim_checkpoint.py --src old.pth --dst weights/gpt-5/mvtec_seed100.pth- Write a
meta.jsonfor the dataset, like the ones indata/meta/. - Add a dataset class in
dataset/, followingdataset/mvtec.py, and register it indataset/__init__.py. - Copy
.env.exampleto.envand set the key of one provider. - Run
test.pywith the new--test_datasetname. The prompts are generated on the first run from the class names and one image per class, and cached.
| File | Content |
|---|---|
train.py, test.py |
Training and evaluation |
descriptions_generation.py |
CSTP generation with an MLLM and its JSON cache |
prompt_ensemble.py |
CSTP encoding with the text encoder |
method/adapter.py |
Residual adapters |
method/csclip.py |
The model: alternating training, inference, checkpoint I/O |
loss.py |
Focal and Dice losses |
metrics.py |
AUROC, F1-max, AP, AUPRO, IoU-max and mAD |
dataset/ |
Dataset loaders, adapted from AdaCLIP |
open_clip/ |
Modified OpenCLIP that returns multi-level patch tokens, with its own LICENSE |
data/meta/ |
The meta.json file lists of the 11 datasets |
text_descriptions/ |
Released CSTPs |
scripts/ |
test.sh, train.sh, reproduce_paper.sh |
tools/install_meta.py, tools/slim_checkpoint.py |
Utilities |
docs/ |
Project page |
Each adapter is a linear layer without bias followed by a LeakyReLU. Its output is added to the output of the frozen
CLIP layer with a weight of 0.1 (--image_adapt_weight, --text_adapt_weight). Adapters sit in the first six layers
of the image encoder and the first three layers of the text encoder, 11.8M trainable parameters in total. Training
alternates between the two encoders. With epochs counted from zero, even epochs update the text adapters and odd epochs
update the image adapters. At inference the anomaly map of each phase is computed, and the two maps are averaged.
@ARTICLE{11783453,
author={Son, Junyeong and Lee, Woojun and Sung, Siyul and Kang, Pilsung},
journal={IEEE Transactions on Automation Science and Engineering},
title={Zero-Shot Anomaly Segmentation With Class-Specific Text Prompts},
year={2026},
volume={23},
number={},
pages={20270-20285},
keywords={Modeling;Training;Visualization;Learning (artificial intelligence);Anomaly detection;Conferences;Computers;Poles and zeros;Computer vision;Transistors;Image anomaly segmentation;zero-shot anomaly segmentation;multimodal large language models},
doi={10.1109/TASE.2026.3752260}}The code in this repository is released under the MIT License. The code in open_clip/ and dataset/ keeps
its own license (open_clip/LICENSE, dataset/LICENSE). The CLIP weights are
OpenAI's, and each dataset keeps the license of its source. This repository includes neither, only the file lists of
the datasets. The dataset images shown on the project page come from the test sets of the datasets named there.
ZSAS builds on OpenCLIP. The dataset loaders and layouts follow AnomalyCLIP and AdaCLIP.
