GROOD: GRadient-aware Out-Of-Distribution detection in interpolated manifolds
Abstract
\AcpDNN often fail silently with over-confident predictions on out-of-distribution (OOD) samples, posing risks in real-world deployments. Existing techniques predominantly emphasize either the feature representation space or the gradient norms computed with respect to deep neural network (DNN) parameters, yet they overlook the intricate gradient distribution and the topology of classification regions. To address this gap, we introduce GRadient-aware Out-Of-Distribution detection in interpolated manifolds (GROOD), a novel post-hoc method that relies on the discriminative power of gradient space to distinguish between in-distribution (ID) and OOD samples. To build this space, GROOD relies on class prototypes together with a prototype that specifically captures OOD characteristics. Uniquely, our approach incorporates a targeted mix-up operation at an early intermediate layer of the DNN to refine the separation of gradient spaces between ID and OOD samples. For a new sample, we ultimately estimate its deviation from the training distribution by comparing our computed gradient to the gradients observed on the training set, using nearest neighbor distance. Experimental evaluations substantiate that the introduction of targeted input mix-up amplifies the separation between ID and OOD in the gradient space, yielding impressive results across diverse datasets. Notably, when benchmarked on ImageNet-1k, GROOD surpasses the established robustness of state-of-the-art baselines. Through this work, we establish the utility of leveraging gradient spaces and class prototypes for enhanced OOD detection for DNNs in image classification.
1 Introduction
\AcfpDNN have revolutionized a multitude of disciplines, ranging from computer vision and natural language processing to robotics and control systems [14, 32]. These models, trained with empirical risk minimization (ERM) [62], excel in their capacity to generalize learned representations from training datasets to test instances that are independent and identically distributed (iid) [30, 52, 18, 6, 67].
Nevertheless, the iid assumption, so foundational in traditional ERM, often does not hold in real-world settings [19, 35], which can lead to models performing admirably on samples that are iid with respect to the training data, called in-distribution (ID), but make over-confident and erroneous predictions when confronted with samples that deviate from the training distribution, called out-of-distribution (OOD) [44, 59].
This phenomenon is particularly problematic in safety-critical applications like healthcare and autonomous driving where both ID and OOD scenarios are prevalent [38, 4]. Furthermore, we increasingly deploy DNNs in open-world contexts [19], where the test data could substantially deviate from the training distribution. In such scenarios, it becomes imperative for the model to exhibit self-awareness about its own limitations [13]. Conventional approaches that focus solely on minimizing the training loss are often ill-equipped to cope with OOD samples, thereby jeopardizing the safe and reliable deployment of deep learning systems [10, 1, 50, 39].
Consequently, several active lines of research work toward equip** DNNs with the capability to detect unknown or OOD samples effectively. Among them, the post-hoc OOD detection approach, which designs algorithms that leverage representations of already-trained DNNs to identify OOD data, is the most convenient because it does not involve a new training procedure and can be applied to any neural network. Some experimental studies on large benchmarks have even emphasized that this approach may be the most performant [65, 69], stimulating the appearance of dedicated libraries [27, 45].
This rich domain is populated by different families of methods. Gradient-based methods [24, 26, 54, 34] build gradients of quantities based on the DNNs parameters. Distance-based approaches operate in a different regime, focusing on feature-space proximity to differentiate between samples [36, 58, 11]. Other methodologies, not reliant on gradients or feature space, direct their attention to the output space of the model. These works often analyze the distribution of output logits or energy scores as a basis for OOD detection [19, 64, 7].
In this work, we introduce a new method that we call GROOD that builds upon three observations:
-
1.
The neural collapse property [46] suggests that at the end of neural network training, within-class variability tends to zero for sample representation in the feature space. This motivates the use of nearest centroid classification based on the distance to class centroids, also called prototypes, defined as means of samples of each class in the feature space. Inspired by this property, we construct logits out of the distance with respect to class prototypes.
-
2.
As evidenced in Fig. 3 (upper panel) and Sun et al. [57], the distribution of OOD points in the feature space is more spread out. However, we find that an OOD prototype can serve as an anchor point for computing gradients, enabling us to formulate our ID/OOD classification problem in a gradient space (Fig. 3, lower panel) that proves to be more suitable.
- 3.
In contrast with previous post-hoc methods, we combine both gradient and distance-based methods by deriving the gradients of the cross-entropy loss applied to the constructed logits with respect to the newly introduced OOD prototype. Then, for a new input point, we find the nearest neighbour among the gradients of ID data points and compute the distance to this nearest neighbor to serve as our OOD score.
The principal contribution of this work can be encapsulated in the following premise:
Leveraging insights on neural collapse, feature space distribution differences between ID and OOD samples, OOD proxy information and mixup techniques, GROOD combines gradient and distance-based approaches to compute OOD scores, enabling more effective detection of OOD data without requiring additional training.
We conduct an extensive empirical study following the recent methodology introduced in OpenOOD Benchmark [69], but we also evaluate our method on other recent architectures. The following results highlight the following key advantages of GROOD:
-
•
GROOD provides effective detection in both the near and the far OOD regimes with AUROC performance either on par with or above state-of-the-art post-hoc methods across all setups.
- •
2 Related Work
Neural network properties
Prior research has underscored the significance of linear interpolation in manifold space, with applications ranging from word embeddings [43] to machine translation [16]. Verma et al. [61] introduced manifold mixup (MM) as a means to mitigate over-confident predictions near ID data by smoothing decision boundaries. This idea aligns with the observations by Papyan et al. [46] and Kothapalli et al. [29], who investigated the neural collapse (NC) phenomenon, highlighting how training data tends to cluster around class-specific prototypes.
Our work is also informed by insights into the structure of classification regions in deep neural networks. While Fawzi et al. [12] provided an understanding of these regions, our approach primarily leverages the neural collapse phenomenon and the concept of prototype/centroid-based classification. We exploit the sensitivity of feature extractor layers to differentiate between ID and OOD samples, employing guided perturbations at an initial layer to enhance this distinction.
Output-based methods
A prevalent approach to develo** OOD scores involves solely utilizing the model’s output. Hendrycks and Gimpel [20] employ the model’s maximum softmax probability as the OOD score. Guo et al. [15] scale the logits to enhance model calibration, subsequently using the maximum softmax probability as the OOD score. Liang et al. [37] apply temperature scaling and introduce minor perturbations to inputs to distinguish ID and OOD samples, while still using the maximum softmax probability as the OOD score. Hendrycks et al. [21] opt for logits over softmax as the OOD score. They also propose another OOD score which measures the KL divergence between softmax output and mean class conditional distributions.
In contrast to directly using the model output, several works devise OOD scores by calculating a different score over the model outputs. Liu et al. [40] propose the use of energy scores over the logits for OOD detection. Sun et al. [56] suggest truncating high activations to reduce model overconfidence, then using the energy score over the obtained logits as the OOD score. Sun and Li [55] propose pruning activations from less important weights and using the energy score over the obtained logits as the OOD score. Song et al. [53] suggest removing the largest singular value and associated singular vectors from the features to reduce the model’s overconfidence, especially on OOD samples, and use the energy score over the obtained logits as the OOD score. Djurisic et al. [8] propose removing a large portion of low activations and using the energy score over the obtained logits as the OOD score. Liu et al. [41] propose computing generalized entropy instead of cross entropy over the logits and using it as an OOD score.
Feature-based methods
Several other works devise OOD scores using the feature space of the network. Lee et al. [36] use the Mahalanobis distance from class centroids of features as the OOD score. Another work splits the image into two parts, foreground and background, and then calculates the Mahalanobis distance ratio between the two spaces [48]. Sastry and Oore [49] use anomalies found in activity patterns given by Gram matrices of features as the OOD score. Wang et al. [63] construct an additional virtual logit using features and existing logits to measure the probability of a given sample coming from an OOD class and use the softmax score of this logit as the OOD score. Sun et al. [57] use the distance from the k-th nearest neighbor sample as the OOD score. Zhang et al. [68] propose using modern Hopfield networks [47, 31] to measure the discrepancy between an OOD sample and class conditional features of ID samples as an OOD score. Various works propose an OOD score based on the cosine similarity between test sample features and class features [60, 5]. [66] showed that the first singular vector is more suitable for cosine similarity-based detection.
Gradient-based methods
rely on gradient information across different layers instead of relying solely on intermediate layers or network outputs. The seminal work of the out-of-distribution detector for neural networks (ODIN) [22] pioneered the utilization of gradient-based information to discern OOD samples, incorporating gradient-informed input perturbations. Such perturbations are designed to intensify the softmax confidence scores for ID samples, increasing the gap between ID and OOD. This technique is also in use in [35] to improve the discriminative power of the Mahalanobis distance between ID and OOD. While these techniques only use a gradient to perturb the input, Lee and AlRegib [33] proposed using gradients with respect to a neural network’s weight as a proxy to predict uncertainties and hence detect OOD samples having high uncertainties. Another recent work [54] proposed to separate ID and OOD samples by computing the Mahalanobis distance between input samples’ gradients and ID/OOD gradients guided by a self-supervised binary classifier. Recently, Huang et al. [24] proposed GradNorm, which derives a scoring function from the gradient space. GradNorm uses a vector norm of gradients back-propagated using the KL divergence between a softmax output and uniform probability distribution. The key idea is that the magnitude of gradients is higher for ID data than for OOD data. However, GROOD is the first to explore the use of gradients in the penultimate layer space built with ID and OOD information to disentangle ID from OOD.
3 Preliminaries and Notation
Before diving into the specifics of GROOD, we introduce the foundational problem of OOD detection and establish the notations.
3.1 Context and Notations
We consider a supervised classification problem. Let be the input space, and represent the label space. The training set is assumed to be drawn iid from a joint data distribution . We denote as the marginal distribution on .
We assume access to a neural network trained on samples from to produce a logit vector, which is subsequently used for label prediction. The architecture of our network is systematically decomposed as follows:
(1) |
represents the early feature extraction layer, responsible for initial processing of input images to generate low-level features. This is followed by the mid-level feature extractor , and subsequently, the penultimate feature extraction layer . The final stage of the network is the classification module , which outputs the prediction.
3.2 Problem Setting: Out-of-Distribution Detection
When deploying a machine learning model in practice, the classifier should not only be accurate on ID samples but should also identify any OOD inputs as “unknown”.
Formally, OOD detection can be viewed as a binary classification task. During testing, the task is to determine whether a sample comes from (ID) or not (OOD). The decision can be framed as a level set estimation:
where is a score function, and is a threshold. Typically, OOD is evaluated on distribution simulating unknowns that might be encountered during deployment. Such samples are from a distribution whose label set has no intersection with .
4 GROOD Methodology
Overview
In this section, we introduce GRadient-aware Out-Of-Distribution detection in interpolated manifolds (GROOD), which is also summarized in Figure 2. As we show, GROOD is a new and effective way to use a distance-based measure with gradient information for post-hoc OOD detection.
The first step involves computing the class prototypes [46] at the early and penultimate layers of our network, as well as a OOD prototype, as described in Sec. 4.1. Subsequently, in Sec. 4.2, we show how we construct gradients out of these prototypes based on a modified cross-entropy loss built out of the distances to the penultimate class and OOD prototypes. Next, in Sec. 4.3, we introduce the concept of guided prototype interpolation, where we create interpolated samples guided by class prototypes at the early layer of the DNN. This interpolation accentuates the discriminative power of the gradients. Finally, we describe how we build our OOD score, on which our final decision between ID and OOD is based, using the distance to the nearest neighbor in the gradients space, as shown in Sec. 4.4.
4.1 Prototype Computation
The class prototypes are calculated as the averages of feature vectors at their respective layers, but exclusively for training instances that have been correctly classified. This method ensures that the prototypes effectively capture class-discriminative patterns. We note these prototypes and and compute them as:
(2) |
where is the set of correctly classified training instances in class . Next, we propose to encapsulate the representation of our network in an OOD . Crucially, this special prototype is computed by averaging penultimate layer representations on instances that have not been used for training. For this paper, we consider a mixture of uniform noise with an OOD validation dataset:
(3) |
In constructing , we selected 100 data points from an OOD validation dataset sourced from the OpenOOD framework [69, 65] with no overlap with the test set and used in some exisitng post-hoc methods [35, 36, 28]. Alongside this, we incorporated 100 iid samples of uniform noise (), culminating in a total of 200 data points for the OOD prototype computation. By combining real-world OOD data with synthetic noise, we achieve a more robust representation of the OOD prototype. We further illustrate the importance of using this combination in Sec. 5.2 (experiment (5)).
4.2 Gradients Computation
Inspired by the neural collapse property [46] and prototype-based open set recognition [51], we use the previously defined prototypes to construct logits with the Euclidean distances to each class prototype. Crucially, we also consider an additional logit corresponding to our OOD prototype. For any vector in the penultimate latent space, we therefore define our logit vector as
(4) |
where is equivalent to . The corresponding softmax values are:
(5) |
where denotes the softmax value corresponding to the OOD prototype. By considering the cross-entropy loss on this newly introduced set of probits, we are able to quantify how optimal our OOD prototype would be if were to represent an ID sample. This loss is given by:
(6) |
where is the class predicted by , i.e. we are only interested in the case where is an ID class label. Our score is based on the gradient of this loss with respect to the OOD prototype . This expression has a closed form given by
(7) |
where we denote for conciseness. Note that this expression does not depend on the label , since it is always an ID label. Eq. (7) shows that the gradient norm is equal to the softmax probability of the OOD class. When represents an ID sample, tends to be smaller than for OOD samples, which corresponds to a smaller norm of the gradient with respect to the OOD prototype. While this scalar information already enjoys a discriminative power, our gradient also contains the rich information given by the unit vector in the direction pointing from towards . In summary, we expect that the hypothetical update of the OOD prototype represented by will be larger in norm and/or different in orientation when represents an OOD sample compared to the case where it represents an ID sample.
In Fig. 3, we produce a t-SNE visualization of the penultimate feature space vs the gradient space to show how different these spaces can be, thereby potentially encompassing additional information. Specifically, we examine the t-SNE representations of in-distribution (ID) samples alongside out-of-distribution (OOD) test samples. We will see in Sec. 5.2 (experiment (2)) that this information is key to GROOD’s performance, and justifies evaluating the gradients of rather than simply comparing the logits.
4.3 Guided Prototype Interpolation
We perform guided prototype perturbation by mixing-up samples towards the predicted class prototype at an early layer. The interpolation and the penultimate representation of the interpolated sample can be formalized as:
(8) |
where is a hyper-parameter and is the predicted class of . Note that computing requires to perform a forward pass to get and therefore the corresponding prototype.
Our intuition is that mix-up at an early layer with alters the penultimate representation of OOD data more than ID data. In Fig. 4, we illustrate this intuition by comparing the distributions of distances on OOD and ID data points. We can see that OOD penultimate representations are more affected by the mixup than ID ones. We also dedicate Sec. 5.1 to an analysis of the choice of ’s value, that we consequently set as in all our experiments. The results of Sec. 5.2 (experiment (1)) show that this mixup strategy has a positive impact on the final OOD score.
4.4 Distance Measurement
In Sec 4.2 we described our computation of gradients with respect to the OOD prototype based on mixed-up representations. Finally, we estimate the high dimensional distribution of the gradients corresponding to training samples and formulate our detection score as a measure of the deviation to that reference distribution.
Given a test sample , we compute the mixed-up interpolation and then its gradient with respect to the OOD prototype. We then measure its distance to the nearest gradient among training ID samples to serve as the OOD score. Specifically, we define the OOD score as:
(9) |
Finally, based on this OOD score, the sample is classified as ID or OOD using a pre-defined threshold as explained earlier in Sec. 3.
By relying on the distance on the gradient space, our method provides a nuanced yet computationally feasible strategy for OOD detection. This approach leverages both gradient information and distance metrics, encapsulating insights from both gradient-based and distance-based methods. For a comprehensive overview, the complete GROOD algorithm is outlined in Algorithm 1 and Algorithm 2.
5 Experiments
CIFAR-10 | CIFAR-100 | ImageNet-200 | ImageNet-1K | |||||
ID Acc. | 95.06(±0.30) | 77.25(±0.10) | 86.37(±0.08) | 76.18 | ||||
Method | Near-OOD | Far-OOD | Near-OOD | Far-OOD | Near-OOD | Far-OOD | Near-OOD | Far-OOD |
OpenMax [3] (CVPR’16) | 87.62(±0.29) | 89.62(±0.19) | 76.41(±0.25) | 79.48(±0.41) | 80.27(±0.10) | 90.20(±0.17) | 74.77 | 89.26 |
MSP [20] (ICLR’17) | 88.03(±0.25) | 90.73(±0.43) | 80.27(±0.11) | 77.76(±0.44) | 83.34(±0.06) | 90.13(±0.09) | 76.02 | 85.23 |
TempScale [15] (ICML’17) | 88.09(±0.31) | 90.97(±0.52) | 80.90(±0.07) | 78.74(±0.51) | 83.69(±0.04) | 90.82(±0.09) | 77.14 | 87.56 |
ODIN [37] (ICLR’18) | 82.87(±1.85) | 87.96(±0.61) | 79.90(±0.11) | 79.28(±0.21) | 80.27(±0.08) | 91.71(±0.19) | 74.75 | 89.47 |
MDS [36] (NeurIPS’18) | 84.20(±2.40) | 89.72(±1.36) | 58.69(±0.09) | 69.39(±1.39) | 61.93(±0.51) | 74.72(±0.26) | 55.44 | 74.25 |
MDSEns [36] (NeurIPS’18) | 60.43(±0.26) | 73.90(±0.27) | 46.31(±0.24) | 66.00(±0.69) | 54.32(±0.24) | 69.27(±0.57) | 49.67 | 67.52 |
Gram [49] (ICML’20) | 58.66(±4.83) | 71.73(±3.20) | 51.66(±0.77) | 73.36(±1.08) | 67.67(±1.07) | 71.19(±0.24) | 61.70 | 79.71 |
EBO [40] (NeurIPS’20) | 87.58(±0.46) | 91.21(±0.92) | 80.91(±0.08) | 79.77(±0.61) | 82.50(±0.05) | 90.86(±0.21) | 75.89 | 89.47 |
OpenGAN [28] (ICCV’21) | 53.71(±7.68) | 54.61(±15.51) | 65.98(±1.26) | 67.88(±7.16) | 59.79(±3.39) | 73.15(±5.07) | N/A | N/A |
GradNorm [25] (NeurIPS’21) | 54.90(±0.98) | 57.55(±3.22) | 70.13(±0.47) | 69.14(±1.05) | 72.75(±0.48) | 84.26(±0.87) | 72.96 | 90.25 |
ReAct [56] (NeurIPS’21) | 87.11(±0.61) | 90.42(±1.41) | 80.77(±0.05) | 80.39(±0.49) | 81.87(±0.98) | 92.31(±0.56) | 77.38 | 93.67 |
MLS [21] (ICML’22) | 87.52(±0.47) | 91.10(±0.89) | 81.05(±0.07) | 79.67(±0.57) | 82.90(±0.04) | 91.11(±0.19) | 76.46 | 89.57 |
KLM [21] (ICML’22) | 79.19(±0.80) | 82.68(±0.21) | 76.56(±0.25) | 76.24(±0.52) | 80.76(±0.08) | 88.53(±0.11) | 76.64 | 87.60 |
VIM [63] (CVPR’22) | 88.68(±0.28) | 93.48(±0.24) | 74.98(±0.13) | 81.70(±0.62) | 78.68(±0.24) | 91.26(±0.19) | 72.08 | 92.68 |
KNN [57] (ICML’22) | 90.64(±0.20) | 92.96(±0.14) | 80.18(±0.15) | 82.40(±0.17) | 81.57(±0.17) | 93.16(±0.22) | 71.10 | 90.18 |
DICE [55] (ECCV’22) | 78.34(±0.79) | 84.23(±1.89) | 79.38(±0.23) | 80.01(±0.18) | 81.78(±0.14) | 90.80(±0.31) | 73.07 | 90.95 |
RankFeat [53] (NeurIPS’22) | 79.46(±2.52) | 75.87(±5.06) | 61.88(±1.28) | 67.10(±1.42) | 56.92(±1.59) | 38.22(±3.85) | 50.99 | 53.93 |
ASH [8] (ICLR’23) | 75.27(±1.04) | 78.49(±2.58) | 78.20(±0.15) | 80.58(±0.66) | 82.38(±0.19) | 93.90(±0.27) | 78.17 | 95.74 |
SHE [68] (ICLR’23) | 81.54(±0.51) | 85.32(±1.43) | 78.95(±0.18) | 76.92(±1.16) | 80.18(±0.25) | 89.81(±0.61) | 73.78 | 90.92 |
GEN [41] (CVPR’23) | 88.2(±0.3) | 91.35(±0.55) | 81.31(±0.1) | 79.68(±0.6) | 83.68(±0.34) | 91.36 (±0.45) | 76.85 | 89.76 |
GROOD (OURS) | 91.05(±0.001) | 94.19(±0.3) | 81.01(±0.01) | 81.98(±0.7) | 81.9(±0.07) | 94.9(±0.012) | 78.18 | 96.16 |
For a comprehensive evaluation of GROOD’s performance, we adhere to the OpenOOD v1.5 criteria [69, 65]. Results are aggregated in Tab. 1 including the performance of the nearest class prototype used instead of the classification head. For robustness, each evaluation metric except for ImageNet-1K is derived from three runs with unique initialization seeds. In the case of ImageNet-1K, we report results based on a single seed run provided by torchvision Author [2].
Benchmarking Strategy
Dataset Characteristics
-
•
CIFAR-10 and CIFAR-100: Each encompasses 50k training and 10k test images. For near-OOD, we use CIFAR-100 and TinyImageNet; for far-OOD, MNIST, SVHN, Textures, and Places365.
-
•
ImageNet-200: A subset of ImageNet featuring 200 classes and 64x64 resolution. SSB-hard and NINCO serve as near-OOD, while iNaturalist, Textures, and OpenImage-O constitute far-OOD.
-
•
ImageNet-1K: Encompasses 1000 classes, and shares OOD datasets with ImageNet-200.
- •
Experimental Configuration
-
•
ResNet-18: Deployed for CIFAR-10/100 and ImageNet-200. Instead of training the models from scratch, we utilized pre-trained checkpoints provided by the OpenOOD framework [69, 65]. This approach ensures consistency with the established benchmark and allows us to focus on the evaluation of GROOD’s robustness. For a comprehensive analysis, we tested models with three distinct initialization seeds.
-
•
ResNet-50, ViT-B-16, Swin-T: Applied to ImageNet-1K using pre-trained torchvision models. This setup extends beyond the scope of OpenOOD v1 [65], allowing us to explore the effectiveness of GROOD in a broader context.
Experimental results
5.1 Choice of
The selection of the parameter is pivotal to the performance of the interpolation mechanism described in Sec. 4.3. The value of determines the extent to which the input image is perturbed towards the class prototype during guided interpolation. To empirically assess the impact of different values, we conduct experiments on the CIFAR-10 and CIFAR-100 datasets. The results of these experiments are illustrated in Fig. 6, where we observe that the method is optimal when , i.e. when the mixup perturbation is moderate. This is consistent since the lower is, the less information we keep about .
5.2 Ablations
Model Variant | AUROC (%) | |
---|---|---|
Far-OOD | Near-OOD | |
(1) Without guided interpolation | 93.64(±0.31) | 90.1(±0.029) |
(2) Distance to the Noise prototype | 90.11(±4.43) | 85.64(±1.03) |
(3) Gradient L1-norm only | 93.85(±0.44) | 90.56(±0.013) |
(4) Grads. wrt class prototypes | 93.42(±0.33) | 90.37(±0.006) |
(5) OOD prototype with uniform noise only | 92.83(±0.6) | 89.5(±0.03) |
GROOD | 94.19(±0.3) | 91.05(±0.001) |
In Tab. 2, we empirically demonstrate the effectiveness of each component within GROOD on CIFAR10.
(1) First, we remove the guided interpolation mechanism, effectively fixing instead of . This leads to a decrease in the AUROC for both near and far OOD, which shows that gradients obtained when applying this mix-up strategy allow for a better discrimination of ID and OOD samples, as shown also in Fig. 6.
(2) We investigate the implications of directly using the distance from to the OOD prototype as the OOD score. This approach shows the importance of using the gradients to construct the scores and the importance of including the OOD prototype.
(3) We also validate the importance of using the distance to the nearest neighbor in the gradient space by assessing the usage of the gradient -norm as in gradnorm [23] only as the OOD score. The former strategy indicates the value of comprehensive gradient information for OOD detection. The consistent enhancements across these varied experimental conditions affirm the robustness of the proposed GROOD framework.
(4) Subsequently, we explore the impact of employing gradients (wrt class prototypes) rather than . The results reveal a distinct advantage in favor of the OOD prototype.
(5) Finally, we explore the importance of using OOD data from external dataset instead of pure random noise by running GROOD with an OOD prototype built with uniform noise only ( in Eq. (3)).
6 Conclusion
In this work, we presented the GRadient-aware Out-Of-Distribution detection in interpolated manifolds (GROOD), a novel approach to the challenge of detecting OOD samples in DNN image classifiers. By leveraging the strengths of gradient information and distance metrics, GROOD demonstrates a significant advancement in identifying OOD instances, crucial for deploying DNNs in real-world applications where reliability and safety are paramount.
Our methodology relies on the innovative use of class prototypes to encapsulate class-specific features, the design of an OOD prototype to encompass OOD information, and the employment of gradients of a newly defined cross-entropy loss relying on the distance to these prototypes for enhanced separation between in-distribution (ID) and OOD samples. The guided prototype interpolation and the subsequent nearest neighbor-based distance measurement offer a robust and reliable OOD scoring mechanism, as evidenced by our experimental results.
The experimental evaluation across various benchmarks illustrates the efficacy of GROOD in detecting both near and far OOD samples, independent of specific DNN architectures or training data distributions. The ability of GROOD to operate without extensive hyper-parameter tuning further underscores its practicality and adaptability.
References
- Arjovsky et al. [2019] Martín Arjovsky, Léon Bottou, Ishaan Gulrajani, and David Lopez-Paz. Invariant Risk Minimization. CoRR, abs/1907.02893, 2019.
- Author [s] Author(s). TorchVision, the PyTorch Computer Vision Library. https://pytorch.org/vision/, 2016.
- Bendale and Boult [2015] Abhijit Bendale and Terrance E. Boult. Towards Open Set Deep Networks. CoRR, abs/1511.06233, 2015.
- Bojarski et al. [2016] Mariusz Bojarski, Davide Del Testa, Daniel Dworakowski, Bernhard Firner, Beat Flepp, Prasoon Goyal, Lawrence D. Jackel, Mathew Monfort, Urs Muller, Jiakai Zhang, Xin Zhang, Jake Zhao, and Karol Zieba. End to End Learning for Self-driving Cars. CoRR, abs/1604.07316, 2016.
- Chen et al. [2020] Xingyu Chen, Xuguang Lan, Fuchun Sun, and Nanning Zheng. A Boundary Based Out-of-distribution Classifier for Generalized Zero-shot Learning. CoRR, abs/2008.04872, 2020.
- Cho et al. [2014] Kyunghyun Cho, Bart van Merrienboer, Çaglar Gülçehre, Fethi Bougares, Holger Schwenk, and Yoshua Bengio. Learning Phrase Representations using RNN Encoder-decoder for Statistical Machine Translation. CoRR, abs/1406.1078, 2014.
- Djurisic et al. [2022a] Andrija Djurisic, Nebojsa Bozanic, Arjun Ashok, and Rosanne Liu. Extremely Simple Activation Sha** for Out-of-distribution Detection. CoRR, abs/2209.09858, 2022a.
- Djurisic et al. [2022b] Andrija Djurisic, Nebojsa Bozanic, Arjun Ashok, and Rosanne Liu. Extremely Simple Activation Sha** for Out-of-distribution Detection. CoRR, abs/2209.09858, 2022b.
- Dosovitskiy et al. [2020] Alexey Dosovitskiy, Lucas Beyer, Alexander Kolesnikov, Dirk Weissenborn, Xiaohua Zhai, Thomas Unterthiner, Mostafa Dehghani, Matthias Minderer, Georg Heigold, Sylvain Gelly, Jakob Uszkoreit, and Neil Houlsby. An Image is Worth 16x16 Words: Transformers for Image Recognition at Scale. CoRR, abs/2010.11929, 2020.
- Duchi and Namkoong [2018] John C. Duchi and Hongseok Namkoong. Learning Models with Uniform Performance via Distributionally Robust Optimization. CoRR, abs/1810.08750, 2018.
- Fang et al. [2022] Zhen Fang, Yixuan Li, Jie Lu, Jiahua Dong, Bo Han, and Feng Liu. Is Out-of-distribution Detection Learnable? CoRR, abs/2210.14707, 2022.
- Fawzi et al. [2017] Alhussein Fawzi, Seyed-Mohsen Moosavi-Dezfooli, Pascal Frossard, and Stefano Soatto. Classification regions of deep neural networks. CoRR, abs/1705.09552, 2017.
- Gal and Ghahramani [2015] Yarin Gal and Zoubin Ghahramani. Dropout as a Bayesian Approximation: Representing Model Uncertainty in Deep Learning. CoRR, abs/1506.02142, 2015.
- Goodfellow et al. [2016] Ian J. Goodfellow, Yoshua Bengio, and Aaron C. Courville. Deep Learning. MIT Press, 2016.
- Guo et al. [2017] Chuan Guo, Geoff Pleiss, Yu Sun, and Kilian Q. Weinberger. On Calibration of Modern Neural Networks. CoRR, abs/1706.04599, 2017.
- Hassan et al. [2017] Hany Hassan, Mostafa Elaraby, and Ahmed Y. Tawfik. Synthetic Data for Neural Machine Translation of Spoken-dialects. In Proceedings of the 14th International Conference on Spoken Language Translation, IWSLT 2017, Tokyo, Japan, December 14-15, 2017, pages 82–89. International Workshop on Spoken Language Translation, 2017.
- He et al. [2015a] Kaiming He, Xiangyu Zhang, Shaoqing Ren, and Jian Sun. Deep residual learning for image recognition. CoRR abs/1512.03385 (2015), 2015a.
- He et al. [2015b] Kaiming He, Xiangyu Zhang, Shaoqing Ren, and Jian Sun. Deep Residual Learning for Image Recognition. CoRR, abs/1512.03385, 2015b.
- Hendrycks and Gimpel [2016a] Dan Hendrycks and Kevin Gimpel. A Baseline for Detecting Misclassified and Out-of-distribution Examples in Neural Networks. CoRR, abs/1610.02136, 2016a.
- Hendrycks and Gimpel [2016b] Dan Hendrycks and Kevin Gimpel. A Baseline for Detecting Misclassified and Out-of-distribution Examples in Neural Networks. CoRR, abs/1610.02136, 2016b.
- Hendrycks et al. [2022] Dan Hendrycks, Steven Basart, Mantas Mazeika, Andy Zou, Joseph Kwon, Mohammadreza Mostajabi, Jacob Steinhardt, and Dawn Song. Scaling Out-of-distribution Detection for Real-world Settings. In International Conference on Machine Learning, ICML 2022, 17-23 July 2022, Baltimore, Maryland, USA, pages 8759–8773. PMLR, 2022.
- Hsu et al. [2020] Yen-Chang Hsu, Yilin Shen, Hongxia **, and Zsolt Kira. Generalized ODIN: Detecting Out-of-distribution Image without Learning from Out-of-distribution Data. CoRR, abs/2002.11297, 2020.
- Huang et al. [2021a] Rui Huang, Andrew Geng, and Yixuan Li. On the Importance of Gradients for Detecting Distributional Shifts in the Wild. CoRR, abs/2110.00218, 2021a.
- Huang et al. [2021b] Rui Huang, Andrew Geng, and Yixuan Li. On the Importance of Gradients for Detecting Distributional Shifts in the Wild. CoRR, abs/2110.00218, 2021b.
- Huang et al. [2021c] Rui Huang, Andrew Geng, and Yixuan Li. On the Importance of Gradients for Detecting Distributional Shifts in the Wild. CoRR, abs/2110.00218, 2021c.
- Igoe et al. [2022] Conor Igoe, Youngseog Chung, Ian Char, and Jeff Schneider. How Useful are Gradients for OOD Detection Really? CoRR, abs/2205.10439, 2022.
- Kirchheim et al. [2022] Konstantin Kirchheim, Marco Filax, and Frank Ortmeier. Pytorch-ood: A library for out-of-distribution detection based on pytorch. In Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR) Workshops, pages 4351–4360, 2022.
- Kong and Ramanan [2021] Shu Kong and Deva Ramanan. OpenGAN: Open-set Recognition via Open Data Generation. CoRR, abs/2104.02939, 2021.
- Kothapalli et al. [2022] Vignesh Kothapalli, Ebrahim Rasromani, and Vasudev Awatramani. Neural Collapse: A Review on Modelling Principles and Generalization. CoRR, abs/2206.04041, 2022.
- Krizhevsky et al. [2012] Alex Krizhevsky, Ilya Sutskever, and Geoffrey E. Hinton. ImageNet Classification with Deep Convolutional Neural Networks. In Advances in Neural Information Processing Systems 25: 26th Annual Conference on Neural Information Processing Systems 2012. Proceedings of a meeting held December 3-6, 2012, Lake Tahoe, Nevada, United States, pages 1106–1114, 2012.
- Krotov and Hopfield [2016] Dmitry Krotov and John J Hopfield. Dense associative memory for pattern recognition. Advances in neural information processing systems, 29, 2016.
- LeCun et al. [2015] Yann LeCun, Yoshua Bengio, and Geoffrey E. Hinton. Deep learning. Nat., 521(7553):436–444, 2015.
- Lee and AlRegib [2020] **sol Lee and Ghassan AlRegib. Gradients as a Measure of Uncertainty in Neural Networks. CoRR, abs/2008.08030, 2020.
- Lee et al. [2022] **sol Lee, Mohit Prabhushankar, and Ghassan AlRegib. Gradient-based Adversarial and Out-of-distribution Detection. CoRR, abs/2206.08255, 2022.
- Lee et al. [2018a] Kimin Lee, Kibok Lee, Honglak Lee, and **woo Shin. A simple unified framework for detecting out-of-distribution samples and adversarial attacks. Advances in neural information processing systems, 31, 2018a.
- Lee et al. [2018b] Kimin Lee, Kibok Lee, Honglak Lee, and **woo Shin. A Simple Unified Framework for Detecting Out-of-distribution Samples and Adversarial Attacks. CoRR, abs/1807.03888, 2018b.
- Liang et al. [2018] Shiyu Liang, Yixuan Li, and R. Srikant. Enhancing The Reliability of Out-of-distribution Image Detection in Neural Networks. In 6th International Conference on Learning Representations, ICLR 2018, Vancouver, BC, Canada, April 30 - May 3, 2018, Conference Track Proceedings. OpenReview.net, 2018.
- Litjens et al. [2017] Geert Litjens, Thijs Kooi, Babak Ehteshami Bejnordi, Arnaud Arindra Adiyoso Setio, Francesco Ciompi, Mohsen Ghafoorian, Jeroen A. W. M. van der Laak, Bram van Ginneken, and Clara I. Sánchez. A Survey on Deep Learning in Medical Image Analysis. CoRR, abs/1702.05747, 2017.
- Liu et al. [2021a] Jiashuo Liu, Zheyuan Hu, Peng Cui, Bo Li, and Zheyan Shen. Heterogeneous Risk Minimization. CoRR, abs/2105.03818, 2021a.
- Liu et al. [2020] Weitang Liu, Xiaoyun Wang, John D. Owens, and Yixuan Li. Energy-based Out-of-distribution Detection. CoRR, abs/2010.03759, 2020.
- Liu et al. [2023] Xixi Liu, Yaroslava Lochman, and Christopher Zach. Gen: Pushing the limits of softmax-based out-of-distribution detection. In Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition, pages 23946–23955, 2023.
- Liu et al. [2021b] Ze Liu, Yutong Lin, Yue Cao, Han Hu, Yixuan Wei, Zheng Zhang, Stephen Lin, and Baining Guo. Swin Transformer: Hierarchical Vision Transformer using Shifted Windows. CoRR, abs/2103.14030, 2021b.
- Mikolov et al. [2013] Tomás Mikolov, Kai Chen, Greg Corrado, and Jeffrey Dean. Efficient Estimation of Word Representations in Vector Space. In 1st International Conference on Learning Representations, ICLR 2013, Scottsdale, Arizona, USA, May 2-4, 2013, Workshop Track Proceedings, 2013.
- Nguyen et al. [2014] Anh Mai Nguyen, Jason Yosinski, and Jeff Clune. Deep Neural Networks are Easily Fooled: High Confidence Predictions for Unrecognizable Images. CoRR, abs/1412.1897, 2014.
- Novello et al. [2023] Paul Novello, Yannick Prudent, Corentin Friedrich, Yann Pequignot, and Matthieu Le Goff. Oodeel, a simple, compact, and hackable post-hoc deep ood detection for already trained tensorflow or pytorch image classifiers. https://github.com/deel-ai/oodeel, 2023.
- Papyan et al. [2020] Vardan Papyan, X. Y. Han, and David L. Donoho. Prevalence of Neural Collapse during the terminal phase of deep learning training. CoRR, abs/2008.08186, 2020.
- Ramsauer et al. [2020] Hubert Ramsauer, Bernhard Schäfl, Johannes Lehner, Philipp Seidl, Michael Widrich, Thomas Adler, Lukas Gruber, Markus Holzleitner, Milena Pavlović, Geir Kjetil Sandve, et al. Hopfield networks is all you need. arXiv preprint arXiv:2008.02217, 2020.
- Ren et al. [2021] Jie Ren, Stanislav Fort, Jeremiah Z. Liu, Abhijit Guha Roy, Shreyas Padhy, and Balaji Lakshminarayanan. A Simple Fix to Mahalanobis Distance for Improving Near-OOD Detection. CoRR, abs/2106.09022, 2021.
- Sastry and Oore [2020] Chandramouli Shama Sastry and Sageev Oore. Detecting Out-of-distribution Examples with Gram Matrices. In Proceedings of the 37th International Conference on Machine Learning, ICML 2020, 13-18 July 2020, Virtual Event, pages 8491–8501. PMLR, 2020.
- Shen et al. [2019] Zheyan Shen, Peng Cui, Tong Zhang, and Kun Kuang. Stable Learning via Sample Reweighting. CoRR, abs/1911.12580, 2019.
- Shu et al. [2019] Yu Shu, Yemin Shi, Yaowei Wang, Tiejun Huang, and Yonghong Tian. P-ODN: Prototype based Open Deep Network for Open Set Recognition. CoRR, abs/1905.01851, 2019.
- Simonyan and Zisserman [2015] Karen Simonyan and Andrew Zisserman. Very Deep Convolutional Networks for Large-scale Image Recognition. In 3rd International Conference on Learning Representations, ICLR 2015, San Diego, CA, USA, May 7-9, 2015, Conference Track Proceedings, 2015.
- Song et al. [2022] Yue Song, Nicu Sebe, and Wei Wang. RankFeat: Rank-1 Feature Removal for Out-of-distribution Detection. CoRR, abs/2209.08590, 2022.
- Sun et al. [2021a] **gbo Sun, Li Yang, Jiaxin Zhang, Frank Liu, Mahantesh Halappanavar, Deliang Fan, and Yu Cao. Gradient-based Novelty Detection Boosted by Self-supervised Binary Classification. CoRR, abs/2112.09815, 2021a.
- Sun and Li [2022] Yiyou Sun and Yixuan Li. DICE: Leveraging Sparsification for Out-of-distribution Detection. In Computer Vision - ECCV 2022: 17th European Conference, Tel Aviv, Israel, October 23-27, 2022, Proceedings, Part XXIV, pages 691–708. Springer, 2022.
- Sun et al. [2021b] Yiyou Sun, Chuan Guo, and Yixuan Li. ReAct: Out-of-distribution Detection With Rectified Activations. CoRR, abs/2111.12797, 2021b.
- Sun et al. [2022a] Yiyou Sun, Yifei Ming, Xiao** Zhu, and Yixuan Li. Out-of-distribution Detection with Deep Nearest Neighbors. CoRR, abs/2204.06507, 2022a.
- Sun et al. [2022b] Yiyou Sun, Yifei Ming, Xiao** Zhu, and Yixuan Li. Out-of-distribution Detection with Deep Nearest Neighbors. CoRR, abs/2204.06507, 2022b.
- Szegedy et al. [2014] Christian Szegedy, Wojciech Zaremba, Ilya Sutskever, Joan Bruna, Dumitru Erhan, Ian J. Goodfellow, and Rob Fergus. Intriguing properties of neural networks. In 2nd International Conference on Learning Representations, ICLR 2014, Banff, AB, Canada, April 14-16, 2014, Conference Track Proceedings, 2014.
- Techapanurak et al. [2020] Engkarat Techapanurak, Masanori Suganuma, and Takayuki Okatani. Hyperparameter-free Out-of-distribution Detection Using Cosine Similarity. In Computer Vision - ACCV 2020 - 15th Asian Conference on Computer Vision, Kyoto, Japan, November 30 - December 4, 2020, Revised Selected Papers, Part IV, pages 53–69. Springer, 2020.
- Verma et al. [2019] Vikas Verma, Alex Lamb, Christopher Beckham, Amir Najafi, Ioannis Mitliagkas, David Lopez-Paz, and Yoshua Bengio. Manifold Mixup: Better Representations by Interpolating Hidden States. In Proceedings of the 36th International Conference on Machine Learning, ICML 2019, 9-15 June 2019, Long Beach, California, USA, pages 6438–6447. PMLR, 2019.
- Vladimir and Vapnik [1998] N Vapnik Vladimir and Vlamimir Vapnik. Statistical learning theory. Xu JH and Zhang XG. translation. Bei**g: Publishing House of Electronics Industry, 2O04, 1998.
- Wang et al. [2022a] Haoqi Wang, Zhizhong Li, Litong Feng, and Wayne Zhang. ViM: Out-Of-distribution with Virtual-logit Matching. CoRR, abs/2203.10807, 2022a.
- Wang et al. [2022b] Haoqi Wang, Zhizhong Li, Litong Feng, and Wayne Zhang. ViM: Out-Of-distribution with Virtual-logit Matching. CoRR, abs/2203.10807, 2022b.
- Yang et al. [2022] **gkang Yang, Pengyun Wang, Dejian Zou, Zitang Zhou, Kunyuan Ding, WenXuan Peng, Haoqi Wang, Guangyao Chen, Bo Li, Yiyou Sun, Xuefeng Du, Kaiyang Zhou, Wayne Zhang, Dan Hendrycks, Yixuan Li, and Ziwei Liu. OpenOOD: Benchmarking Generalized Out-of-distribution Detection. In Thirty-sixth Conference on Neural Information Processing Systems Datasets and Benchmarks Track, pages 32598–32611, 2022.
- Zaeemzadeh et al. [2021] Alireza Zaeemzadeh, Niccoló Bisagno, Zeno Sambugaro, Nicola Conci, Nazanin Rahnavard, and Mubarak Shah. Out-of-distribution Detection Using Union of 1-Dimensional Subspaces. In IEEE Conference on Computer Vision and Pattern Recognition, CVPR 2021, virtual, June 19-25, 2021, pages 9452–9461. Computer Vision Foundation / IEEE, 2021.
- Zhang et al. [2016] Chiyuan Zhang, Samy Bengio, Moritz Hardt, Benjamin Recht, and Oriol Vinyals. Understanding deep learning requires rethinking generalization. CoRR, abs/1611.03530, 2016.
- Zhang et al. [2023a] **song Zhang, Qiang Fu, Xu Chen, Lun Du, Zelin Li, Gang Wang, Xiaoguang Liu, Shi Han, and Dongmei Zhang. Out-of-distribution Detection based on In-distribution Data Patterns Memorization with Modern Hopfield Energy. In The Eleventh International Conference on Learning Representations, ICLR 2023, Kigali, Rwanda, May 1-5, 2023. OpenReview.net, 2023a.
- Zhang et al. [2023b] **gyang Zhang, **gkang Yang, Pengyun Wang, Haoqi Wang, Yueqian Lin, Haoran Zhang, Yiyou Sun, Xuefeng Du, Kaiyang Zhou, Wayne Zhang, Yixuan Li, Ziwei Liu, Yiran Chen, and Hai Li. OpenOOD v1.5: Enhanced Benchmark for Out-of-distribution Detection. CoRR, abs/2306.09301, 2023b.