Abstract
Existing anomaly detection paradigms overwhelmingly focus on training detection models using exclusively normal data or unlabeled data (mostly normal samples). One notorious issue with these approaches is that they are weak in discriminating anomalies from normal samples due to the lack of the knowledge about the anomalies. Here, we study the problem of few-shot anomaly detection, in which we aim at using a few labeled anomaly examples to train sample-efficient discriminative detection models. To address this problem, we introduce a novel weakly-supervised anomaly detection framework to train detection models without assuming the examples illustrating all possible classes of anomaly. Specifically, the proposed approach learns discriminative normality (regularity) by leveraging the labeled anomalies and a prior probability to enforce expressive representations of normality and unbounded deviated representations of abnormality. This is achieved by an end-to-end optimization of anomaly scores with a neural deviation learning, in which the anomaly scores of normal samples are imposed to approximate scalar scores drawn from the prior while that of anomaly examples is enforced to have statistically significant deviations from these sampled scores in the upper tail. Furthermore, our model is optimized to learn fine-grained normality and abnormality by top-K multiple-instance-learning-based feature subspace deviation learning, allowing more generalized representations. Comprehensive experiments on nine real-world image anomaly detection benchmarks show that our model is substantially more sample-efficient and robust, and performs significantly better than state-of-the-art competing methods in both closed-set and open-set settings. Our model can also offer explanation capability as a result of its prior-driven anomaly score learning.
Introduction: The Challenge of Few-shot Anomaly Detection
Traditional anomaly detection systems typically rely on unsupervised learning, training exclusively on "normal" data. While this avoids the high cost of labeling rare defects, these models often struggle to distinguish subtle anomalies from normal variations because they lack a conceptual model of abnormality. Conversely, fully supervised models require massive amounts of labeled data and often fail to detect new, unseen types of anomalies—a challenge known as the "open-set" problem.
The authors address Few-shot Anomaly Detection (FSAD). The goal is to create a model that is sample-efficient—performing well with only a handful of labeled anomalies—and robust enough to generalize to entirely new classes of anomalies not seen during training.
Methodology: The DevNet Framework
The core of the proposed approach is DevNet, an end-to-end framework that unifies representation learning and anomaly scoring. Its architecture consists of three main components:
- Anomaly Scoring Network: Unlike standard methods that learn features and then apply a separate distance measure, DevNet directly maps high-dimensional inputs to a scalar anomaly score using a deep neural network.
- Gaussian Prior-based Reference Scores: To guide the network, a "normality" reference is defined by drawing scores from a Gaussian prior ($N(\mu, \sigma^2)$). Normal samples are forced to have scores close to the mean ($\mu$), while anomalies are pushed to have statistically significant deviations in the upper tail of the distribution.
- Top-K Multiple Instance Learning (MIL): To handle complex images, an image is treated as a "bag" of patches. The loss function only considers the top-$K$ most anomalous patches. This prevents the model from overfitting to the normal regions within a defective image, allowing it to focus on fine-grained irregularities.
Key Insights and Results
DevNet introduces several critical advancements over existing paradigms:
- Direct Scoring: By optimizing anomaly scores directly in an end-to-end fashion, the model fully exploits limited anomaly examples.
- Statistical Interpretability: Because scores are tied to a Gaussian prior, they have inherent statistical meaning. A score above a certain Z-score threshold provides a quantifiable confidence level for anomaly detection.
- Open-Set Generalization: The top-$K$ MIL approach allows the model to learn a generalized concept of "abnormality" rather than memorizing specific training examples.
- Explainability: Since the network is differentiable, gradient-based localization (similar to Grad-CAM) can highlight the specific pixels contributing to a high anomaly score.
Experimental Performance
Evaluated on nine diverse real-world image benchmarks (including MVTec AD, medical imaging, and planetary exploration), DevNet significantly outperformed state-of-the-art competitors like Deep SAD and KDAD.
- Sample Efficiency: With only 10 labeled anomalies, DevNet achieved better results than other methods using 40 labels.
- Robustness: The model remained effective even when training data was contaminated with up to 20% unlabeled anomalies.
- Localization: DevNet provided highly accurate pixel-level anomaly masks, achieving an F1-score close to 90% while maintaining a 95% AUC-ROC for detection.
Conclusion
Deviation Networks bridge the gap between unsupervised and fully supervised anomaly detection. By combining a Gaussian prior with top-K multiple instance learning, DevNet achieves state-of-the-art performance in both seen and unseen anomaly detection while providing clear, gradient-based explanations for its decisions. Future work includes using Automated Machine Learning (AutoML) to optimize architectures and exploring techniques to further reduce open space risk.
Summary updated