RG: OUT-OF-DISTRIBUTION DETECTION WITH REACTIVATE GRADNORM

Abstract

Detecting out-of-distribution (OOD) data is critical to building reliable machine learning systems in the open world. Previous works mainly perform OOD detection in feature space or output space. Recently, researchers have achieved promising results using gradient information, which combines the information in both feature and output space for OOD detection. However, existing works still suffer from the problem of overconfidence. To address this problem, we propose a novel method called "Reactivate Gradnorm (RG)", which exploits the norm of the clipped feature vector and the energy in the output space for OOD detection. To verify the effectiveness of our method, we conduct experiments on four benchmark datasets. Experimental results demonstrate that our RG outperforms existing state-of-the-art approaches by 2.06% in average AUROC. Meanwhile, RG is easy to implement and does not require additional OOD data or fine-tuning process. We can realize OOD detection in only one forward pass of any pretrained model.

1. INTRODUCTION

In addition to the need for the accuracy of predictions, more and more attention has been paid to whether the model can make rejection identification when faced with completely unfamiliar samples. People want models that are not only accurate in their familiar data distribution but also aware of uncertainty outside the training distribution. This gives rise to the importance of out-of-distribution (OOD) detection, which determines whether an input is in-distribution (ID) or OOD. And OOD detection is widely used in fields with high safety requirements, such as medical diagnosis (Nair et al., 2020) and autonomous driving (Amini et al., 2018) . Deep neural networks can easily make overconfident predictions on OOD inputs, which increases the challenge to separate ID and OOD data Van den Oord et al. (2016); Chen et al. (2021) . For instance, a model may wrongly but confidently classify an image of a crab into the clapping class, even though no crab-related concepts appear in the training set. Previous works focused on deriving OOD uncertainty measurements from the output space (Hendrycks & Gimpel, 2016; Liu et al., 2020) or feature space (Lee et al., 2018; Sun et al., 2022) . A recent work (Huang et al., 2021) based on gradients has intrigued us. Actually, gradient information can often be decomposed into information from feature space and output space, which can be derived from the process of the BP algorithm. However, this method still has room for further improvement on OOD detection, which encourages us to utilize both output space and feature space information for better OOD detection. In this paper, we perform OOD detection by jointly using information from feature space and output space. Formally, we propose Reactivate Gradnorm (RG), a simple and effective method to detect OOD by utilizing the inputs and outputs of the last layer of the neural networks. Specifically, RG directly uses the product of the 1-norm of the clipped input of the last layer of neural network and the logarithm of the exponential sum of the outputs (free energy) as the OOD scoring function. The reason for using the 1-norm of the hidden layer features is that the neurons will be activated for the ID sample. The motivation for cropping it comes from the fact that there will be a few OOD samples with strong features. Appropriate cropping can reduce the 1-norm of the features of the OOD samples without excessively affecting the 1-norm of the features of the ID samples. The energy information in the logits space is selected instead of the information in the probability space (like MSP(Hendrycks & Gimpel, 2016)) because there is information loss from the logits space to the probability space (the relative size information of the logits will be ignored by the softmax layer). on the other hand, there are good theoretical and practical effects by using the energy as an OOD evaluation score. Empirically, we have established excellent performance on the large-scale ImageNet benchmark. RG is vastly superior to previous use of energy after crop ReAct (Sun et al., 2021) 8.9% by AUROC, and our source of inspiration Grodnorm 5.86% by AUROC. Our method also achieves excellent performance compared to the MOS (Huang & Li, 2021) 2.06% by AUROC. Our key results and contributions are summarized as follows: • We propose RG, a simple and effective OOD uncertainty estimation method, which is labelagnostic (no label required), OOD agnostic (no outlier data required), train data agnostic (Only the pre-trained model is used and no fine-tuning or extra training). • We conduct sufficient experiments on the combination of information from output space and input space to help us better understand the effectiveness of our OOD detection methods. RG promotes the average AUROC by 2.06% compared to the current best method under the same pre-trained model and dataset. Experiments show that using information from both feature space and output space has a gain for OOD detection. • We perform a simple theoretical analysis of our method that using information from both feature space and output space at the same time helps to model the distribution of training data, which facilitates ood detection. And we unify several previous approaches under the equation 10 in a new framework.

2. BACKGROUND

In a supervised learning, we denote by X = R d the input space and Y = {1, 2, ..., C} the output space. A neural network f (x, θ) = {f i (x, θ)} C i=1 with the parameter θ, we abbreviate it as f (x), which is a mapping from X to R C . When given a dataset D = {(x i , y i )} n i=1 , the supervised learning task is to minimize: R(f ) = E (x,y)∈D l CE (f (x), y) where l CE usually used the cross-entropy loss: l CE (f (x), y) = -log e fy(x) c i=1 f i (x) where y is the ground-truth label. Problem statement OOD detection can be formulated as a binary classification problem. The goal is to design a discriminator G(x) which is a mapping from X to R. Given a threshold c, we will decide a sample x as an OOD sample if and only if G(x) < c. The design of the discriminator G is often related to the neural network model f (x, θ), which will help the neural network model reject the recognition when G(x) < c. Typically, c will be set to the fraction of 95% of In-distribution (ID) data that can to be identified as ID. The key challenge is to derive a scoring function G(x) that captures OOD uncertainty. Previous OOD detection approaches primarily rely on the output or feature space for deriving OOD scores, and there has been some recent interest in utilizing gradient information for OOD detection. We will reveal that effective gradient-based OOD detection method is a method that combines the information from output space and feature space. And based on it, a more efficient method is proposed in the following section.

3. MOTIVATION AND METHOD

In this section, we will first describe the gradient-based OOD detection method and then analyze that the gradient-based OOD detection method is based on the synthesis of the information in the feature space and the information in the output space in section 3.1. The gradient-based OOD detection method inspired us to design an appropriate OOD score which is a combination of the norm of the clipped feature vector and the energy in the output space to achieve OOD detection in Section 3.2. In section 3.3, we unify several previous approaches under the equation 10 in a new framework.

