Hunting Normality from Query Sample via Residual Learning for Generalist Anomaly Detection

Xiaolei Wang, Yuexin Wang, Tianhong Dai, Huihui Bai, Yao Zhao, Jimin XiaoCVPR 2026

TL;DR

Generalist Anomaly Detection (GAD) models often rely on "residual features" to generalize across unseen domains, but directly modeling these residuals risks high false positive and false negative rates. This paper introduces a novel framework that re-purposes residuals as an attention-based guide to dynamically learn instance-level normality from support samples. By "hunting for normality" rather than modeling anomaly distributions directly, the proposed method achieves state-of-the-art performance and high efficiency across diverse industrial and medical datasets.

What Problem Does This Paper Address?

Visual anomaly detection (AD) is crucial for tasks like industrial quality control and medical diagnosis. However, traditional AD models follow a "one-for-one" paradigm, meaning a model trained to find defects in hazelnuts cannot be used to find defects in transistors without being completely retrained.

Generalist Anomaly Detection (GAD) aims to break this limitation by training a single, unified model on a source domain that can immediately detect anomalies in completely unseen target categories using just a few normal "support" images (few-shot setup).

To make features class-invariant, current state-of-the-art GAD methods use residual features—calculated by subtracting the nearest normal support feature from a query feature. The assumption was that normal residuals cluster together, while abnormal residuals stand out.

The authors identify a major flaw in this assumption: residuals are an indirect and inconsistent signal of abnormality. As shown in the paper's analysis, a subtle defect might yield a tiny residual (a false negative), while natural variations in a perfectly normal object might yield a massive residual (a false positive). Directly modeling these unpredictable residual distributions introduces significant risks.

Figure 1. (a) The residual feature effectively removes class-specific information compared to instance features. (b) The inconsistency between residuals and instance features. A subtle defect may produce a small residual that is incorrectly classified as normal (false negatives). Conversely, the residuals calculated with two normal features may also be large (false positives).

Methods

Instead of modeling the distribution of residuals directly, the authors propose a framework called HNQ-GAD (Hunting Normality from Query via Residual Learning). This framework treats residuals not as the final metric, but as a transferable guide to locate normal patterns within the query image.

The architecture leverages a frozen feature extractor (like DINOv2) and introduces two novel attention-based modules:

  1. Residual Feature Learning (RFL): This module uses a set of learnable proxies that interact with the raw residual features via cross-attention. This allows the model to capture diverse, domain-agnostic residual patterns, outputting refined "residual proxies."
  2. Normality Learning from Support (NLS): This is the core innovation. The module takes the residual proxies and uses them to query the actual normal support features via a Residual-Guided Attention (RG-Attention) mechanism. It dynamically aggregates the most relevant normal instance prototypes, creating "normality proxies" grounded in the actual instance feature space.

Finally, the Hunting Normality within Query (HNQ) step computes the cosine similarity between the query patch features and these dynamically generated normality proxies. If a query patch matches the normality proxies, it's classified as normal; if it doesn't, it's flagged as an anomaly.

Overview of the HNQ-GAD training framework.

Datasets

The framework was evaluated across three widely recognized benchmarks to test cross-domain generalization:

  • MVTec AD: A standard industrial inspection dataset containing 15 categories with various defects.
  • VisA: A challenging anomaly dataset containing 12 subsets of complex structures (e.g., printed circuit boards).
  • BraTS: A medical dataset consisting of brain tumor MRI scans, used specifically to evaluate extreme transferability from industrial objects to medical applications.

The models were evaluated using cross-dataset configurations (e.g., training on VisA and testing on MVTec AD) under 1-shot, 2-shot, and 4-shot settings.

Key Insights and Ideas

  • Flipping the Script on Anomalies: Instead of trying to model what an anomaly looks like—which is an open-ended and highly variable problem—the model focuses entirely on dynamically defining what normality looks like for each specific query-support pair.
  • Residuals as a Bridge, Not a Destination: Residual features are highly transferable across domains because they represent "differences," but they are unreliable metrics on their own. Using them purely as attention guidance to filter the original instance feature space elegantly combines cross-domain transferability with instance-level reliability.
  • Efficiency via Simplicity: By avoiding complex distribution-fitting algorithms (like normalizing flows) or heavy text-visual multi-modal mappings, the framework remains incredibly lightweight and fast.

Key Results

  • Superior Accuracy: On the MVTec AD benchmark (when trained on VisA), HNQ-GAD achieved a 97.6% image-level AUROC and 92.4% pixel-level PRO in the 4-shot setting, consistently outperforming prominent GAD methods like WinCLIP and PromptAD.
  • Industrial-to-Medical Transfer: When trained on industrial data (MVTec AD) and tested on medical brain scans (BraTS), the model achieved a mean AUROC of 91.5% in the 4-shot setting, significantly outperforming the previous residual-based baseline, ResAD (84.6%).
  • Massive Efficiency Gains: HNQ-GAD requires only 24.4M parameters (compared to InCTRL's 117.5M). It slashes training time down to 0.5 hours (compared to ResAD's 20.6 hours) and achieves an inference speed of 15.8 FPS, making it highly viable for real-time deployment.

Limitations and Future Work

While the paper demonstrates excellent empirical results, it relies heavily on the quality of the frozen backbone network (DINOv2). If the underlying self-supervised model fails to capture subtle feature representations for a highly niche target domain, the downstream residual guidance might lose its effectiveness.

Additionally, the authors note that the patterns of abnormal residuals remain complex. Future work could explore extending this residual-guided normality hunting paradigm to zero-shot settings or adapting it for video-based generalist anomaly detection.

Summary updated

BibTeX
@inproceedings{wang2026hunting,
  author = {Xiaolei Wang and Yuexin Wang and Tianhong Dai and Huihui Bai and Yao Zhao and Jimin Xiao},
  title = {{Hunting Normality from Query Sample via Residual Learning for Generalist Anomaly Detection}},
  booktitle = {IEEE/CVF Conference on Computer Vision and Pattern Recognition},
  year = {2026},
  url = {https://openreview.net/forum?id=LGBxpqRCAU},
}
Figure