Abstract
While deep learning models have seen widespread success in controlled environments, there are still barriers to their adoption in open-world settings. One critical task for safe deployment is the detection of anomalous or out-of-distribution samples that may require human intervention. In this work, we present a novel loss function and recipe for training networks with improved density-based out-of-distribution sensitivity. We demonstrate the effectiveness of our method on CIFAR-10, notably reducing the false-positive rate of the relative Mahalanobis distance method on far-OOD tasks by over 50%.
Introduction
Deep learning models are notoriously "overconfident" when they encounter data they haven't seen before—known as out-of-distribution (OOD) samples. In high-stakes environments like autonomous driving or medical diagnosis, a model needs to know when to "say I don't know" and hand the decision to a human.
Existing OOD detection methods usually fall into two camps: those that look at the model's final output (logits) and those that look at internal representations (embeddings). A popular representation-based method uses the Mahalanobis distance, which assumes that the model's internal features follow a Gaussian distribution. However, standard training doesn't actually force features to be Gaussian; it just happens to work "well enough" post-hoc. This paper addresses the gap between how we train models and how we test them for OOD sensitivity.
Methods
The authors introduce Mahalanobis-Aware Training, which consists of a new loss function and a specific training "recipe":
- The Regularization Loss ($L_{reg}$): Instead of just using standard cross-entropy ($L_{base}$), they add a second term ($L_{maha}$). This term treats the Mahalanobis distances of the training samples as if they were logits, essentially forcing the model to maximize the likelihood of in-distribution data under a Gaussian assumption during the training process itself.
- Online Parameter Estimation: To calculate Mahalanobis distance during training, the model needs to know the mean and covariance of each class. The authors use an Exponential Moving Average (EMA) to track these statistics on the fly.
- Noise Reduction: To stabilize covariance estimation from small batches, they employ a shrinkage estimator (the Ledoit-Wolf method), making the training process much more robust.
At test time, they use the Relative Mahalanobis Distance (RMD) score to decide if a sample is OOD.
Experimental Results
The researchers evaluated their method using CIFAR-10 as the "In-Distribution" (ID) dataset. To test OOD detection, they used two categories of benchmarks: Far-OOD (visually distinct datasets like SVHN, Places365, iSUN, LSUN, and Textures) and Near-OOD (CIFAR-100, which is semantically similar to the training data). All experiments were conducted using a standard ResNet18 architecture.
The proposed method outperformed several state-of-the-art baselines (like MSP, Energy, KNN, and ViM) across the board.
On the Far-OOD benchmark, the method achieved a False Positive Rate (FPR95) of 17.79%. For context, the next best baseline (ViM) was at 27.50%, and the standard Mahalanobis-based method (RMD) was at 36.58%. This represents a reduction in false positives of over 50% compared to the direct baseline. Even on the difficult CIFAR-100 task, the method improved the FPR95 to 49.53%, whereas most baselines hovered between 51% and 61%. The Area Under the ROC curve (AUROC) reached 96.76% for Far-OOD.
Discussion and Conclusion
The most significant insight is that OOD detection shouldn't be an afterthought. By making the training objective "aware" of the scoring function used at test time, the model learns a latent space that is much more discriminative for anomalies. While many researchers assumed latent spaces were "Gaussian enough," this paper proves that explicitly enforcing that structure leads to a significant leap in sensitivity. Crucially, this method maintains high in-distribution accuracy (94.7% vs. 95.2% for the baseline).
The hyperparameter $\alpha$, which balances the two losses, shows a stable positive trend regarding OOD performance, as seen in the figure above. While the results on CIFAR-10 are impressive, the primary limitation is scalability. Calculating and maintaining covariance matrices for datasets with thousands of classes (like ImageNet) could become computationally expensive. Future work should focus on exploring how this "Mahalanobis-aware" approach scales to these larger, more complex datasets.
Summary updated