Abstract
The susceptibility of deep neural networks to untrustworthy predictions, including out-of-distribution (OOD) data and adversarial examples, still prevent their widespread use in safety-critical applications. This paper introduces Geometric Gradient Analysis (GGA), a method that detects these samples by analyzing the alignment of a model's input gradients across all possible classes. GGA requires no model retraining and provides a robust "sanity check" for neural network predictions by looking at the geometry of the local loss landscape.
Introduction
Deep Neural Networks (DNNs) are notoriously overconfident, often classifying out-of-distribution (OOD) data or random noise with high certainty. Furthermore, they are vulnerable to adversarial attacks—tiny, invisible perturbations that can drastically change a model's prediction. Most current solutions are specialized, targeting either OOD detection or adversarial robustness, and many require computationally expensive adversarial training that can degrade performance on clean data. This work proposes a "plug-and-play" detection mechanism applicable to any pre-trained model.
Methods: Geometric Gradient Analysis (GGA)
The core of GGA lies in analyzing saliency maps—the gradient of the loss with respect to the input—for every possible output class, not just the predicted one.
Cosine Similarity Matrix (CSM)
For a given input, saliency maps are calculated for all $C$ classes. A $C \times C$ Cosine Similarity Matrix (CSM) is constructed where each entry $(i, j)$ represents the cosine similarity between the gradients of class $i$ and class $j$.
The Geometric Signature
A key observation of this work is the distinct geometric signature of clean vs. untrustworthy data:
- Trustworthy (Clean) Data: Gradients for incorrect classes tend to point in a similar direction, while the gradient for the correct class points in the opposite direction.
- Untrustworthy (OOD/Adversarial) Data: This geometric alignment breaks down. Gradients for different classes point in disparate directions, resulting in lower average similarity and higher variance in the CSM.
Outlier Detection
Instead of relying on softmax scores, GGA extracts statistical features (mean, max, min, etc.) from the CSM. These features are then processed by a lightweight, unsupervised outlier detector (LODA) to identify untrustworthy predictions.
Results
The authors evaluated GGA across computer vision (MNIST, CIFAR-10/100) and time-series (UCR ECG) benchmarks.
- Detection Performance: On MNIST, GGA achieved an AUROC of 99.5% for detecting untrustworthy samples, significantly outperforming the baseline (86.1%).
- Adversarial Robustness: Against strong PGD attacks, GGA maintained nearly 99% detection accuracy on MNIST and over 92% on CIFAR-10, where standard baselines often fail.
- Cross-Modality Versatility: On the UCR ECG dataset, GGA achieved a 96.9% AUROC, suggesting that the geometric properties of gradients are a fundamental characteristic of DNNs across different data types.
- Efficiency: The method remains effective even when using only the top-N predicted classes (e.g., top-5 or top-10 for ImageNet), reducing computational overhead.
Discussion and Conclusion
GGA provides a retraining-free method for identifying untrustworthy predictions by exploiting the local geometry of the loss landscape. While it introduces some computational overhead due to multiple backward passes, it offers a robust defense that is difficult to bypass even with adaptive attacks. Future work includes exploring end-to-end training to sharpen these geometric signatures and scaling the method to larger datasets like ImageNet.
Summary updated