Explainable Deep One-Class Classification

1 INTRODUCTION . Anomaly detection ( AD ) is the task of identifying anomalies in a corpus of data ( Edgeworth , 1887 ; Barnett and Lewis , 1994 ; Chandola et al. , 2009 ; Ruff et al. , 2021 ) . Powerful new anomaly detectors based on deep learning have made AD more effective and scalable to large , complex datasets such as high-resolution images ( Ruff et al. , 2018 ; Bergmann et al. , 2019 ) . While there exists much recent work on deep AD , there is limited work on making such techniques explainable . Explanations are needed in industrial applications to meet safety and security requirements ( Berkenkamp et al. , 2017 ; Katz et al. , 2017 ; Samek et al. , 2020 ) , avoid unfair social biases ( Gupta et al. , 2018 ) , and support human experts in decision making ( Jarrahi , 2018 ; Montavon et al. , 2018 ; Samek et al. , 2020 ) . One typically makes anomaly detection explainable by annotating pixels with an anomaly score and , in some applications , such as finding tumors in cancer detection ( Quellec et al. , 2016 ) , these annotations are the primary goal of the detector . One approach to deep AD , known as Deep Support Vector Data Description ( DSVDD ) ( Ruff et al. , 2018 ) , is based on finding a neural network that transforms data such that nominal data is concentrated to a predetermined center and anomalous data lies elsewhere . In this paper we present Fully Convolutional Data Description ( FCDD ) , a modification of DSVDD so that the transformed samples are themselves an image corresponding to a downsampled anomaly heatmap . The pixels in this heatmap that are far from the center correspond to anomalous regions in the input image . FCDD does this by only using convolutional and pooling layers , thereby limiting the receptive field of each output pixel . Our method is based on the one-class classification paradigm ( Moya et al. , 1993 ; Tax , 2001 ; Tax and Duin , 2004 ; Ruff et al. , 2018 ) , which is able to naturally incorporate known anomalies Ruff et al . ( 2021 ) , but is also effective when simply using synthetic anomalies . ∗equal contribution 1Our code is available at : https : //github.com/liznerski/fcdd We show that FCDD ’ s anomaly detection performance is close to the state of the art on the standard AD benchmarks with CIFAR-10 and ImageNet while providing transparent explanations . On MVTecAD , an AD dataset containing ground-truth anomaly maps , we demonstrate the accuracy of FCDD ’ s explanations ( see Figure 1 ) , where FCDD sets a new state of the art . In further experiments we find that deep one-class classification models ( e.g . DSVDD ) are prone to the “ Clever Hans ” effect ( Lapuschkin et al. , 2019 ) where a detector fixates on spurious features such as image watermarks . In general , we find that the generated anomaly heatmaps are less noisy and provide more structure than the baselines , including gradient-based methods ( Simonyan et al. , 2013 ; Sundararajan et al. , 2017 ) and autoencoders ( Sakurada and Yairi , 2014 ; Bergmann et al. , 2019 ) . 2 RELATED WORK . Here we outline related works on deep AD focusing on explanation approaches . Classically deep AD used autoencoders ( Hawkins et al. , 2002 ; Sakurada and Yairi , 2014 ; Zhou and Paffenroth , 2017 ; Zhao et al. , 2017 ) . Trained on a nominal dataset autoencoders are assumed to reconstruct anomalous samples poorly . Thus , the reconstruction error can be used as an anomaly score and the pixel-wise difference as an explanation ( Bergmann et al. , 2019 ) , thereby naturally providing an anomaly heatmap . Recent works have incorporated attention into reconstruction models that can be used as explanations ( Venkataramanan et al. , 2019 ; Liu et al. , 2020 ) . In the domain of videos , Sabokrou et al . ( 2018 ) used a pre-trained fully convolutional architecture in combination with a sparse autoencoder to extract 2D features and provide bounding boxes for anomaly localization . One drawback of reconstruction methods is that they offer no natural way to incorporate known anomalies during training . More recently , one-class classification methods for deep AD have been proposed . These methods attempt to separate nominal samples from anomalies in an unsupervised manner by concentrating nominal data in feature space while mapping anomalies to distant locations ( Ruff et al. , 2018 ; Chalapathy et al. , 2018 ; Goyal et al. , 2020 ) . In the domain of NLP , DSVDD has been successfully applied to text , which yields a form of interpretation using attention mechanisms ( Ruff et al. , 2019 ) . For images , Kauffmann et al . ( 2020 ) have used a deep Taylor decomposition ( Montavon et al. , 2017 ) to derive relevance scores . Some of the best performing deep AD methods are based on self-supervision . These methods transform nominal samples , train a network to predict which transformation was used on the input , and provide an anomaly score via the confidence of the prediction ( Golan and El-Yaniv , 2018 ; Hendrycks et al. , 2019b ) . Hendrycks et al . ( 2019a ) have extended this to incorporate known anomalies as well . No explanation approaches have been considered for these methods so far . Finally , there exists a great variety of explanation methods in general , for example model-agnostic methods ( e.g . LIME ( Ribeiro et al. , 2016 ) ) or gradient-based techniques ( Simonyan et al. , 2013 ; Sundararajan et al. , 2017 ) . Relating to our work , we note that fully convolutional architectures have been used for supervised segmentation tasks where target segmentation maps are required during training ( Long et al. , 2015 ; Noh et al. , 2015 ) . 3 EXPLAINING DEEP ONE-CLASS CLASSIFICATION . We review one-class classification and fully convolutional architectures before presenting our method . Deep One-Class Classification Deep one-class classification ( Ruff et al. , 2018 ; 2020b ) performs anomaly detection by learning a neural network to map nominal samples near a center c in output space , causing anomalies to be mapped away . For our method we use a Hypersphere Classifier ( HSC ) ( Ruff et al. , 2020a ) , a recently proposed modification of Deep SAD ( Ruff et al. , 2020b ) , a semi-supervised version of DSVDD ( Ruff et al. , 2018 ) . Let X1 , . . . , Xn denote a collection of samples and y1 , . . . , yn be labels where yi = 1 denotes an anomaly and yi = 0 denotes a nominal sample . Then the HSC objective is min W , c 1 n n∑ i=1 ( 1− yi ) h ( φ ( Xi ; W ) − c ) − yi log ( 1− exp ( −h ( φ ( Xi ; W ) − c ) ) ) , ( 1 ) where c ∈ Rd is the center , and φ : Rc×h×w → Rd a neural network with weightsW . Here h is the pseudo-Huber loss ( Huber et al. , 1964 ) , h ( a ) = √ ‖a‖22 + 1 − 1 , which is a robust loss that interpolates from quadratic to linear penalization . The HSC loss encourages φ to map nominal samples near c and anomalous samples away from the center c. In our implementation , the center c corresponds to the bias term in the last layer of our networks , i.e . is included in the network φ , which is why we omit c in the FCDD objective below . Fully Convolutional Architecture Our method uses a fully convolutional network ( FCN ) ( Long et al. , 2015 ; Noh et al. , 2015 ) that maps an image to a matrix of features , i.e . φ : Rc×h×w → R1×u×v by using alternating convolutional and pooling layers only , and does not contain any fully connected layers . In this context , pooling can be seen as a special kind of convolution with fixed parameters . A core property of a convolutional layer is that each pixel of its output only depends on a small region of its input , known as the output pixel ’ s receptive field . Since the output of a convolution is produced by moving a filter over the input image , each output pixel has the same relative position as its associated receptive field in the input . For instance , the lower-left corner of the output representation has a corresponding receptive field in the lower-left corner of the input image , etc . ( see Figure 2 left side ) . The outcome of several stacked convolutions also has receptive fields of limited size and consistent relative position , though their size grows with the amount of layers . Because of this an FCN preserves spatial information . Fully Convolutional Data Description Here we introduce our novel explainable AD method Fully Convolutional Data Description ( FCDD ) . By taking advantage of FCNs along with the HSC above , we propose a deep one-class method where the output features preserve spatial information and also serve as a downsampled anomaly heatmap . For situations where one would like to have a full-resolution heatmap , we include a methodology for upsampling the low-resolution heatmap based on properties of receptive fields . FCDD is trained using samples that are labeled as nominal or anomalous . As before , let X1 , . . . , Xn denote a collection of samples with labels y1 , . . . , yn where yi = 1 denotes an anomaly and yi = 0 denotes a nominal sample . Anomalous samples can simply be a collection of random images which are not from the nominal collection , e.g . one of the many large collections of images which are freely available like 80 Million Tiny Images ( Torralba et al. , 2008 ) or ImageNet ( Deng et al. , 2009 ) . The use of such an auxiliary corpus has been recommended in recent works on deep AD , where it is termed Outlier Exposure ( OE ) ( Hendrycks et al. , 2019a ; b ) . When one has access to “ true ” examples of the anomalous dataset , i.e . something that is likely to be representative of what will be seen at test time , we find that even using a few examples as the corpus of labeled anomalies performs exceptionally well . Furthermore , in the absence of any sort of known anomalies , one can generate synthetic anomalies , which we find is also very effective . With an FCN φ : Rc×h×w → Ru×v the FCDD objective utilizes a pseudo-Huber loss on the FCN output matrix A ( X ) = ( √ φ ( X ; W ) 2 + 1− 1 ) , where all operations are applied element-wise . The FCDD objective is then defined as ( cf. , ( 1 ) ) : min W 1 n n∑ i=1 ( 1− yi ) 1 u · v ‖A ( Xi ) ‖1 − yi log ( 1− exp ( − 1 u · v ‖A ( Xi ) ‖1 ) ) . ( 2 ) Here ‖A ( X ) ‖1 is the sum of all entries in A ( X ) , which are all positive . FCDD is the utilization of an FCN in conjunction with the novel adaptation of the HSC loss we propose in ( 2 ) . The objective maximizes ‖A ( X ) ‖1 for anomalies and minimizes it for nominal samples , thus we use ‖A ( X ) ‖1 as the anomaly score . Entries of A ( X ) that contribute to ‖A ( X ) ‖1 correspond to regions of the input image that add to the anomaly score . The shape of these regions depends on the receptive field of the FCN . We include a sensitivity analysis on the size of the receptive field in Appendix A , where we find that performance is not strongly affected by the receptive field size . Note that A ( X ) has spatial dimensions u × v and is smaller than the original image dimensions h × w. One could use A ( X ) directly as a low-resolution heatmap of the image , however it is often desirable to have full-resolution heatmaps . Because we generally lack ground-truth anomaly maps in an AD setting during training , it is not possible to train an FCN in a supervised way to upsample the low-resolution heatmap A ( X ) ( e.g . as in ( Noh et al. , 2015 ) ) . For this reason we introduce an upsampling scheme based on the properties of receptive fields . Algorithm 1 Receptive Field Upsampling Input : A ∈ Ru×v ( low-res anomaly heatmap ) Output : A′ ∈ Rh×w ( full-res anomaly heatmap ) Define : [ G2 ( µ , σ ) ] x , y , 12πσ2 exp ( − ( x−µ1 ) 2+ ( y−µ2 ) 2 2σ2 ) A′ ← 0 for all output pixels a in A do f ← receptive field of a c← center of field f A′ ← A′ + a ·G2 ( c , σ ) end for return A′ Heatmap Upsampling Since we generally do not have access to ground-truth pixel annotations in anomaly detection during training , we can not learn how to upsample using a deconvolutional type of structure . We derive a principled way to upsample our lower resolution anomaly heatmap instead . For every output pixel in A ( X ) there is a unique input pixel which lies at the center of its receptive field . It has been observed before that the effect of the receptive field for an output pixel decays in a Gaussian manner as one moves away from the center of the receptive field ( Luo et al. , 2016 ) . We use this fact to upsample A ( X ) by using a strided transposed convolution with a fixed Gaussian kernel ( see Figure 2 right side ) . We describe this operation and procedure in Algorithm 1 which simply corresponds to a strided transposed convolution . The kernel size is set to the receptive field range of FCDD and the stride to the cumulative stride of FCDD . The variance of the distribution can be picked empirically ( see Appendix B for details ) . Figure 3 shows a complete overview of our FCDD method and the process of generating full-resolution anomaly heatmaps .

Summary: This paper presents a one-class classification method using a fully convolutional model and directly using the output map as an explanation map. The method is dubbed FCDD for fully convolutional data descriptor. FCDD uses a hypersphere classifier combined with a pseudo-Huber loss. FCDD is trained using outliers exposure (OE) from a different but related dataset. The empirical study consists of 3 parts: