Mahalanobis++: Improving OOD Detection via Feature Normalization
Maximilian Mueller, Matthias Hein
TL;DR
This work addresses the instability of Mahalanobis distance-based OOD detection across diverse pretrained models, tracing failures to violations of Gaussian feature-space assumptions caused by varying feature norms. It introduces Mahalanobis++—a post-hoc fix that applies $l_2$-normalization to pre-logit features, projecting them onto the unit sphere before estimating class means and a shared covariance. The approach improves alignment with Gaussian assumptions, reduces norm-driven biases, and yields consistent OOD detection gains across a wide range of architectures and pretraining schemes, outperforming both the vanilla Mahalanobis method and several baselines on large-scale benchmarks. The results suggest a simple, effective post-hoc normalization can substantially enhance reliability of OOD rejection in real-world deployments without retraining.
Abstract
Detecting out-of-distribution (OOD) examples is an important task for deploying reliable machine learning models in safety-critial applications. While post-hoc methods based on the Mahalanobis distance applied to pre-logit features are among the most effective for ImageNet-scale OOD detection, their performance varies significantly across models. We connect this inconsistency to strong variations in feature norms, indicating severe violations of the Gaussian assumption underlying the Mahalanobis distance estimation. We show that simple $\ell_2$-normalization of the features mitigates this problem effectively, aligning better with the premise of normally distributed data with shared covariance matrix. Extensive experiments on 44 models across diverse architectures and pretraining schemes show that $\ell_2$-normalization improves the conventional Mahalanobis distance-based approaches significantly and consistently, and outperforms other recently proposed OOD detection methods.
