Kernel-Aware Graph Prompt Learning for Few-Shot Anomaly Detection

Fenfang Tao, Guo-Sen Xie, Fang Zhao, Xiangbo Shu

TL;DR

This paper introduces KAG-prompt, a novel framework for few-shot anomaly detection (FSAD) that leverages a kernel-aware hierarchical graph to capture intricate cross-layer relationships within visual features. By effectively modeling these contextual dependencies, KAG-prompt significantly improves the accuracy and robustness of detecting anomalies, even with limited training data.

What Problem Does This Paper Address?

Industrial anomaly detection (AD) is crucial for modern manufacturing, aiming to identify defects in product images. However, acquiring and labeling diverse anomalies is costly and labor-intensive. Few-shot anomaly detection (FSAD) aims to alleviate this by detecting anomalies using only a few normal "support" images. Existing FSAD methods often rely on complex, manually designed text prompts to align with visual features, a paradigm that can overlook crucial intrinsic contextual information within visual features, such as the interactions between different layers of a deep neural network. This oversight can lead to misclassifications, where normal background regions are incorrectly flagged as anomalies. The paper addresses this gap by proposing a method that explicitly models these cross-layer visual relationships to enhance anomaly detection capabilities.

Methods

The core of KAG-prompt lies in its two main modules: the Kernel-Aware Hierarchical Graph (KAHG) and the Multi-Information Fusion (MIF) module.

  • Kernel-Aware Hierarchical Graph (KAHG): This module constructs a graph where nodes represent visual features from different layers of an image encoder, specifically focusing on anomalous regions of varying sizes. These features are first processed by multi-kernel convolutions to capture scale-specific information. The relationships (edges) between these nodes represent the cross-layer dependencies. A message-passing mechanism is then employed on this graph to allow features from different layers to interact and enrich each other, creating a more comprehensive understanding of potential anomalies. This process implicitly learns visual prompts by reasoning about these graph-based relationships.
  • Multi-Information Fusion (MIF): To improve the final anomaly prediction, KAG-prompt proposes a novel image-level scoring method. Instead of solely relying on the maximum anomaly score, it fuses a global score (derived from aligning class tokens with text features) with a score based on the average of the top-k maximum values in the anomaly map. This fusion strategy aims to integrate multiple important anomaly signals, enhancing both accuracy and robustness.

Datasets

The paper evaluates KAG-prompt on two widely used datasets for anomaly detection:

  • MVTecAD: A comprehensive dataset for unsupervised anomaly detection, featuring 5 textures and 10 objects with high-resolution images.
  • VisA: A dataset with 12 subsets containing high-resolution images, including both normal and anomalous samples.

The authors use the training set of one dataset and synthesized anomalous images for training, and then perform few-shot testing on the other dataset, mimicking real-world scenarios where new defect types might appear.

Key Insights and Ideas

  • Cross-layer relationships are critical: The paper strongly emphasizes that the interactions between features from different layers of a vision model are vital for accurate anomaly detection, a fact often overlooked by methods that focus solely on text-image alignment.
  • Graph-based reasoning for visual context: Using a graph structure to model and propagate information between visual features from different layers is a novel way to capture rich contextual dependencies.
  • Beyond the maximum score: The proposed multi-information fusion for image-level scoring, which combines global and local (top-k maxima) information, offers a more robust approach than traditional methods relying solely on peak anomaly scores.
  • Implicit visual prompting: By learning relationships within a kernel-aware hierarchical graph, KAG-prompt implicitly learns effective visual prompts without requiring explicit, manual text prompt engineering.

Key Results

KAG-prompt achieves state-of-the-art results on both the MVTecAD and VisA datasets for both image-level and pixel-level anomaly detection across 1-shot, 2-shot, and 4-shot settings.

  • 1-shot setting on VisA: KAG-prompt achieves an AUROC of 91.6% and a PAUROC of 97.0%, outperforming existing methods like PromptAD by significant margins (e.g., 4.7% improvement in AUROC).
  • MVTecAD: The method also shows strong performance, with a 1-shot AUROC of 95.8% and PAUROC of 96.2%.
  • Ablation studies: The kernel-aware hierarchical graph (KAHG) module is identified as the most crucial component, contributing significantly to the performance gains. The top-k strategy for fusion also shows considerable impact, with an optimal k value around 30-40.

Limitations and Future Work

  • Limitations: While the paper demonstrates strong performance, the reliance on a pre-trained image encoder means its performance is inherently tied to the quality of that encoder. The complexity of the graph construction and message passing might also introduce computational overhead, though this is not explicitly detailed as a limitation.
  • Future Work: The authors suggest that their approach of leveraging contextual information from different layer features for industrial anomaly detection has significant potential. Future work could explore more sophisticated graph structures, different message-passing mechanisms, or extending this kernel-aware graph learning paradigm to other vision tasks beyond anomaly detection. The effectiveness of the multi-information fusion strategy also opens avenues for exploring more advanced fusion techniques.

Summary updated

BibTeX
@inproceedings{tao2025kernel,
  author = {Fenfang Tao and Guo-Sen Xie and Fang Zhao and Xiangbo Shu},
  title = {{Kernel-Aware Graph Prompt Learning for Few-Shot Anomaly Detection}},
  booktitle = {AAAI Conference on Artificial Intelligence},
  year = {2025},
  doi = {10.1609/aaai.v39i7.32790},
}
Figure