NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Anomaly Detection under Distribution Shift

Tri Cao, Jiawen Zhu, Guansong Pang

TL;DR

This paper introduces Generalized Normality Learning (GNL), a novel unsupervised framework designed to perform anomaly detection (AD) even when test data undergoes significant distribution shifts (e.g., changes in lighting, pose, or background). By combining distribution-invariant training with a feature-matching strategy at test time, GNL outperforms state-of-the-art methods by over 10% in AUROC on shifted datasets while maintaining high accuracy on standard in-distribution data.

What Problem Does This Paper Address?

Anomaly detection models are notoriously "brittle." Most are trained on a specific set of "normal" samples and assume that the test data will come from the exact same distribution. In the real world, this assumption fails: a model trained to find defects in wood under bright studio lights might flag perfectly normal wood as "anomalous" if the lighting changes or the camera angle shifts.

While Out-of-Distribution (OOD) Generalization is a well-studied field in supervised learning, it doesn't translate easily to AD. Standard OOD methods rely on multiple labeled classes or known anomaly examples to learn what features are "domain-invariant." In unsupervised AD, we only have one class (the "normal" one) and no labels, making the training data monotonous and difficult to generalize.

Figure 1: Illustrative samples for anomaly detection un- der distribution shift. First row: the ‘Wood’ dataset from MVTec [5]. Second row: the ‘Elephant’ class as normal and the remaining classes as anomaly in PACS [42]. Third row: the ‘0’ class as normal and the remaining classes as anomaly in MNIST [38]/MNIST-M [18]. We aim at distin- guishing anomalies from normal data in both in-distribution test data and out-distribution test data

Methods

The authors propose Generalized Normality Learning (GNL), built upon the state-of-the-art Reverse Distillation (RD4AD) framework. GNL tackles distribution shift through two synergistic components:

  1. Distribution-invariant Normality Learning (DINL): During training, the model uses a modified version of AugMix to create diverse "styles" of the normal training images. A new normality-preserved loss function forces the student network to produce consistent feature representations across these different styles at both high-level (bottleneck) and low-level (decoder) stages. This prevents the model from overfitting to domain-specific "noise" like background textures.
  2. AD-oriented Test Time Augmentation (ATTA): During inference, GNL uses Exact Feature Distribution Matching (EFDM). When a test sample arrives, the model randomly selects a normal training sample and "injects" the training style into the test sample's features at the early encoder layers. This aligns the test sample's distribution with the training data before the final anomaly score is calculated.
Figure 3: Overview of our approach. (a) Distribution-invariant normality learning in the training phase. (b) Test time augmentation with feature distribution matching in the inference phase.

Datasets

The authors established a comprehensive benchmark by adapting four widely-used datasets to include distribution shifts:

  • MVTec & CIFAR-10: Standard AD benchmarks, but with four types of synthetic visual corruptions (Brightness, Contrast, Defocus Blur, Gaussian Noise) applied to the test sets to create OOD scenarios.
  • MNIST-M: An OOD version of the MNIST digit dataset where digits are superimposed on random colored patches.
  • PACS: A classic OOD generalization dataset containing four domains: Photo (used as In-Distribution), Art, Cartoon, and Sketch (used as Out-of-Distribution).

Key Insights and Ideas

  • The "Monotony" Challenge: Standard OOD generalization fails in AD because the training data is unimodal (only one class). Models struggle to distinguish between "features that define normality" and "features that define the domain style."
  • Irrelevant Feature Overfitting: Traditional AD models often mistake domain-specific background information for "normal" features. When the background changes in the test set, the model produces high anomaly scores for normal samples.
  • Synergy of Training and Inference: The authors found that reducing the distribution gap during both training and inference is crucial. Training the model to be invariant to style changes makes the test-time feature alignment much more effective.

Key Results

GNL demonstrated significant robustness across all benchmarks:

  • Superior OOD Performance: On the MNIST-M dataset, GNL improved AUROC by at least 10% over the best baseline (RD4AD).
  • Robustness to Severity: As the severity of image corruption (like contrast) increases, standard models' performance crashes, while GNL remains remarkably stable. For example, at the highest corruption level on MVTec, GNL maintained ~90% AUROC while competitors dropped to ~60-65%.
  • Maintaining ID Accuracy: Crucially, GNL does not sacrifice performance on clean, in-distribution data, matching or slightly exceeding baseline SOTA results.
Figure 4: AUROC results on MVTec with varying severity of the ‘Contrast’ corruption.

Limitations and Future Work

  • Computational Overhead: GNL is more computationally expensive than the baseline RD4AD. Training takes roughly 3x longer per epoch, and inference latency increases slightly (from ~0.028s to ~0.035s per image).
  • Monotonous Data Limits: While GNL improves generalization, the inherent lack of diversity in one-class training data remains a fundamental hurdle for reaching the performance levels seen in multi-class supervised OOD tasks.
  • Future Directions: The authors suggest exploring more sophisticated ways to generate synthetic "OOD normal" samples that go beyond standard image augmentations.

Summary updated

BibTeX
@inproceedings{cao2023anomaly,
  author = {Tri Cao and Jiawen Zhu and Guansong Pang},
  title = {{Anomaly Detection under Distribution Shift}},
  booktitle = {IEEE/CVF International Conference on Computer Vision},
  year = {2023},
  doi = {10.1109/iccv51070.2023.00599},
}
Figure