README.md

June 30, 2026 Β· View on GitHub

AG-VAS: Anchor-Guided Zero-Shot Visual Anomaly Segmentation with Large Multimodal Models (CVPR 2026)

Zhen Qu, Xian Tao, Xiaoyi Bao, Dingrong Wang, ShiChen Qu, Zhengtao Zhang, Xingang Wang

Paper link

Large multimodal models (LMMs) exhibit strong task generalization capabilities, offering new opportunities for zero-shot visual anomaly segmentation (ZSAS). However, existing LMM-based segmentation approaches still face fundamental limitations: anomaly concepts are inherently abstract and context-dependent, lacking stable visual prototypes, and the weak alignment between high-level semantic embeddings and pixel-level spatial features hinders precise anomaly localization. To address these challenges, we present AG-VAS (Anchor-Guided Visual Anomaly Segmentation), a new framework that expands the LMM vocabulary with three learnable semantic anchor tokensβ€”[SEG], [NOR], and [ANO], establishing a unified anchor-guided segmentation paradigm. Specifically, [SEG] serves as an absolute semantic anchor that translates abstract anomaly semantics into explicit, spatially grounded visual entities (e.g., holes or scratches), while [NOR] and [ANO] act as relative anchors that model the contextual contrast between normal and abnormal patterns across categories. To further enhance cross-modal alignment, we introduce a Semantic-Pixel Alignment Module (SPAM) that aligns language-level semantic embeddings with high-resolution visual features, along with an Anchor-Guided Mask Decoder (AGMD) that performs anchor-conditioned mask prediction for precise anomaly localization. In addition, we curate Anomaly-Instruct20K, a large-scale instruction dataset that organizes anomaly knowledge into structured descriptions of appearance, shape, and spatial attributes, facilitating effective learning and integration of the proposed semantic anchors. Extensive experiments on six industrial and medical benchmarks demonstrate that AG-VAS achieves consistent state-of-the-art performance in the zero-shot setting.

Table of Contents

Introduction

This repository contains source code for AG-VAS implemented with PyTorch (Accepted by CVPR 2026οΌ‰.

Data Preparation

The overall composition of the dataset, including the training and test sets, is presented as follows. Note that, except for the anomaly_seg and anomaly_instruct_20K datasets, all other subsets require no additional processing and can be downloaded directly from official or third-party sources. We provide the download links for the datasets in the following section.

my_dataset/                              # Root directory
β”‚
β”œβ”€β”€ ade20k/                               # Task: sem_seg
β”‚   β”œβ”€β”€ annotations/
β”‚   β”‚   β”œβ”€β”€ training/
β”‚   β”‚   └── validation/
β”‚   β”œβ”€β”€ images/
β”‚   β”‚   β”œβ”€β”€ training/
β”‚   β”‚   └── validation/
β”‚   β”œβ”€β”€ objectInfo150.txt
β”‚   └── sceneCategories.txt
β”‚
β”œβ”€β”€ coco/                                 # Task: sem_seg (images for COCOStuff)
β”‚   └── train2017/
β”‚       └── *.jpg
β”‚
β”œβ”€β”€ cocostuff/                            # Task: sem_seg
β”‚   └── train2017/
β”‚       └── *.png
β”‚
β”œβ”€β”€ mapillary/                            # Task: sem_seg
β”‚   β”œβ”€β”€ config_v1.2.json
β”‚   β”œβ”€β”€ config_v2.0.json
β”‚   β”œβ”€β”€ LICENSE
β”‚   β”œβ”€β”€ README
β”‚   β”œβ”€β”€ demo.py
β”‚   β”œβ”€β”€ testing/
β”‚   β”‚   └── images/
β”‚   β”œβ”€β”€ training/
β”‚   β”‚   β”œβ”€β”€ images/
β”‚   β”‚   β”œβ”€β”€ v1.2/
β”‚   β”‚   └── v2.0/
β”‚   └── validation/
β”‚       β”œβ”€β”€ images/
β”‚       β”œβ”€β”€ v1.2/
β”‚       └── v2.0/
β”‚
β”œβ”€β”€ vlpart/                               # Task: sem_seg (part detection)
β”‚   β”œβ”€β”€ paco/
β”‚   β”‚   └── annotations/
β”‚   β”‚       └── paco_lvis_v1_train.json
β”‚   └── pascal_part/
β”‚       β”œβ”€β”€ Annotations_Part/
β”‚       β”œβ”€β”€ train.json
β”‚       β”œβ”€β”€ train_base.json
β”‚       β”œβ”€β”€ train_base_one.json
β”‚       β”œβ”€β”€ train_one.json
β”‚       β”œβ”€β”€ val.json
β”‚       └── VOCdevkit/
β”‚
β”œβ”€β”€ refer_seg/                            # Task: refer_seg
β”‚   β”œβ”€β”€ images/
β”‚   β”‚   β”œβ”€β”€ mscoco/
β”‚   β”‚   β”‚   └── images/
β”‚   β”‚   β”‚       └── train2014/
β”‚   β”‚   └── saiapr_tc-12/
β”‚   β”œβ”€β”€ refclef/
β”‚   β”‚   β”œβ”€β”€ instances.json
β”‚   β”‚   β”œβ”€β”€ refs(unc).p
β”‚   β”‚   └── refs(berkeley).p
β”‚   β”œβ”€β”€ refcoco/
β”‚   β”‚   β”œβ”€β”€ instances.json
β”‚   β”‚   β”œβ”€β”€ refs(unc).p
β”‚   β”‚   └── refs(google).p
β”‚   β”œβ”€β”€ refcoco+/
β”‚   β”‚   β”œβ”€β”€ instances.json
β”‚   β”‚   └── refs(unc).p
β”‚   └── refcocog/
β”‚       β”œβ”€β”€ instances.json
β”‚       β”œβ”€β”€ refs(umd).p
β”‚       └── refs(google).p
β”‚
β”œβ”€β”€ vqa_dataset/                        # Task: vqa
β”‚   └── llava_dataset
β”‚       β”œβ”€β”€ llava_instruct_150k.json
β”‚   └── anomalyov_dataset
β”‚       β”œβ”€β”€ images
β”‚             β”œβ”€β”€ bmad
β”‚             β”œβ”€β”€ webAD
β”‚       β”œβ”€β”€ bmad_zero_shot.json
β”‚       β”œβ”€β”€ webad_processed.json
β”‚
β”œβ”€β”€ reason_seg/                           # Task: reason_seg
β”‚   └── ReasonSeg/
β”‚       β”œβ”€β”€ explanatory/
β”‚       β”‚   └── train.json
β”‚       β”œβ”€β”€ train/
β”‚       β”‚   β”œβ”€β”€ *.jpg
β”‚       β”‚   └── *.json
β”‚       β”œβ”€β”€ val/
β”‚       └── test/
β”œβ”€β”€ anomaly_seg/   # Task: anomaly segmentation and reasoning
β”‚   └── mvtec/
β”‚   └── KSDD2/
β”‚   └── RSDD/
β”‚   └── ISIC/
β”‚   └── ColonDB/
β”‚   └── Road/                         
β”‚   └── ZJU/ 
β”‚   └── RealIADC1/ 
β”‚   └── DTD/
β”‚   └── Goods/
β”‚   └── MIAD/
β”‚   └── meta_mvtec.json
β”‚   └── meta_visa.json
β”‚   └── meta_KSDD2.json
β”‚   └── meta_RSDD.json
β”‚   └── meta_ISIC.json
β”‚   └── meta_ColonDB.json
β”‚   └── meta_Road.json                     
β”‚   └── meta_ZJU.json
β”‚   └── meta_RealIADC1.json
β”‚   └── meta_DTD.json
β”‚   └── meta_MIAD.json
β”‚   └── meta_Goods.json
β”œβ”€β”€ anomaly_instruct_20K/
β”‚   └── RealIADC.json 
β”‚   └── DTD.json
β”‚   └── Goods.json  
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€

ade20k: Download

coco: Download

cocostuff: Download

mapillary: Download

vlpart: Download of paco, Download of pascal_part

refer_seg: images/mscoco, images/saiapr_tc-12, refCOCO, refCOCO+, refCOCOg, refCLEF

vqa_dataset: LLaVA-Instruct-150k, anomalyov_dataset

reason_seg: ReasonSeg


Prepare the anomaly_seg sub-datasets:

The organization and construction of the anomaly_seg dataset follow the same procedure as that used in Bayes-PL and DictAS:

1、Download and prepare the original MVTec-AD, VisA, RealIAD, GoodsAD, DTD-Synthetic, MIAD, Zju-leaper to any desired path. Taking MVTec-AD and VisA as examples, the original dataset format is as follows:

path1
β”œβ”€β”€ mvtec
    β”œβ”€β”€ bottle
        β”œβ”€β”€ train
            β”œβ”€β”€ good
                β”œβ”€β”€ 000.png
        β”œβ”€β”€ test
            β”œβ”€β”€ good
                β”œβ”€β”€ 000.png
            β”œβ”€β”€ anomaly1
                β”œβ”€β”€ 000.png
        β”œβ”€β”€ ground_truth
            β”œβ”€β”€ anomaly1
                β”œβ”€β”€ 000.png

path2
β”œβ”€β”€ visa
    β”œβ”€β”€ candle
        β”œβ”€β”€ Data
            β”œβ”€β”€ Images
                β”œβ”€β”€ Anomaly
                    β”œβ”€β”€ 000.JPG
                β”œβ”€β”€ Normal
                    β”œβ”€β”€ 0000.JPG
            β”œβ”€β”€ Masks
                β”œβ”€β”€ Anomaly
                    β”œβ”€β”€ 000.png
    β”œβ”€β”€ split_csv
        β”œβ”€β”€ 1cls.csv
        β”œβ”€β”€ 1cls.xlsx

2、Standardize the MVTec-AD and VisA datasets to the same format and generate the corresponding .json files.

  • run ./dataset/make_dataset.py to generate standardized datasets ./dataset/mvisa/data/visa and ./dataset/mvisa/data/mvtec
  • run ./dataset/make_meta.py to generate ./dataset/mvisa/data/meta_visa.json and ./dataset/mvisa/data/meta_mvtec.json (This step can be skipped since we have already generated them.)

The format of the standardized datasets is as follows:

./datasets/mvisa/data
β”œβ”€β”€ visa
    β”œβ”€β”€ candle
        β”œβ”€β”€ train
            β”œβ”€β”€ good
                β”œβ”€β”€ visa_0000_000502.bmp
        β”œβ”€β”€ test
            β”œβ”€β”€ good
                β”œβ”€β”€ visa_0011_000934.bmp
            β”œβ”€β”€ anomaly
                β”œβ”€β”€ visa_000_001000.bmp
        β”œβ”€β”€ ground_truth
            β”œβ”€β”€ anomaly1
                β”œβ”€β”€ visa_000_001000.png
β”œβ”€β”€ mvtec
    β”œβ”€β”€ bottle
        β”œβ”€β”€ train
            β”œβ”€β”€ good
                β”œβ”€β”€ mvtec_000000.bmp
        β”œβ”€β”€ test
            β”œβ”€β”€ good
                β”œβ”€β”€ mvtec_good_000272.bmp
            β”œβ”€β”€ anomaly
                β”œβ”€β”€ mvtec_broken_large_000209.bmp
        β”œβ”€β”€ ground_truth
            β”œβ”€β”€ anomaly
                β”œβ”€β”€ mvtec_broken_large_000209.png

β”œβ”€β”€ meta_mvtec.json
β”œβ”€β”€ meta_visa.json

Other Datasets

Please download the other datasets from Google Drive: [DTAT.zip]. The processing methods for the datasets are similar to those for MVTec and VisA; all datasets are standardized into the MVTec format with a corresponding meta.json file.

Dataset Brief Description:

(1) HeadCT, BrainMRI, Br35H, ISIC, CVC-ColonDB, and CVC-ClinicDB are carefully curated by the AdaCLIP project, while Endo and Kvasir are curated by the AnomalyCLIP project. We sincerely appreciate their excellent work and dedication.

(2) KSDD2, RSDD, and DAGM datasets were post-processed by us, including operations such as random cropping. The original DAGM dataset was designed for weakly supervised defect segmentation, and thus its pixel-level annotations are imprecise elliptical labels. To make it suitable for anomaly segmentation, we manually re-annotated the dataset with precise pixel-level labels. Moreover, since the test sets of these datasets contain no normal samples, they are not directly suitable for anomaly classification. Therefore, when generating standardized datasets, we randomly selected an equal number of normal samples from the training set to match the number of abnormal samples in the test set for evaluation purposes. Due to the randomness involved, re-running ./dataset/make_dataset.py may result in different selections of normal samples. Therefore, we have also uploaded the version used in our paper for reference: [DATA_three.zip].

Environments

Create a new conda environment and install required packages.

conda create -n llava_ov python=3.10
conda activate llava_ov
conda install pytorch==2.1.2 torchvision==0.16.2 torchaudio==2.1.2 pytorch-cuda=12.1 -c pytorch -c nvidia
conda env create -f environment.yml

Acknowledgements

We thank the great works WinCLIP(zqhang), WinCLIP(caoyunkang), RegAD, VCP-CLIP, APRIL-GAN, Bayes-PFL, FastRecon, AnomalyGPT, PromptAD, MetaUAS and ResAD for assisting with our work.

Todo list

  • Release our AG-VAS paper
  • Release our training code of DictAS
  • Release our model weights
  • Release our training code of DictAS

License

The code and dataset in this repository are licensed under the MIT license.