Introduction
Anomaly detection (AD) algorithms typically operate under a "closed-world" assumption, where training and test data are expected to share the same distribution. However, real-world applications often encounter distribution shifts—changes in environmental factors like lighting, background, or sensor noise. In these scenarios, traditional AD models frequently suffer from high false-positive rates, mistakenly flagging benign environmental changes as structural anomalies. While Out-of-Distribution (OOD) generalization is well-explored in classification, AD presents a unique challenge: models are typically trained only on "normal" data, making it difficult to distinguish between a "shifted-but-normal" sample and a true anomaly.
Generalized Normality Learning (GNL)
To address this, we introduce Generalized Normality Learning (GNL), a framework designed to enhance the robustness of AD models against distribution shifts. GNL builds upon the Reverse Distillation for Anomaly Detection (RD4AD) architecture and operates in two distinct phases.
Training Phase: Distribution-invariant Normality Learning
During training, GNL employs AugMix to generate various "styled" versions of normal images. A novel normality-preserved loss function is introduced to force the model’s internal representations—specifically at the bottleneck and decoder layers—to remain consistent across these augmentations. By minimizing the cosine similarity gap between the original and augmented features, the model learns to prioritize core semantic structures over superficial textures or styles.
Inference Phase: Test Time Augmentation
At test time, GNL utilizes Exact Feature Distribution Matching (EFDM). For each incoming test sample, the model selects a random normal sample from the training set and "injects" its style into the test image's features within the encoder. This process effectively "normalizes" the test sample, mapping it back toward the training distribution. If the sample is truly normal, this mapping facilitates recognition; if it contains a structural anomaly, the underlying geometric differences persist, allowing for accurate detection.
Experimental Evaluation
The framework was evaluated across a diverse benchmark including MVTec AD, CIFAR-10, MNIST/MNIST-M, and the PACS domain generalization dataset. These datasets were modified to include various visual corruptions (e.g., brightness, blur, noise) or domain shifts (e.g., Photo to Sketch).
Key Results and Robustness
GNL demonstrates significant performance gains, outperforming state-of-the-art AD models and general OOD methods by over 10% in AUROC on shifted data. Crucially, GNL maintains high accuracy on clean, in-distribution data while exhibiting remarkable stability as corruption severity increases.
As shown in the figure above, while competing models like RD4AD and Augmix see a sharp decline in performance as image quality degrades, GNL maintains a stable AUROC of approximately 0.90 even at the highest severity levels. This robustness is achieved without sacrificing performance on standard in-distribution data.
Conclusion and Future Work
GNL provides a robust solution for anomaly detection in dynamic environments by decoupling style from semantics. While the method introduces some computational overhead during training (~2.8x) and a slight increase in inference latency, the gains in reliability under distribution shift are substantial. Future research will explore more sophisticated reference sample selection strategies to further optimize the inference-time correction process.
Summary updated