Beyond Normal References: Discriminative Few-Shot Anomaly Detection

Huan Wang, Jun Shen, Jun Yan, Guansong PangNeurIPS 2026

TL;DR

Standard few-shot anomaly detection relies exclusively on normal examples to spot defects, completely ignoring historical examples of anomalies you might already have on hand. Simply feeding those known anomalies into a detector, however, causes it to overfit—treating a scratch as the only kind of defect and missing a dent. IDEAL solves this by using both normal and anomalous references to learn the underlying directions of how defects deviate from normality, allowing a single generalist model to cleanly spot both familiar and completely unseen anomalies on the fly.

What Problem Does This Paper Address?

Imagine setting up an automated quality inspector on a factory line. Gathering thousands of defect-free images to train a model is tedious, which led researchers to Few-Shot Anomaly Detection (FSAD)—spotting defects using just a handful of normal reference images at test time.

In the real world, though, you rarely have only normal images. You usually have a few confirmed anomalies lying around in historical logs—a cracked lens, a misprinted circuit, or a flagged tumor scan. Yet conventional FSAD methods throw these away because they are built strictly to match against normality.

The authors formalize discriminative FSAD, where a small number of both normal and abnormal references are available during inference without retraining the model. The catch? Anomalies are wildly diverse. If you use a single reference of a scratched bottle cap as a literal template, your detector will overfit to scratches and miss a missing label, or produce noisy false alarms when textures don't quite line up.

Figure 1: Anomaly score maps of (a) an input image using direct similarity matching of (b) anomalous-only references and (c) both anoma- lous and normal references, compared to (d) our method IDEAL under a 1-shot normal and anomalous reference setting. Two simple refer- ence matching methods produce noisy and spuri- ous anomaly responses, whereas IDEAL yields substantially cleaner activations. Note that, to illustrate the anomaly heterogeneity issue, the anomalous reference was intentionally chosen to be different from the abnormality in this input.

Methods

Instead of asking "Does this test image look like my anomalous reference?", the authors' framework—IDEAL (Intrinsic Deviation Learning)—asks: "In what fundamental ways do anomalies break away from normal patterns?"

Starting with standard patch features extracted from a frozen, pre-trained visual encoder (like CLIP or DINOv2), IDEAL introduces two clever, lightweight modules:

  1. Normal Variation Eraser (NVE): Not all differences matter. Shifts in lighting, camera angle, or background texture create "nuisance" deviations between a test image and a normal reference. NVE finds the local neighborhood of normal reference patches, runs Principal Component Analysis (PCA) on the fly to find the primary axes of benign, everyday variation, and mathematically projects them out. What remains are denoised deviations.
  2. Intrinsic Deviation Encoder (IDE): Next, IDEAL uses a cross-attention mechanism with a small set of learnable vectors to distill the denoised abnormal references into intrinsic deviation vectors. Driven by a custom dual loss, these vectors are forced to be mutually orthogonal (capturing distinct, non-redundant modes of failure) and tightly aligned with true abnormal shifts.
Figure 2: Overview of IDEAL (Algorithm 1). (a) Given each input E = {xq, Sn, Sa}, we employ a pre-trained encoder E(·) to extract features. We then introduce (b) a Normal Variation Eraser (Sec. 4.1) and (c) an Intrinsic Deviation Encoder (Sec. 4.2) to learn intrinsic deviation vectors from both references. Finally, (d) anomalies are detected by measuring query-to-normal deviations preserved after projection onto these learned intrinsic deviation vectors (Sec. 4.3).

At test time, IDEAL takes a query image, erases its nuisance normal variations via NVE, and projects the remaining deviations onto the learned intrinsic deviation vectors. If a large chunk of the deviation survives that projection, you have an anomaly.

Datasets

To prove generalist capability—training once and deploying anywhere without fine-tuning—the authors evaluate across eight real-world datasets spanning industrial manufacturing and medical imaging:

  • Industrial: MVTecAD, VisA, AITEX, MPDD, BTAD, KSDD, and MVTec3D.
  • Medical: BraTS (brain tumor segmentation).

To prevent data leakage when testing on MVTecAD, the model is pre-trained on VisA, and for all other datasets, it is pre-trained on MVTecAD. No new datasets are introduced, though existing benchmarks are adapted to evaluate both general settings and strict "unseen anomaly" splits (holding out specific defect classes during reference selection).

Key Insights and Ideas

  • Anomalies shouldn't be templates; they are compasses: Even if an unseen defect looks nothing like your reference defect at the pixel level, they often share relative deviation directions away from the normal manifold in feature space. Projecting onto orthogonal deviation directions generalizes where similarity matching fails.
  • Subtracting "normal noise" is half the battle: Raw feature residuals between normal and abnormal images are surprisingly tangled because benign variations (like glare on metal) can have huge magnitudes. Stripping away local PCA subspaces of normality cleanly separates normal clusters from anomalies before any deep learning even happens.
Figure 3: T-SNE visualization for differ- ent deviation representations produced by IDEAL on VisA (normal abnormal).

Key Results

Across all eight datasets and various few-shot combinations (such as 1-normal/1-abnormal N1A1 up to N8A4), IDEAL consistently outperforms state-of-the-art normal-only, abnormal-only, and joint-reference baselines.

  • Boost from a single anomaly: Under the N1A1 setting, IDEAL hits 96.3% image-level / 96.8% pixel-level AUROC on MVTecAD and 90.8% / 97.8% on VisA, beating normal-only methods by substantial margins (often 3%–10% gains on harder datasets like MPDD and BraTS).
  • Generalizing to unseen defects: When tested strictly on anomaly types never seen in the reference set, competing joint-reference methods suffer steep accuracy drops (e.g., NAGL drops up to 13.4% on MPDD), whereas IDEAL experiences minimal degradation (often less than 1% on MVTecAD) because its orthogonal vectors capture broader deviation subspaces.

Limitations and Future Work

Not discussed in the paper. (Note: Only the first two pages of the manuscript text were provided in the document alongside the extracted figures and tables, which did not include the concluding limitations section.)

Summary updated

Abstract

This paper considers a practical few-shot anomaly detection (FSAD) setting, termed **discriminative FSAD**, where a limited number of both normal and anomalous examples are available as references during inference. Existing FSAD methods rely on normal-only references through normality matching, ignoring the discriminative clues in anomalous references, while directly fitting both references can overfit to the seen anomalies. We introduce **IDEAL**, an intrinsic deviation learning framework that leverages both reference types to learn intrinsic deviation patterns characterizing generalizable abnormality as deviations from normality. IDEAL decomposes the learning process into two novel components: 1) a Normal Variation Eraser to suppress nuisance normal variations that may lead to noisy deviations from normality, thereby highlighting anomaly-relevant deviation representations; 2) an Intrinsic Deviation Encoder to decompose these denoised deviation representations into intrinsic deviation vectors capturing the most discriminative orthogonal deviation directions. At inference, IDEAL scores query-to-normal deviations preserved after projection onto the learned intrinsic deviation vectors, enabling generalization for both seen and unseen anomalies. Extensive experiments on eight real-world datasets show that IDEAL generalizes effectively to unseen anomalies and consistently outperforms existing state-of-the-art FSAD methods.
BibTeX
@inproceedings{wang2026beyond,
  author = {Huan Wang and Jun Shen and Jun Yan and Guansong Pang},
  title = {{Beyond Normal References: Discriminative Few-Shot Anomaly Detection}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2026},
  url = {https://openreview.net/forum?id=MZQzx0Papt},
}

Loading related content...

Figure