Abstract
Detecting out-of-distribution (OOD) data is crucial for ensuring the safe deployment of machine learning models in real-world applications. However, existing OOD detection approaches primarily rely on the feature maps or the full gradient space information to derive OOD scores, neglecting the role of the most important parameters of the pre-trained network over in-distribution (ID) data. In this study, we propose a novel approach called GradOrth to facilitate OOD detection based on the observation that the important features to identify OOD data lie in the lower-rank subspace of in-distribution (ID) data. In particular, we identify OOD data by computing the norm of gradient projection on the subspaces considered important for the in-distribution data. A large orthogonal projection value (i.e., a small projection value onto the subspace) indicates the sample as OOD as it captures a weak correlation with the ID data. This simple yet effective method exhibits outstanding performance, showcasing a notable reduction in the average false positive rate at a 95% true positive rate (FPR95) of up to 8% when compared to current state-of-the-art methods.
Introduction
Deep Neural Networks (DNNs) are notoriously overconfident. When presented with data that falls outside their training distribution (OOD data), they often produce high-confidence predictions instead of signaling uncertainty. This overconfidence is a major hurdle for deploying AI in safety-critical fields like autonomous driving or healthcare.
Existing OOD detection methods typically analyze "activations" (internal neuron values) or the "full gradient space" (how the model would update its weights). However, the full gradient space is often noisy and high-dimensional. While recent "sparsification" techniques attempt to mitigate this by pruning unimportant parameters, they often rely on empirical heuristics. GradOrth addresses this by providing a mathematically grounded approach to utilizing gradient information for OOD detection.
Methodology: Leveraging Gradient Orthogonality
The core hypothesis of GradOrth is that the most critical features for identifying ID data reside in a lower-rank subspace of the model's gradients. The method operates in three distinct phases:
- Subspace Computation: Using a small subset of training data (ID), we perform Singular Value Decomposition (SVD) on the activations of the model's last layer. This identifies a $k$-dimensional subspace ($S^L$) that captures the significant representation of the training data.
- Inference: For a new, unknown test sample, the model calculates the gradient of the loss with respect to the weights of the last layer.
- Orthogonal Projection: The gradient is projected onto the previously calculated ID subspace ($S^L$).
As illustrated above, if the projection is large (the gradient aligns well with the subspace), the sample is likely In-Distribution. Conversely, if the projection is small—meaning the orthogonal component is large—the sample is flagged as OOD because it lacks a strong correlation with the features learned during training.
Experimental Setup
The researchers evaluated GradOrth across several standard benchmarks to ensure architectural and dataset robustness:
- In-Distribution (ID): ImageNet-1k, CIFAR-10, and CIFAR-100.
- Out-of-Distribution (OOD): iNaturalist, SUN, Places, Textures, SVHN, and LSUN.
- Architectures: ResNet-50, MobileNetV2, and DenseNet-101.
Key Results
GradOrth consistently outperformed or matched strong baselines such as ASH, DICE, and GradNorm across various metrics.
On the ImageNet (ResNet-50) benchmark, GradOrth achieved an average FPR95 of 18.57%, significantly outperforming the previous state-of-the-art ASH-B (22.73%). For CIFAR-100, it reduced the average FPR95 to 33.35%, compared to 41.40% for ASH-S. Notably, GradOrth maintained its edge on lightweight architectures like MobileNetV2, demonstrating its efficiency for mobile-friendly deployments.
Discussion and Insights
- Gradients vs. Activations: GradOrth demonstrates that gradients provide a richer signal for OOD detection than activations alone because they represent the model's "reaction" to an input.
- Low-Rank Efficiency: Most "knowledge" in a pre-trained model is concentrated in a few dimensions. Filtering out the noise of the full parameter space using SVD makes the OOD signal significantly clearer.
- Computational Simplicity: Unlike methods requiring heavy hyperparameter tuning or full training set feature maps, GradOrth only requires a tiny subset of ID data (e.g., 10 samples per class) to define the subspace once.
- Norm Selection: Ablation studies indicated that the $L_2$ norm consistently performed best, likely because it captures information from all gradient dimensions equally without the bias of higher-order norms.
Conclusion
GradOrth provides a simple, efficient, and mathematically principled method for OOD detection. By focusing on the orthogonal projection of gradients relative to a low-rank ID subspace, it achieves state-of-the-art results with minimal computational overhead. While no single method is a universal solution, GradOrth's stability across architectures and datasets marks a significant step toward safer machine learning deployment. Future work will explore its application in larger models like Transformers and in the domain of Natural Language Processing.
Summary updated