Gradient-Regularized Out-of-Distribution Detection

Sina Sharifi, Taha Entesari, Bardia Safaei, Vishal M. Patel, Mahyar Fazlyab

Abstract

Neural networks often exhibit "arrogant ignorance," producing high-confidence predictions for inputs that deviate significantly from their training distribution. While existing Out-of-Distribution (OOD) detection methods utilize auxiliary datasets to define decision boundaries, they often treat samples as isolated points, neglecting the local geometry of the scoring function. This paper introduces GReg, a gradient-regularization framework that smooths the scoring manifold to ensure local stability. By penalizing the gradient norm of the score function and employing a novel energy-based clustering and sampling strategy (GReg+), the authors achieve a new state-of-the-art in OOD detection, including a 4% improvement in FPR95 on ImageNet benchmarks.

Introduction

The core challenge of OOD detection lies in distinguishing between In-Distribution (ID) data and anomalous inputs. Modern approaches typically define a scoring function—such as Energy or Softmax probability—to separate these classes. However, these models often suffer from two primary issues: local instability and inefficient sampling. Local instability occurs when a minor perturbation to an OOD sample causes a drastic swing in its score, leading to misclassification. Furthermore, when training with massive auxiliary datasets (e.g., the 300K RandomImages set), random or greedy sampling strategies often fail to capture the diversity of the outlier space or bias the model toward specific regions.

Researchers from Johns Hopkins University propose that the solution lies in the "neighborhood" of the data. By ensuring the scoring function behaves consistently in the local vicinity of a sample, models can achieve more robust and reliable OOD detection.

Methodology

1. Gradient Regularization (GReg)

The fundamental contribution of this work is the regularization of the gradient of the score function: $\|\nabla_x S(x)\|$. By penalizing this norm, the authors effectively control the local behavior of the model. Using a first-order Taylor approximation, a small gradient ensures that the score $S(x')$ for a nearby point $x'$ remains close to $S(x)$.

Crucially, the GReg loss specifically targets samples that are already correctly classified. This approach encourages the model to establish "stable zones" around known ID and OOD regions, preventing volatile fluctuations near the decision boundary and smoothing the overall manifold.

2. Energy-Based Sampling (GReg+)

To optimize training on large-scale auxiliary datasets, the authors developed GReg+, which incorporates a two-step sampling process:

  • Feature-Space Clustering: The method employs K-Means clustering in the feature space to group auxiliary OOD samples. This ensures that the model is exposed to a diverse range of outliers rather than overfitting to a specific subset.
  • Informative Selection: Within each cluster, samples are selected based on their energy scores. By picking the most informative samples (those with the lowest or highest energy), the model receives a stronger signal for both the gradient and energy loss terms.

Theoretical Foundations

The authors provide a theoretical basis for GReg through Lipschitz analysis. By penalizing the gradient norm, they essentially constrain the local Lipschitz constant of the neural network. This allows for the calculation of a "certified radius"—a guaranteed spatial distance around a sample within which the OOD detection result is mathematically certain not to change. This connection transforms gradient regularization from a heuristic improvement into a theoretically grounded method for robust detection.

Experimental Evaluation

The GReg framework was evaluated against standard benchmarks, including CIFAR-10, CIFAR-100, and ImageNet-1K. The method consistently outperformed existing state-of-the-art (SOTA) approaches such as Energy Loss, Outlier Exposure (OE), and DOS.

  • ImageNet Performance: GReg+ achieved a 4% improvement in the False Positive Rate at a 95% True Positive Rate (FPR95) compared to previous SOTA methods.
  • CIFAR-100: Utilizing a DenseNet architecture, GReg+ reached an FPR95 of 30.55%, a significant advancement over the Energy Loss baseline (64.37%) and the previous SOTA (34.92%).
  • Classification Integrity: Importantly, the regularization did not degrade standard ID classification accuracy, maintaining the primary utility of the models while enhancing their safety profiles.

Conclusion and Future Work

Gradient-Regularized OOD detection represents a significant step toward more reliable machine learning systems. By focusing on the smoothness of the scoring manifold and ensuring outlier diversity through GReg+, the authors have demonstrated that local stability is key to global performance.

While the method introduces some computational overhead due to the requirement of calculating gradients with respect to inputs during training, it remains more efficient than full Lipschitz estimation. Future research may explore the application of these techniques to non-CNN architectures, such as Vision Transformers (ViTs), and further refine the dependency on auxiliary datasets to make OOD detection even more generalizable.

Summary updated

Abstract

One of the challenges for neural networks in real-life applications is the overconfident errors these models make when the data is not from the original training distribution. Addressing this issue is known as Out-of-Distribution (OOD) detection. Many state-of-the-art OOD methods employ an auxiliary dataset as a surrogate for OOD data during training to achieve improved performance. However, these methods fail to fully exploit the local information embedded in the auxiliary dataset. In this work, we propose the idea of leveraging the information embedded in the gradient of the loss function during training to enable the network to not only learn a desired OOD score for each sample but also to exhibit similar behavior in a local neighborhood around each sample. We also develop a novel energy-based sampling method to allow the network to be exposed to more informative OOD samples during the training phase. This is especially important when the auxiliary dataset is large. We demonstrate the effectiveness of our method through extensive experiments on several OOD benchmarks, improving the existing state-of-the-art FPR95 by \(4\%\) on our ImageNet experiment. We further provide a theoretical analysis through the lens of certified robustness and Lipschitz analysis to showcase the theoretical foundation of our work. Our code is available at https://github.com/o4lc/Greg-OOD.
BibTeX
@inproceedings{sharifi2024gradient,
  author = {Sina Sharifi and Taha Entesari and Bardia Safaei and Vishal M. Patel and Mahyar Fazlyab},
  title = {{Gradient-Regularized Out-of-Distribution Detection}},
  booktitle = {European Conference on Computer Vision},
  year = {2024},
  url = {https://openreview.net/forum?id=fAzvfWhvuq},
}
Figure