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).

