Identifying Untrustworthy Predictions in Neural Networks by Geometric Gradient Analysis

Leo Schwinn, An Nguyen, René Raab, Leon Bungert, Daniel Tenbrinck, Dario Zanca, Martin Burger, Bjoern M. Eskofier

Introduction

Deep Neural Networks (DNNs) have achieved remarkable success across various domains, yet they remain prone to being "confidently wrong." This overconfidence manifests in two primary ways: assigning high probability to Out-of-Distribution (OOD) data (e.g., a digit classifier seeing a picture of a jacket) and falling victim to Adversarial Attacks, where subtle, invisible perturbations trick the model into a wrong classification.

Existing defenses often require expensive model retraining or are specialized for either OOD or adversarial detection, but rarely both. This paper introduces Geometric Gradient Analysis (GGA), a "plug-and-play" method that identifies untrustworthy predictions for any pre-trained model without requiring retraining or prior exposure to specific attacks.

Methodology: Geometric Gradient Analysis (GGA)

GGA shifts the focus from final prediction scores (softmax) to the underlying geometric properties of the model's loss landscape. The core idea is to analyze saliency maps—the gradients of the loss with respect to the input—for every possible output class.

  1. Gradient Calculation: For a given input, GGA calculates how the input would need to change to increase the probability of each class (0 through 9 for MNIST, for example).
  2. Cosine Similarity Matrix (CSM): The method computes the pairwise similarity between these gradient vectors, forming a matrix that captures the geometric alignment of the model's internal representations.
  3. The Geometric Signal: The authors demonstrate that for a "correct" input, the gradients for all incorrect classes tend to align, pointing away from the local minimum of the correct class. In contrast, for OOD or adversarial data, these gradients are disorganized and poorly aligned.
Visualizing the Cosine Similarity Matrix (CSM) for various input types.

To detect anomalies, statistical features (such as mean and variance) are extracted from the CSM and processed by a lightweight anomaly detector (LODA) to flag untrustworthy inputs.

Key Insights

The "Local Minimum" Theory

The effectiveness of GGA is rooted in a mathematical proof: correctly classified samples typically lie in a local minimum of the loss landscape. This geometric property forces the gradients of non-predicted classes to align significantly.

Robustness to Adaptive Attacks

GGA is inherently difficult to fool. To bypass the detector, an attacker must not only flip the model's prediction but also craft a perturbation that forces the gradients of all other classes to align perfectly—a significantly more complex optimization problem than standard adversarial attacks.

Scalability via Top-N Analysis

For datasets with many classes (e.g., CIFAR-100), calculating gradients for every class is computationally expensive. The authors found that analyzing only the top 5 or 10 predicted classes maintains high detection accuracy while significantly reducing latency.

Experimental Results

GGA was evaluated across computer vision (MNIST, CIFAR) and time-series (UCR ECG) domains. It consistently outperformed standard baselines like ODIN and matched or exceeded state-of-the-art methods like Mahalanobis distance.

Performance comparison of GGA against baseline methods across multiple datasets.
  • Adversarial Detection: On MNIST, GGA achieved a 98.9% detection rate for PGD attacks, vastly outperforming the Mahalanobis-based method's 12.4%.
  • OOD Detection: On the UCR ECG dataset, GGA achieved a perfect 100% detection rate for OOD samples.
  • Adaptive Robustness: Even against "Cosine Similarity Attacks" specifically designed to fool the detector, GGA maintained a detection accuracy of ~70-72%, whereas most other detectors failed completely.

Limitations and Future Work

While powerful, GGA introduces computational overhead due to the need for multiple gradient calculations. Additionally, it requires "white-box" access to the model's gradients, making it unsuitable for black-box API scenarios. Future research may explore "end-to-end" training to encourage these geometric properties during initial model training, potentially enhancing both efficiency and robustness.

Summary updated

BibTeX
@inproceedings{schwinn2021identifying,
  author = {Leo Schwinn and An Nguyen and René Raab and Leon Bungert and Daniel Tenbrinck and Dario Zanca and Martin Burger and Bjoern M. Eskofier},
  title = {{Identifying Untrustworthy Predictions in Neural Networks by Geometric Gradient Analysis}},
  booktitle = {Conference on Uncertainty in Artificial Intelligence},
  year = {2021},
  url = {https://openreview.net/forum?id=9ZsldOul6lY},
}
Figure