WinCLIP: Zero-/Few-Shot Anomaly Classification and Segmentation

Jongheon Jeong, Yang Zou, Taewan Kim, Dongqing Zhang, Avinash Ravichandran, Onkar DabeerCVPR 2023

Abstract

Visual anomaly classification and segmentation are vital for automating industrial quality inspection. The focus of prior research in the field has been on training custom models for each quality inspection task, which requires task-specific images and annotation. In this paper we move away from this regime, addressing zero-shot and few-normal-shot anomaly classification and segmentation. Recently CLIP, a vision-language model, has shown revolutionary generality with competitive zero-/few-shot performance in comparison to full-supervision. But CLIP falls short on anomaly classification and segmentation tasks. Hence, we propose window-based CLIP (WinCLIP) with (1) a compositional ensemble on state words and prompt templates and (2) efficient extraction and aggregation of window/patch/image-level features aligned with text. We also propose its few-normal-shot extension WinCLIP+, which uses complementary information from normal images. In MVTec-AD (and VisA), without further tuning, WinCLIP achieves 91.8%/85.1% (78.1%/79.6%) AUROC in zero-shot anomaly classification and segmentation while WinCLIP+ does 93.1%/95.2% (83.8%/96.4%) in 1-normal-shot, surpassing state-of-the-art by large margins.

Introduction

Automating industrial quality inspection is a "long-tail" problem. Every factory floor has different parts—screws, PCBs, textiles—and each has its own definition of what a "defect" looks like. Traditional deep learning requires training a bespoke model for every single task, which demands hundreds of images and tedious manual annotations. Two major hurdles exist: data scarcity, as defects are rare, and contextual normality, where the definition of "normal" is subjective to the object. While models like CLIP are masters of zero-shot general classification, they typically struggle with Anomaly Segmentation (AS)—identifying the exact pixels of a defect—because they are trained on global image-level concepts rather than local details.

Methodology

The researchers introduce two versions: WinCLIP (zero-shot) and WinCLIP+ (few-shot).

Compositional Prompt Ensemble (CPE)

Instead of using a simple "normal" vs. "anomalous" prompt, a library of state words (e.g., flawless, damaged, cracked, broken) is combined with various templates (e.g., “a cropped photo of the [c]”). By averaging the text embeddings of these combinations, the model is provided with a much richer linguistic description of what an anomaly actually is.

Window-based CLIP (WinCLIP)

To solve the localization problem, the authors utilize sliding windows at multiple scales (small, medium, and full-image). Each window is processed by the CLIP image encoder, and the resulting local features are compared against the text prompts. Scores are aggregated using harmonic averaging to suppress false positives by weighting "normality" more heavily.

Reference Association (WinCLIP+)

When a few normal images are available, WinCLIP+ creates a "memory bank" of features from those healthy parts. The model then looks for deviations not just from the text description, but also from these visual reference points.

WinCLIP Framework: (a) Language-defined normality, (b) Multi-scale inspection, and (c) Visual reference context.

Experiments and Results

The approach was evaluated on two primary benchmarks: MVTec-AD, the industry standard for anomaly detection, and VisA, a diverse dataset featuring complex structures like printed circuit boards.

WinCLIP sets a new bar for low-data industrial inspection. On MVTec-AD, WinCLIP achieved 91.8% AUROC for classification and 85.1% for segmentation without seeing a single training image. In the 1-shot regime, WinCLIP+ reached 93.1% classification AUROC, outperforming the previous state-of-the-art (PatchCore) by nearly 10%.

Qualitative comparison of WinCLIP (0-shot) and WinCLIP+ (1-shot) against ground truth masks across various industrial categories.

Discussion

A key insight is that CLIP already "knows" what a crack or a missing component looks like from its massive pre-training. However, standard CLIP features are optimized for global context, making them poor for localization. Re-running CLIP on local windows restores the model's ability to see fine-grained defects.

Despite these advances, the model still struggles with "logical" defects—cases where components look healthy but are incorrectly placed. Additionally, extremely minute defects can be lost in feature aggregation. Future work may involve fine-tuning vision-language models specifically on industrial data to further close the gap with fully supervised models.

Summary updated

BibTeX
@inproceedings{jeong2023winclip,
  author = {Jongheon Jeong and Yang Zou and Taewan Kim and Dongqing Zhang and Avinash Ravichandran and Onkar Dabeer},
  title = {{WinCLIP: Zero-/Few-Shot Anomaly Classification and Segmentation}},
  booktitle = {IEEE/CVF Conference on Computer Vision and Pattern Recognition},
  year = {2023},
  url = {https://openreview.net/forum?id=QFv4rIxIfl},
}
Figure