Practical Evaluation of Out-of-Distribution Detection Methods for Image Classification

We reconsider the evaluation of OOD detection methods for image recognition . Although many studies have been conducted so far to build better OOD detection methods , most of them follow Hendrycks and Gimpel ’ s work for the method of experimental evaluation . While the unified evaluation method is necessary for a fair comparison , there is a question of if its choice of tasks and datasets reflect real-world applications and if the evaluation results can generalize to other OOD detection application scenarios . In this paper , we experimentally evaluate the performance of representative OOD detection methods for three scenarios , i.e. , irrelevant input detection , novel class detection , and domain shift detection , on various datasets and classification tasks . The results show that differences in scenarios and datasets alter the relative performance among the methods . Our results can also be used as a guide for practitioners for the selection of OOD detection methods . 1 INTRODUCTION . Despite their high performance on various visual recognition tasks , convolutional neural networks ( CNNs ) often show unpredictable behaviors against out-of-distribution ( OOD ) inputs , i.e. , those sampled from a different distribution from the training data . For instance , CNNs often classify irrelevant images to one of the known classes with high confidence . A visual recognition system should desirably be equipped with an ability to detect such OOD inputs upon its real-world deployment . There are many studies of OOD detection that are based on diverse motivations and purposes . However , as far as the recent studies targeted at visual recognition are concerned , most of them follow the work of Hendrycks & Gimpel ( 2017 ) , which provides a formal problem statement of OOD detection and an experimental procedure to evaluate the performance of methods . Employing this procedure , the recent studies focus mainly on increasing detection accuracy , where the performance is measured using the same datasets . On the one hand , the employment of the experimental procedure has arguably bought about the rapid progress of research in a short period . On the other hand , little attention has been paid to how well the employed procedure models real-world problems and applications . They are diverse in purposes and domains , which obviously can not be covered by the single problem setting with a narrow range of datasets . In this study , to address this issue , we consider multiple , more realistic scenarios of the application of OOD detection , and then experimentally compare the representative methods . To be specific , we consider the three scenarios : detection of irrelevant inputs , detection of novel class inputs , and detection of domain shift . The first two scenarios differ in the closeness between ID samples and OOD samples . Unlike the first two , domain shift detection is not precisely OOD detection . Nonetheless , it is the same as the other two in that what we want is to judge if the model can make a meaningful inference for a novel input . In other words , we can generalize OOD detection to the problem of judging this . Then , the above three scenarios are naturally fallen into the same group of problems , and it becomes natural to consider applying OOD detection methods to the third scenario . It is noteworthy that domain shift detection has been poorly studied in the community . Despite many demands from practitioners , there is no established method in the context of deep learning for image classification . Based on the above generalization of OOD detection , we propose a meta-approach in which any OOD detection method can be used as its component . For each of these three scenarios , we compare the following methods : the confidence-based baseline ( Hendrycks & Gimpel , 2017 ) , MC dropout ( Gal & Ghahramani , 2016 ) , ODIN ( Liang et al. , 2017 ) , cosine similarity ( Techapanurak et al. , 2019 ; Hsu et al. , 2020 ) , and the Mahalanobis detector ( Lee et al. , 2018 ) . Domain shift detection is studied in ( Elsahar & Gallé , 2019 ) with natural language processing tasks , where proxy-A distance ( PAD ) is reported to perform the best ; thus we test it in our experiments . As for choosing the compared methods , we follow the argument shared by many recent studies ( Shafaei et al. , 2019 ; Techapanurak et al. , 2019 ; Yu & Aizawa , 2019 ; Yu et al. , 2020 ; Hsu et al. , 2020 ) that OOD detection methods should not assume the availability of explicit OOD samples at training time . Although this may sound obvious considering the nature of OOD , some of the recent methods ( e.g. , Liang et al . ( 2017 ) ; Lee et al . ( 2018 ) ) use a certain amount of OOD samples as validation data to determine their hyperparameters . The recent studies , ( Shafaei et al. , 2019 ; Techapanurak et al. , 2019 ) , show that these methods do perform poorly when encountering OOD inputs sampled from a different distribution from the assumed one at test time . Thus , for ODIN and the Mahalanobis detector , we employ their variants ( Hsu et al. , 2020 ; Lee et al. , 2018 ) that can work without OOD samples . The other compared methods do not need OOD samples . The contribution of this study are summarized as follows . i ) Listing three problems that practitioners frequently encounter , we evaluate the existing OOD detection methods on each of them . ii ) We show a practical approach to domain shift detection that is applicable to CNNs for image classification . iii ) We show experimental evaluation of representative OOD detection methods on these problems , revealing each method ’ s effectiveness and ineffectiveness in each scenario . 2 PROBLEMS AND METHODS . 2.1 PRACTICAL SCENARIOS OF OOD DETECTION . We consider image recognition tasks in which a CNN classifies a single image x into one of C known classes . The CNN is trained using pairs of x and its label , and x is sampled according to x ∼ p ( x ) . At test time , it will encounter an unseen input x , which is usually from p ( x ) but is sometimes from p′ ( x ) , a different , unknown distribution . In this study , we consider the following three scenarios . Detecting Irrelevant Inputs The new input x does not belong to any of the known classes and is out of concern . Suppose we want to build a smartphone app that recognizes dog breeds . We train a CNN on a dataset containing various dog images , enabling it to perform the task with reasonable accuracy . We then point the smartphone to a sofa and shoot its image , feeding it to our classifier . It could classify the image as a Bull Terrier with high confidence . Naturally , we want to avoid this by detecting the irrelevance of x . Most studies of OOD detection assumes this scenario for evaluation . Detecting Novel Classes The input x belongs to a novel class , which differs from any of C known classes , and furthermore , we want our CNN to learn to classify it later , e.g. , after additional training . For instance , suppose we are building a system that recognizes insects in the wild , with an ambition to make it cover all the insects on the earth . Further , suppose an image of one of the endangered ( and thus rare ) insects is inputted to the system while operating it . If we can detect it as a novel class , we would be able to update the system in several ways . The problem is the same as the first scenario in that we want to detect whether x ∼ p ( x ) or not . The difference is that x is more similar to samples of the learned classes , or equivalently , p′ ( x ) is more close to p ( x ) , arguably making the detection more difficult . Note that in this study , we don ’ t consider distinguishing whether x is an irrelevant input or a novel class input , for the sake of simplicity . We left it for a future study . Detecting Domain Shift The input x belongs to one of C known classes , but its underlying distribution is p′ ( x ) , not p ( x ) . We are especially interested in the case where a distributional shift p ( x ) → p′ ( x ) occurs either suddenly or gradually while running a system for the long term . Our CNN may or may not generalize beyond this shift to p′ ( x ) . Thus , we want to detect if it does not . If we can do this , we would take some actions , such as re-training the network with new training data ( Elsahar & Gallé , 2019 ) . We consider the case where no information is available other than the incoming inputs x′s . A good example is a surveillance system using a camera deployed outdoor . Let us assume the images ’ quality deteriorates after some time since its deployment , for instance , due to the camera ’ s aging . Then , the latest images will follow a different distribution from that of the training data . Unlike the above two cases where we have to decide for a single input , we can use multiple inputs ; we should , especially when the quality of input images deteriorate gradually as time goes . The problem here has three differences from the above two scenarios . First , the input is a valid sample belonging to a known class , neither an irrelevant sample nor a novel class sample . Second , we are basically interested in the accuracy of our CNN with the latest input ( s ) and not in whether x ∼ p ( x ) or p′ ( x ) . Third , as mentioned above , we can use multiple inputs { xi } i=1 , ... , n for the judgment . Additional remarks on this scenario . Assuming a temporal sequence of inputs , the distributional shift is also called concept drift ( Gama et al. , 2014 ) . It includes several different subproblems , and the one considered here is called virtual concept drift in its terminology . Mathematically , concept drift occurs when p ( x , y ) changes with time . It is called virtual when p ( x ) changes while p ( y|x ) does not change . Intuitively , this is the case where the classes ( i.e. , concept ) remain the same but p ( x ) changes , demanding the classifier to deal with inputs drawn from p′ ( x ) . Then , we are usually interested in predicting if x lies in a region of the data space for which our classifier is well trained and can correctly classify it . If not , we might want to retrain our classifier using additional data or invoke unsupervised domain adaptation methods ( Ganin & Lempitsky , 2015 ; Tzeng et al. , 2017 ) . 2.2 COMPARED METHODS . We select five representative OOD detection methods that do not use real OOD samples to be encountered at test time . Baseline : Max-softmax Hendrycks & Gimpel ( 2017 ) showed that the maximum of the softmax outputs , or confidence , can be used to detect OOD inputs . We use it as the score of an input being in-distribution ( ID ) . We will refer to this method as Baseline . It is well known that the confidence can be calibrated using temperature to better represent classification accuracy ( Guo et al. , 2017 ; Li & Hoiem , 2020 ) . We also evaluate this calibrated confidence , which will be referred to as Calib . MC Dropout The confidence ( i.e. , the max-softmax ) is also thought of as a measure of uncertainty of prediction , but it captures only aleatoric uncertainty ( Hüllermeier & Waegeman , 2019 ) . Bayesian neural networks ( BNNs ) can also take epistemic uncertainty into account , which is theoretically more relevant to OOD detection . MC ( Monte-Carlo ) dropout ( Gal & Ghahramani , 2016 ) is an approximation of BNNs that is computationally more efficient than an ensemble of networks ( Lakshminarayanan et al. , 2017 ) . To be specific , using dropout ( Srivastava et al. , 2014 ) at test time provides multiple prediction samples , from which the average of their max-softmax values is calculated and used as ID score . Cosine Similarity It is recently shown in Techapanurak et al . ( 2019 ) ; Hsu et al . ( 2020 ) that using scaled cosine similarities at the last layer of a CNN , similar to the angular softmax for metric learning , enables accurate OOD detection . To be specific , the method first computes cosine similarities between the feature vector of the final layer and class centers ( or equivalently , normalized weight vectors for classes ) . They are multiplied with a scale and then normalized by softmax to obtain class scores . The scale , which is the inverse temperature , is predicted from the same feature vector . These computations are performed by a single layer replacing the last layer of a standard CNN . The maximum of the cosine similarities ( without the scale ) gives ID score . The method is free of hyperparameters for OOD detection . We will refer to it as Cosine . ODIN ( with OOD-sample Free Extension ) ODIN was proposed by Liang et al . ( 2017 ) to improve Baseline by perturbing an input x→ x+ · sgn ( δx ) in the direction δx of maximally increasing the max-softmax and also by temperature scaling . Thus , there are two hyperparameters , the perturbation size and the temperature T . In Liang et al . ( 2017 ) , they are chosen by assuming the availability of explicit OOD samples . Recently , Hsu et al . ( 2020 ) proposed to select ← argmax ∑ yκ ( x + · sgn ( δx ) ) , where yκ is the max-softmax and the summation is taken over ID samples in the validation set . As for the temperature , they set T = 1000 . ID score is given by yκ ( x+ · sgn ( δx ) ) . To distinguish from the original ODIN , we refer to this as ODIN∗ . Mahalanobis Detector The above three methods are based on the confidence . Another approach is to formulate the problem as unsupervised anomaly detection . Lee et al . ( 2018 ) proposed to model the distribution of intermediate layer ’ s activation by a Gaussian distribution for each class but with a shared covariance matrix among the classes . Given an input , the Mahalanobis distance concerning the predicted class is calculated at each layer . A score for OOD is given by the weighted sum of those calculated at different layers . The weights are predicted by logistic regression , which is determined by assuming the availability of OOD samples . To be free from the assumption , another method is suggested that generates adversarial examples from ID samples and regard them as OOD samples . It is also reported in ( Hsu et al. , 2020 ) that setting all the weights to one works reasonably well . We evaluate the last two methods that do not need OOD samples . Although the original method optionally uses input perturbation similar to ODIN , we do not use it because our experiments show that its improvement is very small despite its high computational cost . Effects of Fine-tuning a Pre-trained Network It has been well known that fine-tuning a pretrained network on a downstream task improves its prediction accuracy , especially when a small amount of training data is available . It was pointed out in ( He et al. , 2019 ) that the improvement is little when there is sufficient training data . Hendrycks et al . ( 2019 ) then show that even in that case , using a pre-trained network helps increase the overall robustness of the inference . It includes improved OOD detection performance , in addition to robustness to adversarial attacks , better calibration of confidence , robustness to covariate shift . However , their experimental validation is performed only on a single configuration with a few datasets . It remains unclear if the improvement can generalize to a broader range of purposes and settings that may differ in image size , the number of training samples , and ID/OOD combinations .

Summary: The paper empirically analyzes the evaluation framework of the current OOD detection systems for the image recognition task, specifically the evaluation described in [1] using Max-softmax and calibrated confidence. They motivate the paper by the necessity of having better evaluation for OOD detection to be reflective of real world scenarios. The addressed problem is interesting and valuable for the field as many of the defined OOD datasets, and evaluation metrics may not cover many real-world scenarios. They specifically addressed three scenarios, inputs that i) are irrelevant to the task ii) are from novel classes and iii) are from another domain (domain shift), which for the first 2 scenarios, they only evaluate them as unseen classes and not distinguish between them. Based on my understanding of the paper, they compare 5 OOD detection methods from the literature, suggest a few test datasets/scenarios and conclude using cosine similarity is consistently favorable for evaluation, and the choice of using confidence-based methods in case of domain shift detection scenarios.