U NDERSTANDING CLASSIFIER MISTAKES WITH GENERATIVE MODELS
Anonymous authors
Paper under double-blind review
A BSTRACT
Although deep neural networks are effective on supervised learning tasks, they have been shown to be brittle.
They are prone to overﬁtting on their training distribution and are easily fooled by small adversarial perturbations.
In this paper, we leverage generative models to identify and characterize instances where classiﬁers fail to generalize.
We propose a generative model of the features extracted by a classiﬁer, and show using rigorous hypothesis testing that errors tend to occur when features are assigned low-probability by our model.
From this observation, we develop a detection criteria for samples on which a classiﬁer is likely to fail at test time. In particular, we test against three different sources of classiﬁcation failures: mistakes made on the test set due to poor model generalization, adversarial samples and out-of-distribution samples.
Our approach is agnostic to class labels from the training set which makes it applicable to models trained in a semisupervised way.
I NTRODUCTION
Machine learning algorithms have shown remarkable success in challenging supervised learning tasks such as object classiﬁcation (He et al., 2016) and speech recognition (Graves et al., 2013).
Deep neural networks in particular, have gained traction because of their ability to learn a hierarchical feature representation of their inputs.
Neural networks, however, are also known to be brittle.
As they require a large number of parameters compared to available data, deep neural networks have a tendency to latch onto spurious statistical dependencies to make their predictions.
As a result, they are prone to overﬁtting and can be fooled by imperceptible adversarial perturbations of their inputs (Szegedy et al., 2013; Kurakin et al., 2016; Madry et al., 2017).
Additionally, modern neural networks are poorly calibrated and do not capture model uncertainty well (Gal & Ghahramani, 2016; Kuleshov & Ermon, 2017; Guo et al., 2017).
They produce conﬁdence scores that do not represent true probabilities and consequently, often output predictions that are over-conﬁdent even when fed with out-of-distribution inputs (Liang et al., 2017).
These limitations of neural networks are problematic as they become ubiquitous in applications where safety and reliability is a priority (Levinson et al., 2011; Sun et al., 2015).
Fully probabilistic, generative models could mitigate these issues by improving uncertainty quantiﬁcation and incorporating prior knowledge (e.g, physical properties (Wu et al., 2015)) into the classiﬁcation process.
While great progress has been made towards designing generative models that can capture high-dimensional objects such as images (Oord et al., 2016a; Salimans et al., 2017), accurate probabilistic modeling of complex, high-dimensional data remains challenging.
Our work aims at providing an understanding of these failure modes under the lens of probabilistic modelling.
Instead of directly modeling the inputs, we rely on the ability of neural networks to extract features from high-dimensional data and build a generative model of these low-dimensional features.
Because deep neural networks are trained to extract features from which they output classiﬁcation predictions, we make the assumption that it is possible to detect failure cases from the learned representations.
Given a neural network trained for image classiﬁcation, we capture the distribution of the learned feature space with a Gaussian Mixture Model (GMM) and use the predicted likelihoods to detect inputs on which the model cannot produce reliable classiﬁcation results.
We show that we are able to not only detect adversarial and out-of-distribution samples, but surprisingly also identify inputs from the test set on which a model is likely to make a mistake .
We experiment on state-of-the-art neural networks trained on CIFAR-10 and CIFAR-100 (Krizhevsky, 2009) and show, through statistical hypothesis testing, that samples leading to classiﬁcation failures tend to correspond to features that lie in a low probability region of the feature space.
Contributions Our contributions are as follows:
• We provide a probabilistic explanation to the brittleness of deep neural networks and show that classiﬁers tend to make mistakes on inputs with low-probability features.
• We demonstrate that a simple modeling by a GMM of the feature space learned by a deep neural network is enough to model the probability space.
Other state-of-the-art methods for probabilistic modelling such as VAEs (Kingma & Welling, 2013) and auto-regressive ﬂow models (Papamakarios et al., 2017) fail in that regard.
• We show that generative models trained on the feature space can be used as a single tool to reliably detect different sources of classiﬁcation failures: test set errors due to poor generalization, adversarial samples and out-of-distribution samples.
R ELATED W ORK
An extensive body of work has been focused on understanding the behaviours of deep neural networks when they are faced with inputs on which they fail.
We provide a brief overview below:
Uncertainty quantiﬁcation Uncertainty quantiﬁcation for neural networks is crucial in order to detect when a model’s prediction cannot be trusted.
Bayesian approaches (MacKay, 1992; Neal, 2012; Blundell et al., 2015), for example, seek to capture the uncertainty of a network by considering a prior distribution over the model’s weights.
Training these networks is challenging because the exact posterior is intractable and usually approximated using a variety of methods for posterior inference.
Closely related, Deep Ensembles (Lakshminarayanan et al., 2017) and Monte-Carlo Dropout (Gal & Ghahramani, 2016) consider the outputs of multiple models as an alternative way to approximate the distribution.
Model calibration (Platt, 1999; Guo et al., 2017) aims at producing conﬁdence score that are representative of the likelihood of correctness.
Uncertainty quantiﬁcation may also be obtained by training the network to provide uncertainty measures.
Prior Networks (Malinin & Gales, 2018) model the implicit posterior distribution in the Bayesian approach, DeVries & Taylor (2018) ; Lee et al. (2017) have the network output an additional conﬁdence output.
These methods require a proxy dataset representing the out-of-distribution samples to train their conﬁdence scores.
Our method differs from the above as it seeks to give an uncertainty estimation based on a model trained with the usual cross-entropy loss.
It does not require additional modelling assumptions, nor modiﬁcations to the model’s architecture or training procedure.
As such, it relates closely to threshold-based methods.
For example, Hendrycks & Gimpel (2016) use the logits outputs as a measure of the network’s conﬁdence and can be improved using Temperature Scaling (Guo et al., 2017; Liang et al., 2017), a post-processing method that calibrates the model.
Our work derives a conﬁdence score by learning the probability distribution of the feature space and generalizes to adversarial samples (Szegedy et al., 2013), another source of neural networks’ brittleness.
Adversarial samples Methods to defend against adversarial examples include explicitly training networks to be more robust to adversarial attacks (Tram`er et al., 2017; Madry et al., 2017; Papernot et al., 2015).
Another line of defense comes from the ability to detect adversarial samples at test time.
Song et al.
(2017) for example, use a generative model trained on the input images to detect and purify adversarial examples at test time using the observation that adversarial samples have lower predicted likelihood under the trained model.
Closer to our work, Zheng & Hong (2018) and Lee et al.
(2018) train a conditional generative model on the feature space learned by the classiﬁer and derive a conﬁdence score based on the Mahalanobis distance between a test sample and its predicted class representation.
Our method makes the GMM class-agnostic, making it applicable to settings where labels are not available at inference time.
We further show that the unsupervised GMM improves on the Mahalanobis score on the OOD detection task.
D ETECTING MISTAKES
Detecting samples on which a trained classiﬁer is likely to make a mistake is crucial when considering the range of applications in which these models are deployed.
However, predicting in advance whether a sample will fail seems challenging, especially when the sample is drawn from the same distribution as the train set.
To illustrate this, we show in Fig.
1, samples from the CIFAR-100 training dataset and compare them to test samples and adversarial examples that our DenseNet model fails to classify properly.
In both cases, it is not obvious to the human eye what fundamentally differs between correct and incorrect samples.
Our main intuition is that a generative model trained on the feature space could capture these subtle differences.
3. B ACKGROUND
We consider the problem of classiﬁcation where we have access to a (possibly partially) labeled dataset D
= { ( X i , y i ) } Ni =1 where ( X i , y i ) ∈
X × Y .
Samples are assumed to be independently sampled from a distribution p data ( X , y ) and we denote the marginal over X as p data ( X ) .
We will denote f θ : X −→ F = R D the feature extractor part of our neural network, where θ represents the parameters of the network and F is the feature space of dimension D .
Given an input X , the predictions probabilities on the label space Y are then typically obtained using multivariate logistic regression on the extracted features.
[Equation]
where ( W , b ) represent the weights and bias of the last fully-connected layer of the neural network.
The model prediction is the class with the highest predicted probability: ˆ y ( X ) =
arg max y ∈Y p ( y | X , θ, W , b ) .
The parameters ( θ, W , b ) are trained to minimize a crossentropy loss on the training set and performance is evaluated on the test set.
Learning the data structure with Generative Models Understanding the data structure can greatly improve the ability of neural models to generalize.
Recently, great progress has been made in designing powerful generative models that can capture high-dimensional complex data such as images.
PixelCNN (Salimans et al., 2017; Oord et al., 2016b;a) in particular, is a state-of-the-art deep generative model with tractable likelihood that represents the probability density of an image as a fully factorized product of conditionals over individual pixels of an image.
[Equation]
Flow models such as the Masked Autogressive Flow (MAF) (Papamakarios et al., 2017) model provide similar tractability by parameterizing distributions with reversible functions which make that likelihood easily tractable through the change of variable formula.
Another widely used class of generative models assumes the existence of unobserved latent variables.
Gaussian Mixture Models, for example, assume discrete latents (corresponding to the mixture component).
Variational autoencoders (Kingma & Welling, 2013) use continuous latent variables and parameterize the (conditional) distributions using neural networks.
3. M ODELING THE FEATURE SPACE
We identify two main reasons why characterizing examples over which a classiﬁer is likely to make a mistake is difﬁcult.
First, modeling the input data distribution p data ( X ) , as done in Song et al.
(2017) to detect adversarial examples, is challenging because of the high-dimensional, complex nature of the image space X .
This approach also fails at detecting out-of-distribution samples, with state-of-the art models assigning higher likelihoods to samples that completely differ from their train set (Nalisnick et al., 2018).
Second, a model of p data ( X ) doesn’t capture any information about the classiﬁer itself.
To overcome these difﬁculties, we propose to model the underlying distribution of the learned features F = f θ ( X ) , where X ∼ p data ( X ) .
Extracted features have lower dimension which makes them easier to model and they give access to some information on the classiﬁer.
Speciﬁcally, we are interested in comparing features F c of samples that are correctly classiﬁed with features F w of samples that are incorrectly classiﬁed by a trained neural network.
F c and F w can be described as elements of the following sets:
[Equation]
The distribution of the extracted features is modeled by:
[Equation]
where K is the number of Gaussians in the mixture, π k , µ k , Σ k are the model parameters.
We choose Σ k to be diagonal in all our experiments.
After training a neural network to convergence, we learn the parameters of the GMM using the EM algorithm.
Our training set is built from the features extracted from the training image set by the trained classiﬁer.
3. D ETECTING CLASSIFICATION MISTAKES
We posit that classiﬁcation mistakes are linked to extracted features that are unusual under the training distribution.
By modeling the feature space learned by the classiﬁer, our generative model will be able to detect an input that will lead to a potential classiﬁcation mistake.
We found that a simple generative model is surprisingly good at capturing the distribution of the feature space and can detect when an input will lead to a classiﬁcation mistake based on its predicted feature log-likelihood.
Statistical Hypothesis Testing We consider p C ( F c ) the distribution of features F c = f θ ( X ) where ( X , y ) ∼ p data ( X , y ) and
ˆ y
( X ) =
y , and p W ( F w ) the distribution of features F w = f θ ( X ) where ( X , y ) ∼ p data ( X , y ) and ˆ y ( X ) (cid:54) =
y .
These correspond to features extracted on correctly classiﬁed vs. incorrectly classiﬁed examples.
Note that these distributions not only depend on the underlying data distribution but also on the classiﬁer’s parameters ( θ, W , b ) .
Assuming we have access to samples F c, 1 , . .
, F c,n ∼ p C and F w, 1 , . . .
F w,m ∼ p W our null hypothesis H 0 and alternative hypothesis H 1 are:
[Equation]
We use the Mann-Whitney U-test, which assumes that samples can be ranked.
The test statistic is deﬁned by ranking all samples of the two groups together and using the sum of their ranks.
[Equation]
where R C and R W are the sum of ranks of samples F c and F w respectively.
The statistic for the statistical test is U = min( U C , U W ) , which has a distribution that can be approximated by a normal distribution under the null hypothesis.
In our approach, samples are ranked based on their predicted probability.
Since our test statistic directly uses the predicted likelihood of a feature, we deduce from it a simple per-sample test to determine if an input is likely to be misclassiﬁed.
Given a threshold T , a test sample X is rejected as being misclassiﬁed if p ( f θ ( X )) < T .
The value of the threshold is chosen by cross-validation on the validation set to obtain a good trade-off between precision and recall.
[Figure]
E XPERIMENTS
We run experiments on the CIFAR-100 dataset, containing 32 × 32 color images used for image classiﬁcation with 100 classes.
All reported results give the mean and standard deviation overindependent runs.
Additional experiments on a model trained on the smaller CIFAR-10 dataset are also available in the appendix.
We examine two state-of-the-art deep neural networks, DenseNet100 (Huang et al., 2016) and Wide ResNet-28 (Zagoruyko & Komodakis, 2016) trained with the usual cross-entropy loss.
In the setting where only a small number of labels is available, we train a WRN-28 model with 100 labeled samples per class using Temporal ensembling (Laine & Aila, 2016).
This self-ensembling training method takes advantage of the stochasticity provided by the use of dropout and random augmentation techniques (e.g. random ﬂipping and cropping).
Mistake Detection Using statistical testing, we verify that the trained model learns a distribution that differentiates correct and incorrect samples.
We sum up the performance of our method by reporting the AUC-ROC and AUC-PR obtained on the test set.
To motivate the use of high-level features, we adapt the detection method used by Song et al. (2017) to the mistake detection problem and compare the performance with our proposed method.
We train a PixelCNN on the image dataset and use the predicted likelihood values to detect classiﬁcation mistakes.
We evaluate mistake detection on the test set and ﬁrst compare the distribution predicted by PixelCNN on the images with the distribution predicted by a GMM-100 model on extracted features (Figure 2).
Using the Mann-Whitney U-test, we verify that the distribution learned by GMMdifferentiates correct and incorrect samples ( p = 1 .
9 e − 13 ).
On the other hand, because PixelCNN is trained without knowledge of the classiﬁer’s internal representations, the distributions of correct and incorrect samples predicted under PixelCNN are almost indistinguishable ( p = 8 .
58 e − 5 ).
Additionally, we experimented with more ﬂexible likelihood models to model the feature space such as the Variational Auto Encoder (Kingma & Welling, 2013) and Masked Autoregressive Flow (Papamakarios et al., 2017).
Surprisingly, we found that a simple Gaussian Mixture Model is better at detecting classiﬁcation mistakes than these more ﬂexible models.
Finally, we also compare with other threshold-based methods: using the predicted logits and calibrated scores obtained after Temperature Scaling.
Detection performance is summed up in Figure 3 for DenseNet and WideResNet models trained on CIFAR-100.
GMM models trained on the features outperform all other generative [Figure] models trained either on images or on the feature space.
We ﬁnd that using a GMM has similar performance than calibrated scores on the Wide ResNet but not on the DenseNet.
This is explained by the fact that our DenseNet model has much lower accuracy than Wide ResNet ( 72 .
76% v. 80 .
and therefore does not produce overly conﬁdent predictions.
Additional results are available in the appendix.
In the next experiments, we show that although using predicted logits provides reliable detection of test set mistakes, this metric doesn’t generalize to adversarial or out-of-detection samples.
On the other hand, our approach to train a generative model on the feature space can be applied to these other sources of classiﬁcation errors.
Adversarial samples We craft adversarial samples from test samples using the Fast-Gradient Sign
Method (FGSM) proposed by Goodfellow et al.
and the Basic Iteration Method (BIM) (Kurakin et al., 2016).
Both methods move the input image in the direction of the gradient of the loss while restraining the adversarial sample to be in a (cid:96) 1 ball of ray (cid:15) attack around the original input. This ensures that the generated adversarial sample is visually indistinguishable from the original.
Figure 4 shows that the GMM is sensitive to features extracted from adversarial samples, as they are assigned higher BPDs than clean samples.
We also plot the ROC curves and corresponding AUC metrics that are obtained by using the predicted BPD to detect adversarial samples.
We compare our approach with other possible detection metrics.
In particular, the method proposed by Zheng & Hong (2018) and the Mahalanobis score from Lee et al.
(2018) also leverage the feature space to detect adversarial inputs. These approaches use one different model per class and therefore require labels to train while we only train one GMM in an unsupervised manner.
ROC curves are shown in Figure 5 and a full comparison table with higher (cid:15) attack values for both attacks is shown in [Figure]
the appendix. Our method, using a GMM-1000 provides better detection performance of adversarial samples than calibrated and non-calibrated logit scores.
Most notably, in a semi-supervised setting (Figure 5c), our method surpasses all others on attacks with low (cid:15) attack values.
[Figure]
Our method achieves comparable detection results as the Mahalanobis and the Zheng metric and surpasses both of them in a semi-supervised setting (Figure 5c)
Out-of-Distribution Detection We also test the use of feature log-likelihood values on the task of detection out-of-distribution samples.
As Out-of-Distribution samples we use Random Gaussian Noise, SVHN (Netzer et al., 2011), Tiny ImageNet (Russakovsky et al., 2015), and Fashion
MNIST (Xiao et al., 2017).
OOD detection results are reported in Table 2 for each model we trained.
Our experiments show that it is not possible to rely on calibrated probability scores for OOD detection, and that our method yields better detection results than using the Mahalanobis score in some cases.
We also highlight that a PixelCNN trained on CIFAR has very poor detection results on image datasets that visually look very different from its original training set (FashionMNIST and SVHN).
This is a result of the generative model assigning higher likelihood to these OOD samples.
Tablein the annex also shows that only calibrated scores fail to detect random gaussian noise as an OOD sample.
[Table]
C ONCLUSION
Using statistical hypothesis testing we provided a general characterization of inputs that lead to classiﬁcation mistakes by deep neural networks.
With a simple Gaussian Mixture Model, we model the distribution of the feature space learned by a classiﬁer and veriﬁed that features extracted from inputs consistently lie outside of the training distribution and can be detected by their low predicted log probability.
Compared to other score-based methods, our characterization holds for a variety of classiﬁcation failure modes in deep neural networks: adversarial sample detection, out-of-distribution detection and test time classiﬁcation mistakes
[Table]
A A DDITIONAL DETECTION RESULTS
[Figure]
[Figure]
[Figure]
[Figure]
[Table]
[Table]
B P URIFICATION B. M ETHOD
The puriﬁcation process aims at moving the feature F extracted by the classiﬁer to a low BPD region.
This can be formulated as a joint optimization problem where we want to ﬁnd features F with minimal BPD, while being close to the initial extracted features F ref .
[Equation]
ν is a hyperparameter that deﬁnes how close the new feature should be to the initial one.
As the objective is not convex and there is no close form solution for stationary points, we use gradient descent with regards to F to minimize the objective function.
[Equation]
B. P URIFICATION RESULTS
Puriﬁcation of features is performed with 100 iterations of gradient descent steps to optimize the objective function.
We test the performance of puriﬁcation for both classiﬁcation and semi-supervised classiﬁcation tasks on CIFAR-100.
We report the accuracy on validation and test set obtained after puriﬁcation with different GMMs and for different values of learning rates (cid:15) and regularization strength ν in Table 4.
For classiﬁcation, our networks are DenseNet (DN-100) and Wide ResNet (WRN-28).
For semi-supervised classiﬁcation, we apply temporal ensembling to wide ResNet (TE-WRN-28).
Our results show that this puriﬁcation procedure is able to correct classiﬁcation mistakes on previously unseen samples and results in an accuracy gain for the model without the need to retrain.
However the puriﬁcation method also leads to new classiﬁcation mistakes, which means that the net improvement on the accuracy reaches 0 .
6% on the DenseNet model at most.
test accuracy by up to 0 .
6% on the DenseNet model.
GMM (cid:15) ν
DNWRN- TE-WRNVal
Test
Val
Test
Val
Test
Original - - 73.
C E XPERIMENTAL SETUP
Dataset and preprocessing We trained on CIFAR-10 and CIFAR-100 Krizhevsky (2009) with 5,000 images held-out validation images.
Inputs were preprocessed with per-channel standardization before training.
DenseNet We use bottleneck layers and compression rate θ = 0 .
5 , growth rate k
= 12 and depth
L = 100 .
The model is trained with batch size 64 for 300 epochs with a learning rate 0 .
1 , dropout rate 0 .
2 and L 2 regularization weight 1 e − 4 .
We use ReLU non-linearities except for the last layer where we use a tanh non-linearity to ensure the extracted features are bounded.
For optimization, we use Stochastic Gradient Descent with a Nestrov momentum of 0 .
The learning rate is divided by 10 at epoch 150 and 175.
Wide ResNet Wide ResNet Zagoruyko & Komodakis (2016) is trained with growth rate k
=and depth L = 28 and batch size 100 for 200 epochs, with a learning rate 0 .
1 , dropout rate 0 .
3 and Lregularization weight 5 e − 4 .
Data augmentation is applied during training with random translation by up to 2 pixels and random horizontal ﬂips.
Temporal Ensembling For the semi-supervised setting, we only keep 100 samples per label in the train set.
We train a Wide ResNet using Temporal Ensembling with a maximum weight decay of 100 .
PixelCNN The PixelCNN model is trained with the PixelCNN++ ameliorations from Salimans et al.
(2017) for our experiments.
The model is trained for 5000 epochs with dropout rate 0 .
5 and learning rate 1 e − 4 .
VAE
The VAE is trainer for 1000 epochs with a learning rate of 0 .
001 and decay rate of 0 . 9995 .
The encoder and decoder architecture are fully connected layers with ReLU non-linearities, one hidden layer of size 512 and latent dimension of 128 .
The model was trained with Adam.
MAF The Masked Autoregressive Flow model is trained for 1000 epochs with a learning rate of 0.01 and batch size 32 using Adam Optimizer.
We used a 5-layer MADE model with hidden layer size of 128.
Temperature Scaling The temperature for Temperature Scaling is optimized using the L-BFGSB optimization algorithm with a maximum of 100 iterations.
We use ECE with B = 10 bins to evaluate the success of the calibration.