Multi-Scale Memory Comparison for Zero-/Few-Shot Anomaly Detection

Chaoqin Huang, Aofan Jiang, Ya Zhang, Yanfeng Wang · DOI

Introduction

In industrial manufacturing, detecting defects—anomalies—is a critical yet challenging task. Traditional supervised learning requires extensive labeled datasets of "broken" examples, which are often prohibitively expensive or impossible to collect. This has catalyzed research into Zero-Shot (no training data) and Few-Shot (minimal normal examples) anomaly detection. While models like WinCLIP have made strides using vision-language models, they often struggle with "complex scenes" containing multiple objects. A single defect among several perfect items can easily be overlooked by global models.

Methodology

To address the multi-object challenge, this paper proposes a dual-branch framework that integrates the Segment Anything Model (SAM) for geometric decomposition and CLIP for semantic feature extraction across multiple scales.

The proposed dual-branch framework for few-shot anomaly detection, utilizing global and individual memory banks alongside SAM and CLIP.

The core methodology consists of four primary stages:

  1. Individual Object Decomposition: SAM segments the input image into individual objects, effectively transforming a complex multi-object scene into a series of simpler single-object tasks.
  2. Multi-Scale Feature Extraction: A sliding-window approach is applied to every object and the entire image at three scales: small-scale (2x2 patches), middle-scale (3x3 patches), and image-scale (full object/image).
  3. Memory Banks (Few-Shot): When reference normal images are available, the model constructs a Global Memory Bank ($M_{global}$) for scene-level features and an Individual Memory Bank ($M_{indiv}$) for isolated object features.
  4. Comparison & Scoring: Test features are compared against these memory banks using cosine similarity. Additionally, text prompts (e.g., "a photo of a [category] with a [defect]") align visual features with semantic anomaly descriptions.

Experimental Results

The framework was evaluated on the Visual Anomaly and Novelty Detection (VAND) challenge dataset, which tests generalization across new categories. The proposed method significantly outperformed the previous state-of-the-art, WinCLIP, in both zero-shot and few-shot scenarios.

Performance comparison between the proposed method and WinCLIP on the VAND challenge dataset.

In the Zero-Shot track, the model achieved an F1-classification score of 0.7945 and a substantial improvement in F1-segmentation (localization) to 0.1866. In the Few-Shot track, it reached an F1-cls of 0.8480 and an F1-seg of 0.4515. These results secured 4th place in the zero-shot track and 2nd place in the few-shot track of the VAND competition.

Discussion and Key Insights

The "divide and conquer" strategy proved highly effective; by using SAM to isolate individual pieces, the model avoids background noise and focuses on relevant features. Furthermore, the multi-scale approach ensures that both minute defects (like scratches) and large-scale structural anomalies are captured. Notably, the multi-scale memory bank approach achieves strong results even without extensive text prompt engineering, reducing a common bottleneck in CLIP-based methods.

Despite its success, the model faces challenges regarding memory occupancy and computational efficiency. Storing multi-scale embeddings for every segmented object requires significant memory, necessitating caps on memory bank size for standard hardware. Future work will explore dimensionality reduction and clustering to compress memory banks, enhancing scalability for real-time industrial applications.

Summary updated

BibTeX
@misc{huang2023multi,
  author = {Chaoqin Huang and Aofan Jiang and Ya Zhang and Yanfeng Wang},
  title = {{Multi-Scale Memory Comparison for Zero-/Few-Shot Anomaly Detection}},
  year = {2023},
  eprint = {2308.04789},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2308.04789},
}
Figure