Revisiting Out-of-Distribution Detection: A Simple Baseline is Surprisingly Effective

1 INTRODUCTION . While deep learning has significantly improved performance in many application domains , there are serious concerns for using deep neural networks in applications which are of safety-critical nature . With one major problem being adversarial samples ( Szegedy et al. , 2014 ; Madry et al. , 2018 ) , which are small imperceptible modifications of the image that change the decision of the classifier , another major problem are overconfident predictions ( Nguyen et al. , 2015 ; Hendrycks & Gimpel , 2017 ; Hein et al. , 2019 ) for images not belonging to the classes of the actual task . Here , one distinguishes between far out-of-distribution data , e.g . different forms of noise or completely unrelated tasks like CIFAR-10 vs. SVHN , and close out-of-distribution data which can for example occur in related image classification tasks where the semantic structure is very similar e.g . CIFAR-10 vs. CIFAR-100 . Both are important to be distinguished from the in-distribution , but it is conceivable that close out-of-distribution data is the more difficult problem with potentially fatal consequences : in an automated diagnosis system we want that the system recognizes that it “ does not know ” when a new unseen disease comes in rather than assigning high confidence into a known class leading to fatal treatment decisions . Thus out-of-distribution awareness is a key property of trustworthy AI systems . In this paper , we focus on the setting of OOD detection where during training time , there is no information available on the distribution of OOD inputs that might appear when the model is used for inference . A large number of different approaches to OOD detection based on combinations of density estimation , classifier confidence , logit space energy , feature space geometry , behaviour on auxiliary tasks , and other principles has been proposed to tackle this problem . We give a detailed overview of existing OOD detection methods in Appendix D. However , most OOD detection papers are focused on establishing superior empirical detection performance and provide little theoretical background on differences but also similarities to existing methods . In this paper we want to take a different path as we believe that a solid theoretical basis is needed to make further progress in this field . Our goal is to identify , at least for a particular subclass of techniques , whether the differences are indeed due to a different underlying theoretical principle or whether they are due to the efficiency of different estimation techniques for the same underlying detection criterion , called “ scoring function ” . In some cases , we will see that one can even disentangle the estimation procedure from the scoring function , so that one can simulate several different scoring functions from one model ’ s estimated quantities . A simple approach to OOD detection is to treat it as a binary discrimination problem between inand out-of-distribution , or more generally predicting a score how likely the input is OOD . In this paper , we show that from the perspective of Bayesian decision theory , several established methods are indeed equivalent to this binary discriminator . Differences arise mainly from i ) the choice of the training out-distribution , e.g . the popular Outlier Exposure of Hendrycks et al . ( 2019a ) has advocated the use of a rich and large set of natural images as a proxy for the distribution of natural images , and ii ) differences in the estimation procedure . Concretely , the main contributions of this paper are : • We show that several OOD detection approaches are equivalent to the binary discriminator between in- and out-distribution when analyzing the rankings induced by the Bayes optimal classifier/density . • We derive the implicit scoring functions for the confidence loss ( Lee et al. , 2018a ) used by Outlier Exposure ( Hendrycks et al. , 2019a ) and for using an additional background class for the out-distribution ( Thulasidasan et al. , 2021 ) . The confidence scoring function turns out not to be equivalent to the “ optimal ” scoring function of the binary discriminator when training and test out-distributions are the same . • We show that when training the binary discriminator between in- and out-distribution together with a standard classifier on the in-distribution in a shared fashion , the binary discriminator reaches state-of-the-art OOD detection performance . • We show that density estimation is equivalent to discrimination between the in-distribution and uniform noise which explains the frequent observation that standard density estimates are not suitable for OOD detection . Even though we identify that a simple baseline is competitive with the state-of-the-art , the main aim of this paper is a better understanding of the key components of different OOD detection methods and to identify the key properties which lead to SOTA OOD detection performance . All of our findings are supported by extensive experiments on CIFAR-10 and CIFAR-100 with evaluation on various challenging out-of-distribution test datasets . 2 MODELS FOR OOD DATA AND EQUIVALENCE OF OOD DETECTION SCORES . As most work in the literature we consider OOD detection on a compact input domain X where the most important example is image classification where X = [ 0 , 1 ] D. The most popular approach to OOD detection is the construction of an in-distribution-scoring function f : X → R ∪ { ±∞ } such that f ( x ) tends to be smaller if x is drawn from an out-distribution than if it is drawn from the in-distribution . There is a variety of different performance metrics for this task , with a very common one being the area under the receiver-operator characteristic curve ( AUC ) . The AUC for a scoring function f distinguishing between an in-distribution p ( x|i ) and an out-distribution p ( x|o ) is given by AUCf ( p ( x|i ) , p ( x|o ) ) = E x∼p ( x|i ) y∼p ( y|o ) [ 1f ( x ) > f ( y ) + 1 2 1f ( x ) =f ( y ) ] . ( 1 ) We define an equivalence of scoring functions based on their AUCs and will show that this equivalence implies equality of other employed performance metrics as well . Definition 1 . Two scoring functions f and g are equivalent and we write f ∼= g if AUCf ( p ( x|i ) , p ( x|o ) ) = AUCg ( p ( x|i ) , p ( x|o ) ) ( 2 ) for all potential distributions p ( x|i ) and p ( x|o ) . As the AUC is not dependent on the actual values of f but just on the ranking induced by f one obtains the following characterization of the equivalence of two scoring functions . Theorem 1 . Two scoring functions f , g are equivalent f ∼= g if and only if there exists a strictly monotonously increasing function ϕ : range ( g ) → range ( f ) , such that f = ϕ ( g ) . Corollary 1 . The equivalence between scoring functions in Def . 1 is an equivalence relation . Another metric is the false positive rate at a fixed true positive rate q , denoted as FPR @ qTPR . A commonly used value for the TPR is 95 % . The smaller the FPR @ qTPR , the better the OOD discrimination performance . Lemma 1 . Two equivalent scoring functions f ∼= g have the same FPR @ qTPR for any pair of inand out-distributions p ( x|i ) , p ( x|o ) and for any chosen TPR q . In the next section , we use the previous results to show that the Bayes optimal scoring functions of , several proposed methods for out-of-distribution detection are equivalent to the scoring functions of simple binary discriminators . 3 BAYES-OPTIMAL BEHAVIOUR OF BINARY DISCRIMINATORS AND COMMON OOD DETECTION METHODS . In the following we will show that the Bayes optimal function of several existing approaches to OOD detection for unlabeled data are equivalent to a binary discriminator between in- and a ( training ) outdistribution whereas differences arise when one has labeled data . As the equivalences are based on the Bayes optimal solution , these are asymptotic statements and thus it has to be noted that convergence to the Bayes optimal solution can be infinitely slow and that the methods can have implicit inductive biases . This is why we additionally support our findings with extensive experiments . 3.1 OOD DETECTION FOR METHODS USING UNLABELED DATA ONLY . We first provide a formal definition of OOD detection before we show the equivalence of density estimators resp . likelihood to a binary discriminator . The OOD problem In order to make rigorous statements about the OOD detection problem we first have to provide the mathematical basis for doing so . We assume that we are given an in-distribution p ( x|i ) and potentially also a training out-distribution p ( x|o ) . At this particular point no labeled data is involved , so both of them are just distributions over X . For simplicity we assume in the following that they both have a density wrt . the Lebesgue measure on X = [ 0 , 1 ] d. We assume that in practice we get samples from the mixture distribution p ( x ) = p ( x|i ) p ( i ) + p ( x|o ) p ( o ) = p ( x|i ) p ( i ) + p ( x|o ) ( 1− p ( i ) ) ( 3 ) where p ( i ) is the probability that we expect to see in-distribution samples in total . In order to make the decision between in-and out-distribution for a given point x it is then optimal to consider p ( i|x ) = p ( x|i ) p ( i ) p ( x ) = p ( x|i ) p ( i ) p ( x|i ) p ( i ) + p ( x|o ) p ( o ) , ( 4 ) which is defined for all x ∈ [ 0 , 1 ] d with p ( x ) > 0 ( assuming p ( x|i ) and p ( x|o ) can be written as densities ) . If the training out-distribution is also the test out-distribution then this is already optimal but we would like that the approach generalizes to other unseen test out-distributions and thus an important choice is the training out-distribution p ( x|o ) . Note that as p ( i|x ) is only well-defined for all x with p ( x ) > 0 , it is thus reasonable to choose for p ( x|o ) a distribution with support in [ 0 , 1 ] d , that is p ( x|o ) > 0 for all x ∈ [ 0 , 1 ] d. In this case we ensure that the criterion with which we perform OOD detection is defined for any possible input x . This is desirable as OOD detection should work for any possible input x ∈ X . Optimal prediction of a binary discriminator between in- and out-distribution We consider a binary discriminator with model parameters θ between in- and ( training ) out-distribution , where p̂θ ( i|x ) is the predicted probability for the in-distribution . Under the assumption that p ( i ) is the probability for in-distribution samples and using cross-entropy ( which in this case is the logistic loss up to a constant global factor of log ( 2 ) ) the expected loss becomes : min θ p ( i ) E x∼p ( x|i ) [ − log p̂θ ( i|x ) ] + p ( o ) E x∼p ( x|o ) [ − log ( 1− p̂θ ( i|x ) ) ] . ( 5 ) One can derive that the Bayes optimal classifier minimizing the expected loss has the predictive distribution : p̂θ∗ ( i|x ) = p ( x|i ) p ( i ) p ( x|i ) p ( i ) + p ( x|o ) p ( o ) = p ( i|x ) . ( 6 ) Thus at least for the training out-distribution a binary classifier based on samples from in- and ( training ) out-distribution would suffice to solve the OOD detection problem perfectly . Equivalence of density estimation and binary discrimination for OOD detection In this section we further analyze the relationship of common OOD detection approaches with the binary discriminator between in-and out-distribution . We start with density estimators sourced from generative models . A basic approach that is known to yield relatively weak OOD performance ( Nalisnick et al. , 2019 ; Ren et al. , 2019 ; Xiao et al. , 2020 ) is directly utilizing a model ’ s estimate for the density p ( x|i ) at a sample input x . An improved density based approach which uses perturbed in-distribution samples as a surrogate training out-distribution is the Likelihood Ratios method ( Ren et al. , 2019 ) , which proposes to fit a generative model for both the in- and out-distribution and to use the ratio between the likelihoods output by the two models as a discriminative feature . We show that with respect to the scoring function , the correct density p ( x|i ) is equivalent to the Bayes optimal prediction of a binary discriminator between the in-distribution and uniform noise . Furthermore , the density ratio p ( x|i ) p ( x|o ) is equivalent to the prediction of a binary discriminator between the two distributions on which the respective models used for density estimation have been trained . Because of this equivalence , we argue that the use of binary discriminators is a simple alternative to these methods because of its easier training procedure . While this equivalence is an asymptotic statement , the experimental comparisons in the appendix show that the methods perform similarly poorly compared to the methods using labeled data . We first prove the more general case of arbitrary likelihood ratios . In the following we use the abbreviation λ = p ( o ) p ( i ) to save space and make the statements more concise . Lemma 2 . Assume that p ( x|i ) and p ( x|o ) can be represented by densities and the support of p ( x|o ) covers the whole input domain X . Then p ( x|i ) p ( x|o ) ∼= p ( x|i ) p ( x|i ) +λp ( x|o ) for any λ > 0 . This means that the likelihood ratio score of two optimal density estimators is equivalent to the indistribution probability p̂θ∗ ( i|x ) predicted by a binary discriminator and this is true for any possible ratio of p ( i ) to p ( o ) . In the experiments below , we show that using such a discriminator has similar performance as the likelihood ratios of the different trained generative models . For the approaches that try to directly use the likelihood of a generative model as a discriminative feature , this means that their objective is equivalent to training a binary discriminator against uniform noise , whose density is pUniform ( x ) = p ( x|o ) = 1 at any x. Lemma 3 . Assume that p ( x|i ) can be represented by a density . Then p ( x|i ) ∼= p ( x|i ) p ( x|i ) +λ for any λ > 0 . This provides additional evidence why a purely density based approach for many applications proves to be insufficient as an OOD detection score on the complex image domain : it is not reasonable to assume that a binary discriminator between certain classes of natural images on the one hand and uniform noise on the other hand provides much useful information about images from other classes or even about other nonsensical inputs .

Summary: The paper analyzes different OOD detection methods and show that even if the formulation for many OOD methods were different, the binary discrimination is equivalent to those different types of methods when the rankings induced by Bayes optimal classifier are analyzed. They also derive implicit scoring functions for confidence loss of OE and for BGC and compare them with “optimal” scoring functions. They also claim that training binary discriminator (in-dist vs out-dist) in a shared fashion along with standard classifier reaches state-of-the-art OOD performance.