GROOD: GRadient-Aware Out-of-Distribution Detection

Mostafa ElAraby, Sabyasachi Sahoo, Yann Pequignot, Paul Novello, Liam Paull

TL;DR

GROOD (GRadient-aware Out-Of-Distribution detection) is a new post-hoc method that identifies unfamiliar data by measuring how "sensitive" a model's prediction is to an artificial "OOD prototype." By analyzing gradients in a prototype-based loss space, GROOD achieves superior separation between in-distribution and out-of-distribution samples, showing particular robustness on large-scale benchmarks like ImageNet-1k and across diverse architectures like Vision Transformers.

What Problem Does This Paper Address?

Deep Neural Networks (DNNs) are famously overconfident. When presented with an input that looks nothing like their training data—an "out-of-distribution" (OOD) sample—they often assign it a high-probability label from a known class. This is a critical failure mode for safety-sensitive applications like autonomous driving or medical diagnosis.

Existing "post-hoc" detection methods (which work on already-trained models) typically look at feature distances or output probabilities. However, these often struggle with "near-OOD" samples—data that is semantically similar to the training set but technically different. Furthermore, many current methods are sensitive to hyperparameters and perform inconsistently when moving from standard convolutional networks (ResNets) to newer architectures like Vision Transformers (ViTs).

Methods

GROOD introduces a framework that combines the geometry of "Neural Collapse" (the tendency of well-trained features to cluster tightly around class means) with gradient-based analysis. The process works in three main steps:

  1. Prototype Construction: The authors calculate "class prototypes" (the mean feature vector for every class in the training set). Crucially, they also generate an artificial OOD prototype. In their practical implementation, they synthesize this OOD prototype using a "manifold mixup" technique, creating features that lie near the decision boundaries of the training data.
  2. Gradient Computation: They define a Nearest-Class-Prototype (NCP) loss. Instead of using standard linear layers, they treat the negative Euclidean distance between an input's features and the prototypes as "logits." They then compute the gradient of this loss with respect to the artificial OOD prototype.
  3. Distance-Based Scoring: The final OOD score for a new sample is determined by its distance to the nearest training gradient in this specialized gradient space. To make this efficient for large datasets, they utilize the FAISS library for fast approximate nearest-neighbor searches.
Figure 1: Initially, we build ID class prototypes as the means of the activations of ID data along with an OOD prototype capturing OOD characteristics (§ 5). Subsequently, gradients of the softmax loss built upon the NCPs distance as logits are computed w.r.t. OOD prototype (§ 4.1). Finally, the OOD score is determined using nearest neighbor distance in the gradient space (§ 4.2).

Datasets

The authors evaluated GROOD using the comprehensive OpenOOD v1.5 benchmark.

  • In-Distribution (ID) Datasets: CIFAR-10, CIFAR-100, ImageNet-200, and the full ImageNet-1k.
  • OOD Datasets: These are categorized into Far-OOD (e.g., MNIST or Textures vs. CIFAR) and Near-OOD (e.g., CIFAR-100 vs. CIFAR-10), which is significantly more challenging.
  • Architectures: Testing spanned ResNet-18, ResNet-50, ViT-B-16, and Swin-T to ensure architectural generalizability.

Key Insights and Ideas

  • Gradient Space vs. Feature Space: The core "aha" moment is that OOD samples which are indistinguishable from ID samples in raw feature space often become clearly separated when transformed into the gradient space. The gradient captures the sensitivity of the model's confidence to the OOD prototype.
  • Neural Collapse as a Strength: While tight clustering of ID features usually leads to overconfidence, GROOD uses these clusters as stable anchors. ID samples produce stable, predictable gradients relative to the OOD prototype, whereas OOD samples produce erratic, high-magnitude gradients.
  • Stability Across Checkpoints: One persistent issue in OOD detection is "checkpoint instability," where a model's detection performance fluctuates wildly during the final epochs of training. GROOD demonstrates significantly lower variance in performance across different training stages compared to established baselines like VIM or MDS.
Figure 2: t-SNE plots on CIFAR-10 with ResNet-18. (a) Feature space: ID clusters vs. dispersed OOD. (b) Gradient space: clearer ID/OOD separation.

Key Results

GROOD consistently outperformed or matched state-of-the-art (SOTA) methods across multiple benchmarks:

  • ImageNet-1k: On ResNet-50, GROOD achieved a 94.8% AUROC on Far-OOD detection, surpassing most established baselines.
  • Transformer Robustness: While many methods see performance drops on Transformers, GROOD excelled. On ViT-B-16, it reached 90.84% AUROC for Far-OOD, significantly higher than ReACT (85.69%) or GradNorm (41.75%).
  • Oracle Performance: In "Oracle" experiments (where a small amount of OOD data is known beforehand to tune the prototype), the method reached near-perfect scores (up to 98.8% AUROC), highlighting the massive potential of the prototype-driven approach.

Limitations and Future Work

  • Computational Cost: While inference is faster than some K-Nearest Neighbor (KNN) methods, storing and processing a large database of training gradients can be memory-intensive for very high-resolution images or massive datasets.
  • Dependency on Feature Structure: The method relies on ID features forming clear clusters. If the training data is extremely noisy or poorly separated, the effectiveness of the prototype-based approach may degrade.
  • Future Directions: The authors suggest exploring ways to further reduce computational overhead and extending the framework to noisier, non-image domains where "Neural Collapse" might be less prevalent.

Summary updated

Abstract

Out-of-distribution (OOD) detection is crucial for ensuring the reliability of deep learning models in real-world applications. Existing methods typically focus on feature representations or output-space analysis, often assuming a distribution over these spaces or leveraging gradient norms with respect to model parameters. However, these approaches struggle to distinguish near-OOD samples and often require extensive hyper-parameter tuning, limiting their practicality.In this work, we propose GRadient-aware Out-Of-Distribution detection (GROOD), a method that derives an OOD prototype from synthetic samples and computes class prototypes directly from In-distribution (ID) training data. By analyzing the gradients of a nearest-class-prototype loss function concerning an artificial OOD prototype, our approach achieves a clear separation between in-distribution and OOD samples. Experimental evaluations demonstrate that gradients computed from the OOD prototype enhance the distinction between ID and OOD data, surpassing established baselines in robustness, particularly on ImageNet-1k. These findings highlight the potential of gradient-based methods and prototype-driven approaches in advancing OOD detection within deep neural networks.
BibTeX
@article{elaraby2025grood,
  author = {Mostafa ElAraby and Sabyasachi Sahoo and Yann Pequignot and Paul Novello and Liam Paull},
  title = {{GROOD: GRadient-Aware Out-of-Distribution Detection}},
  journal = {Trans. Mach. Learn. Res.},
  year = {2025},
}
Figure