Introduction
Anomaly detection (AD) is a critical task in machine learning, focused on identifying data points that deviate significantly from the norm. This capability is essential for high-stakes applications such as medical diagnosis, fraud detection, and industrial monitoring. Traditionally, the field has been dominated by complex self-supervised learning methods that create auxiliary tasks—such as predicting image rotation—to learn representations of "normal" data. However, these methods often rely on rigid assumptions about data orientation and require intensive training.
This paper introduces DN2 (Deep Nearest Neighbors), a surprisingly simple yet powerful baseline that challenges the necessity of complex self-supervised architectures. By leveraging off-the-shelf features from pre-trained networks, DN2 achieves state-of-the-art performance with minimal training requirements.
Methodology
The DN2 approach follows a straightforward two-step process:
- Feature Extraction: Images are passed through a standard ResNet-101 model pre-trained on ImageNet. This process transforms raw pixels into high-dimensional embeddings that capture universal visual features.
- Anomaly Scoring: To determine if a test image is anomalous, the system identifies its $k$ nearest neighbors within the training set. The average distance to these neighbors serves as the anomaly score; a larger distance indicates a higher likelihood that the image is an outlier.
Beyond basic detection, the authors extend DN2 to Unsupervised AD by implementing a cleaning stage that removes isolated training points, and Group AD, which uses orderless pooling to detect anomalies within sets of images.
Robustness to "In-the-Wild" Data
A major limitation of many self-supervised methods is their reliance on data having a consistent "upright" orientation. DN2 bypasses this constraint entirely. The researchers tested the model on challenging real-world datasets like DIOR (aerial imagery) and WBC (white blood cell microscopy), where orientation is naturally random.
Because DN2 relies on generic feature embeddings rather than orientation-based tasks, it remains robust where other models fail. For instance, on the WBC microscope dataset, DN2 achieved an 82.9% ROCAUC, vastly outperforming the self-supervised MHRot, which struggled at 60.5%.
Key Results and Insights
DN2 demonstrates that generic features are remarkably effective for specialized tasks. Despite being trained on general objects like cars and animals, the ResNet features create tight, separable clusters for "normal" data in almost any domain.
The Impact of Model Depth
The study found a clear correlation between the complexity of the feature extractor and the accuracy of the anomaly detection. As the backbone architecture becomes deeper, the quality of the embeddings improves, leading to higher detection scores.
Efficiency and Scaling
One of the most striking findings is DN2's sample efficiency. While self-supervised models often require thousands of images to learn a representation, DN2 reaches near-peak performance with as few as 10 training samples. Furthermore, the optimal number of neighbors ($k$) was found to be surprisingly small, often yielding the best results at $k=2$.
Conclusion
DN2 serves as a powerful reminder that simple baselines can often outperform complex, specialized models. By utilizing pre-trained deep features and a classic kNN approach, the authors provide a robust, efficient, and highly accurate solution for anomaly detection across diverse image domains. While computational scaling for massive datasets remains a future consideration, DN2 currently stands as a new state-of-the-art benchmark for the field.
Summary updated