A Statistical Framework for Efficient Out of Distribution Detection in Deep Neural Networks

1 INTRODUCTION . Deep Neural Networks ’ ( DNNs ) predictions were shown to be overconfident and unreliable when the test samples are drawn from an unexpected distribution ( e.g. , Biggio et al . ( 2013 ) ; Szegedy et al . ( 2013 ) ; Goodfellow et al . ( 2014 ) ; Eykholt et al . ( 2017 ) ) . Therefore , numerous Out Of Distribution ( OOD ) detection methods were suggested to address this issue by informing an operator when not to trust the DNN ’ s prediction . In the context of DNNs , methods for OOD detection can be roughly divided into two classes . `` Mutators '' methods modify the network structure or loss , and depend on training its parameters to provide a confidence measure ( Hendrycks et al. , 2018 ; Malinin and Gales , 2018 ; Winkens et al. , 2020 ; Zhang et al. , 2020 ; Hsu et al. , 2020 ) . `` Observer '' methods model the prediction uncertainty of a pre-trained network , without modifying its architecture or parameters ( Hendrycks and Gimpel , 2016 ; Liang et al. , 2017 ; Lee et al. , 2018 ; Zisselman and Tamar , 2020 ; Raghuram et al. , 2020 ) . Mutators are potentially costly , as they require substituting or retraining the network and subsequently repeating an exhaustive hyperparameter tuning process . Also , the resulting model quality on the original task may vary . Alternatively , observer methods commonly utilize auxiliary models to monitor features produced by the reference network . Since this approach is decoupled from the network optimization process , the reference accuracy is retained at the cost of additional test time resources , such as compute and memory . Another differentiating factor between methods , regardless of their class , stems from fundamental assumptions regarding prior knowledge on the test distribution . Specifically , some methods ( e.g. , Hendrycks et al . ( 2018 ) ; Lee et al . ( 2018 ) ; Zisselman and Tamar ( 2020 ) ) rely on prior knowledge , such as access to the OOD data or its proxy . However , this prior can lead to undesirable bias and poor detection performance on other test distributions . Notably , OOD detection can be naturally cast as a statistical hypothesis testing problem ( Grubbs , 1969 ; Vovk et al. , 2005 ; Papadopoulos , 2008 ; Grosse et al. , 2017 ) . Nevertheless , authors of contemporary observer methods largely overlook the statistical aspects of their proposed algorithms . For example , they do not provide meaningful error guarantees nor explicitly define what hypothesis is being tested . For further details regarding related work , see Section 5 . In addition , these methods also tend to be computationally expensive ( see Section 4.4 ) . In this work , we aim to tackle these issues . Contributions . We first propose methodological innovations • We present a novel framework for OOD detection in DNNs , based on statistical hypothesis testing and phrase two relevant null hypotheses . The first is whether a sample is drawn from the same distribution of the classes in the training dataset ( any-class ) . The second is whether a sample is drawn from the distribution corresponding to the predicted class ( class-conditional ) . We construct valid tests for both hypotheses and further provide empirical evidence for these theoretical results ( Section 3 ) . • Our framework can be viewed as an extension of the inductive conformal predictor framework ( Papadopoulos , 2008 ) , which is a non-parametric method for conducting hypothesis testing with an arbitrary test statistic ( Vovk et al. , 2005 ) . However , instead of focusing solely on the last layer of the DNN predictor , we show how to normalize and aggregate multiple non-conformity ( i.e. , abnormality ) measures based on the entire network . Empirically , we demonstrate that this generalization is crucial for OOD detection . Namely , we find that a multi-layer detector improves accuracy by 50 % on average compared to single-layer variants ( Section 4.2 ) . These innovations lead to considerable practical advantages • Importantly , unlike current methods for OOD detection in DNNs , our framework returns a valid p-value for each tested sample . This guarantees maintaining a Type I Error ( detecting OOD as in-distribution ) on test data ( see Section 3.2 , Propositions 1 and 2 ) , and has additional advantages1 which do not exist in standard threshold-based OOD classification . • Based on this framework , we design a detection scheme denoted as MaSF ( Max-Simes-Fisher , Section 4.2 ) . MaSF achieves similar or better results compared to SOTA on the benchmark proposed by Lee et al . ( 2018 ) , while in our experiments , we show its test statistic inference is 35 times faster . Making MaSF appealing for real-world applications with a limited compute budget ( Section 4.4 ) . • We demonstrate potential avenues to further reduce the computational overhead via structured sparsity ( i.e. , channel sampling ) — further reducing the computational cost by a factor of 10 while degrading accuracy by no more than ∼ 1 % ( Section 4.5 ) . 2 BACKGROUND . In the following section , we provide a summary of Null Hypothesis Statistical Testing ( NHST ) . We begin with a single hypothesis and then further expand on Global-Null tests . Null Hypothesis Statistical Testing . NHST is the process of choosing between two hypotheses - H0 ( null ) and H1 ( alternative ) regarding observation ( sample ) X . It is formalized as H0 : X ∼ P vs H1 : X ̸∼ P , where P is some distribution . The decision to reject H0 is based on the critical value γ and the test statistic T ( X ) . Throughout this section , we will focus on right-tailed tests . We call a test right-tailed when higher values of T ( X ) are more likely under H1 than under H0 . In those kinds of tests , H0 is rejected if T ( X ) ≥ γ . The critical value γ quantifies the required evidence to determine if H0 is false . Erroneously rejecting H0 , is called a Type I Error ( T1E ) . The significance level ( i.e. , probability of T1E ) is given by α = PH0 ( T ( X ) ≥ γ ) . Usually , α is predetermined , and γ is found accordingly . For a given significance level , the goal is to maximize the power of the test , PH1 ( T ( X ) ≥ γ ) , which is the probability of correctly rejecting H0 . Commonly , a p-value is used to summarize NHST . The p-value indicates the probability of obtaining a test statistic equal or more extreme than the observed test statistic , given that H0 is true . The p-value ( denoted by q ) is given by , q ( tobs ) = PH0 ( T ( X ) ≥ tobs ) , where tobs is the observed value of the test statistic . Assuming the null is correct , and that P is continuous , then the p-values are uniformly distributed ( Abramovich and Ritov , 2013 ) . This allows to simply reject the null if q ( tobs ) ≤ α . It is clear that 1For example , p-values enable adjusting the decision rule when more than one hypothesis is tested at a time while maintaining a certain error criterion ( Chapter 2 in Bretz et al . ( 2016 ) ) . For instance , one can potentially employ several OOD detectors on a single sample ( e.g. , each specialized on a specific type of outlier distribution ) . the significance level will be maintained if the p-value distribution is stochastically larger2 than or equal to the uniform distribution3 . Global Null Tests . Given a set of hypotheses , combination tests are used to determine if any hypothesis is false ( global null ) . Let q denote a vector of m p-values , q = ( q1 , . . . , qm ) , that is used to test the m null-hypotheses , H0,1 , . . . , H0 , m . The global null hypothesis is defined as H0 , . = ⋂m i=1 H0 , i . The test statistic is T ( q ) . The test power depends on the unknown distribution of the test statistic under H1 . Two ubiquitous tests of the global-null are the Fisher and Simes tests ( Fisher , 1992 ; Simes , 1986 ) .The Fisher test statistic is −2 ∑m i=1 log ( qi ) . It is suitable for detecting dense signals due to the summation of p-values . The Simes test statistic is min i∈ { 1 , ... , m } q ( i ) m i , where ( i ) is the index of the p-values after sorting . It is adept for detection of a sparse signal , as it focus on a single p-value . These complementing attributes are appealing for OOD detection , as we will demonstrate in the following sections . For a more detailed introduction of these tests see Section B.3 . An important benefit of using p-values is that they allow maintaining a meaningful error rate . There are many methods employed to maintain such error rates , which are applied on p-values ( Holm , 1979 ; Hochberg , 1988 ; Benjamini and Hochberg , 1995 ) . 3 HYPOTHESIS TESTING IN NEURAL NETWORKS . For the sake of simplicity , we focus the next section solely on convolutional neural networks ( CNNs ) for image classification tasks . The method presented , however , is applicable to any DNN . 3.1 PRELIMINARIES . Define [ k ] = { i ∈ N : i ≤ k } and let χc = { ( Xi , yi ) : i ∈ [ nc ] , yi = c } , where |χc| = nc , Xi is an image and yi , ŷi are its true and predicted class ( out of k classes ) . We further split the observations of each class to the CNN training set χctrain , and the validation set χ c val The training set is denoted by χtrain = ⋃k c=1 χ c train , and its cardinality is Ntrain = ∑k c=1 nc . We similarly define χval and Nval . Pc is the class distribution of Xi where yi = c , c ∈ [ k ] . The distribution of any test statistic under H0 is required to obtain p-values . For that reason we apply the empirical cumulative distribution function ( eCDF ) to estimate the null distribution of class c , function T at x using an observations set χc ∈ { χctrain , χcval } , P̂ ( x ; T , χc ) = ∑ ( Xi , yi ) ∈χc I ( T ( Xi ) ≤ x ) + 1 nc + 1 , ( 1 ) where I is the indicator function . The addition of 1 is necessary to ensure that the p-values are not equal to 0 , as it implies they are rejected at all significance levels . The problem of determining if an image Xtest is OOD , can be formalized as H∗0 : ∃c : Xtest ∼ Pc , H∗1 : Xtest ̸∼ Pc ∀c ∈ [ k ] ( 2 ) By rejecting H∗0 , we conclude that the image is not drawn from any of the class distributions . One can also test if an image is sampled from a specific class distribution , Hc0 : Xtest ∼ Pc , Hc1 : Xtest ̸∼ Pc . ( 3 ) Since the true label is unknown at test time , we are interested in the case where the class is assigned according to the CNN prediction , Hŷtest0 . Therefore , rejecting it indicates the image is either misclassified or OOD .

Summary: The authors formalize the out-of-distribution (OOD) detection problem in the framework of statistical hypothesis testing. The proposed method, called Max-Simes-Fisher (MaSF), is designed for deep neural networks and combines sample features extracted from multiple layers in the network. The method returns a $p$-value for every test sample at a specified significance level (_i.e._, probability of incorrectly predicting "OOD" for an actual in-distribution sample). Compared with existing methods for OOD detection, the proposed method achieves similar or better True Positive Rates (TPR, _i.e._, correct OOD prediction rate) with significantly lower computation cost.