UQGAN: A Unified Model for Uncertainty Quantification of Deep Classifiers trained via Conditional GANs
Abstract
We present an approach to quantifying both aleatoric and epistemic uncertainty for deep neural networks in image classification, based on generative adversarial networks (GANs).
While most works in the literature that use GANs to generate out-of-distribution (OoD) examples only focus on the evaluation of OoD detection, we present a GAN based approach to learn a classifier that produces proper uncertainties for OoD examples as well as for false positives (FPs).
Instead of shielding the entire in-distribution data with GAN generated OoD examples which is stateof-the-art, we shield each class separately with out-of-class examples generated by a conditional GAN and complement this with a one-vs-all image classifier.
In our experiments, in particular on CIFAR10, CIFAR100 and Tiny ImageNet, we improve over the OoD detection and FP detection performance of state-of-the-art GAN-training based classifiers.
Furthermore, we also find that the generated GAN examples do not significantly affect the calibration error of our classifier and result in a significant gain in model accuracy.
Introduction
Deep learning has shown outstanding performance in image classification tasks [22, 43, 13].
However, due to the enormous capacity and the inability of rejecting examples, deep neural networks (DNNs) are not capable of expressing their uncertainties appropriately.
DNNs have demonstrated the tendency to overfit training data [46] and to be easily fooled into wrong class predictions with high confidence [9, 12].
Also, importantly, ReLU networks have been proven to show high confidence far away from training data [14].
This is contrary to the behavior that would be expected naturally by humans, which is to be uncertain when being confronted with new data examples that have not been observed during training.
Several approaches to predictive uncertainty quantification have been introduced in recent years, considering uncertainty in a Bayesian sense [2, 7, 18] as well as from a frequentist’s point of view [15, 5, 34].
A common evaluation protocol is to discriminate between true and false positives (FPs) by means of a given uncertainty quantification.
For an introduction to uncertainty in machine learning, we refer to [17], for a survey on uncertainty quantification methods for DNNs see [8].
By design of ordinary DNNs for image classification, their uncertainty is often studied on indistribution examples [1].
The task of out-of-distribution (OoD) detection (or novelty detection) is oftentimes considered separately from uncertainty quantification [29, 44, 31].
Thus, OoD detection in deep learning has spawned an own line of research and method development.
Among others, changes in architecture [5], loss function [41, 48] and the incorporation of data serving as OoD proxy [16] have been considered in the literature.
Generative adversarial networks (GANs) have been used to replace that proxy by artificially generated data examples.
In [27], examples of OoD data are created such that they shield the in-distribution regime from the OoD regime.
Note that this often requires pre-training of the generator.
E.g. in the aforementioned work, the authors constructed
OoD data in their 2D example to pretrain the generator.
While showing promising results, such
GAN-based approaches mostly predict a single score for OoD detection and do not yield a principled approach to uncertainty quantification distinguishing in-distribution uncertainty between classes and out-of-distribution uncertainty.
In this work, we propose to use GANs to, instead of shielding all classes at once, shield each class separately from the out-of-class (OoC) regime (also cf.
figure 1).
Instead of maximizing an uncertainty measure, like softmax entropy, we combine this with a one-vs-all classifier in the final
DNN layer.
This is learned jointly with a class-conditional generator for out-of-class data in an adversarial framework.
The resulting classifiers are used to model (class conditional) likelihoods.
Via Bayes rule we define posterior class probabilities in a principled way.
Our work thus makes the following novel contributions:
We introduce a GAN-based model yielding a classifier with complete uncertainty quantification.
Our model allows to distinguish uncertainty between classes (in large sample limit, if properly learned, approaching aleatoric uncertainty) from OoD uncertainty (approaching epistemic uncertainty).
By a conditional GAN trained with a Wasserstein-based loss function, we achieve class shielding in low dimensions without any pre-training of the generator. 4.
In higher dimensions, we use a class conditional autoencoder and train the GAN on the latent space.
This is coherent with the conditional GAN, allows us to use less complex generators and critics and reduces the influence of adversarial directions.
We improve over the OoD detection and FP detection performance of state-of-the-art GANtraining based classifiers.
We present in-depth numerical experiments with our method on MNIST, CIFAR10, CIFAR100 and Tiny ImageNet, accompanied with various OoD datasets.
We outperform other approaches, also GANbased ones, in terms of OoD detection and FP detection performance on CIFAR10.
Also on MNIST, CIFAR100 and Tiny ImageNet we achieve superior OoD detection performance.
Noteworthily, on the more challenging CIFAR10, CIFAR100 and Tiny ImageNet datasets, we achieve significantly stronger model accuracy compared to other approaches based on the same network architecture.
Related Work
In this section we give an overview of common uncertainty quantification methods as well as publications related to the different parts of our method.
In this context the task of uncertainty quantification is to assign scalar values to predictions, quantifying aleatoric (in-distribution) and epistemic (out-of-distribution) uncertainty.
(Baselines) The works by [52, 15, 5] can be considered as early baseline methods for the task of OoD detection.
They are frequentist approaches relying on confidence scores gathered from model outputs.
The problem can oftentimes be attributed to the usage of the softmax activation function, which leads to overconfident predictions, in particular far away from training data, or to the decoupling of the confidence score from the original classification model during test time.
Our proposed method does not make use of the softmax activation function and can produce unified uncertainty estimates during test time without the requirement of auxiliary confidence scores.
(Conformal methods) Methods associated with the term conformal predictions [35, 3, 30] are predicting, for a given confidence value, a set of classes that is likely to contain the real class.
As such, they can give a more intuitive explanation to which classes might be getting confused.
In essence, the uncertainty of a prediction can be derived from the size of the predicted set, assigning higher prediction uncertainty to larger sets.
They are however not able to quantify both, aleatoric and epistemic uncertainty, and assigning a scalar uncertainty value to predictions, as in our setting, might not be straight forward.
(Data perturbation and auxiliary data) Many methods use perturbed training examples [28, 37, 29] or auxiliary outlier datasets [16, 20]. [28] use them for their confidence score based on class conditional Gaussian distributions, while [29] and [37] are utilizing them to increase the separability between in- and out-of-distribution examples. [16] use a hand picked auxiliary outlier dataset during model training and [20] use it for selecting a suitable GAN discriminator during training which then serves for OoD detection.
The common problem with using perturbed examples is the sensitivity to hyperparameter selection which might render the resulting examples uninformative.
Additionally, auxiliary outlier datasets cannot always be considered readily available and pose the problem of covering only a small proportion of the real world.
In contrast, our method is able to produce OoC examples that are very close to the in-distribution but still distinguishable from it, thus we do not require explicit data perturbation or any auxiliary outlier datasets.
(Bayesian methods) Bayesian approaches [7, 2, 24] provide a strong theoretical foundation for uncertainty quantification and OoD detection.
[24] propose deep ensembles that approximate a distribution over models by averaging predictions of multiple independently trained models.
[7] are utilizing Monte-Carlo (MC) sampling with dropout applied to each layer.
In [2] a variational learning algorithm for approximating the intractable posterior distribution over network weights has been proposed.
While the theoretical foundation is strong, these methods often require changing the architecture, restricting the model space and/or increased computational cost.
While making use of Bayes-rule, we are staying in a frequentist setting and are not dependent on sampling or ensemble techniques.
This reduces computational cost and enables our model to produce high quality aleatoric and epistemic uncertainty estimates with a single forward pass.
Also, our proposed framework does not change the network architecture, except for the output layer activation function, and thus makes it compatible with previously published techniques.
(One-vs-All methods) One-vs-All methods in the context of OoD detection have been recently studied by [6, 34, 38].
In the work by [6] an ensemble of binary neural networks is trained to perform one-vs-all classification on the in-distribution data which are then weighted by a standard softmax classifier.
[34] use a DNN with a single sigmoid binary output for every class and explore the possibility of training the one-vs-all network with a distance based loss function instead of the binary cross entropy.
Domain adaptation is considered in [38], where they utilize a one-vs-all classifier for a first OoD detection step before classifying into known classes with a second model.
Their training objective is also accompanied by a hard negative mining on the in-distribution data.
All these methods use the maximum predicted probability as a score for OoD detection and/or classification and do not aggregate the other probabilities into a single score like the method proposed by us.
They also do not distinguish into different kinds of uncertainties as in our work.
Lastly their training objectives are only based on in-distribution data.
Generated OoC data as used in the present work is not considered.
(Generative methods) More recently generative model based methods [39, 27, 45, 47, 51] have shown strong performance on the task of out-of-distribution detection by supplying classification models with synthesized out-of-distribution examples.
[39] utilize the latent space of a GAN by gradient based reconstruction of an input example.
In the work by [27], a GAN architecture with an additional classification model is built.
The classification model is trained to output a uniform distribution over classes on GAN examples close to the in-distribution.
This approach is further improved by [45] who show improvements on the task of out-of-distribution detection.
The generalization to distant regions in the sample space and the quality of generated boundary examples is however questionable [51].
A similar approach using a normalizing flow and randomly sampled latent vectors is proposed by [10].
The high level idea of the architectures proposed in the previously mentioned works is similar to the one proposed by us.
However, other works are not able to approximate the boundary of data distributions with multiple modes as shown by [51].
Due to the fact that our GAN is class conditional and trained on a low dimensional latent space, we are able to follow multiple distribution modes resulting from different classes.
We improve the in-distribution shielding by using a low-dimensional regularizer and have an additional advantage in terms of computational cost as our cGAN model architecture can be chosen with considerably smaller size due to it being trained in the latent space.
Furthermore, these methods do not yield separate uncertainty scores for FP and OoD examples.
Generating OoD data based on lower dimensional latent representations has been explored in [50, 40]. [50] utilize a variational Autoencoder (vAE) to produce examples that are inside the encoded manifold (type I) as well as outside of it (type II).
[40] (GEN) also use a vAE and train a GAN in the resulting latent space, assigning generated examples to the OoD domain in order to estimate a
Dirichlet distribution on the class predictions.
Utilizing a vAE has the advantage that one can make assumptions on the distribution of the latent space but also results in slightly blurry reconstructions.
While the work of [40] is the most similar to our method, we improve on several shortcomings.
First of all we employ class conditional models to improve diversity and class shielding.
Additionally, we are able to distinguish aleatoric and epistemic uncertainty while the method by [40] is not.
It assigns the same type of uncertainty to OoD and FP examples.
Method 3.1 One-vs-All Classification
We start by formulating our classification model as an ensemble of one-vs-all classifiers.
Let
C ( o | x, y ) model the probability that for a given class y ∈ Y = { 1 , . . . , n } , an example with features x ∈ X =
R d is OoC. Analogously,
C
( i | x, y )
= 1 − C
( o | x, y ) for a given class y models the probability of x being in-class.
Let S ⊆
X
× Y be our training dataset with ˆ p ( y ) ,
y ∈ Y , the estimated relative class frequencies.
To model C ( i | x, y ) , we use a DNN with n ≥ 2 output neurons equipped with sigmoid activations.
For each class output y , the data corresponding to class y serves as in-class data and all other data as OoC data.
Hence, a basic variant of our training objective is given by a weighted empirical binary cross entropy
[Equation]
Therein, ˆ p ( y ) ˆ p ( y ′ ) is weighting the OoC loss to counter potential class imbalance.
Similarly, 1 n − 1 weighs the OoC loss compared to the in-class loss.
Applying the transformation
[Equation]
after training, we obtain an appropriate classifier, formalized as follows:
Lemma 1 (Class posterior) .
Under typical assumptions of statistical learning theory and training C on equation (1) it holds that for | S | → ∞
[Equation]
A enc x z y e ˜ z y
G (˜ z,y )
z y ˜
z
y
D (˜ z,y ) ( z,y )
A dec ˜ x x
C
L C
L GD
C ( i | x,y ) C
( o | x,y 0 ) C
( o | ˜ x,y )
C ( o | ˜ x , y )
See appendix A for the detailed assumptions and the proof, explaining our choice of the classification model. We distinguish between aleatoric and epistemic uncertainty. While aleatoric uncertainty is considered to be inherent to all observations and irreducible (for a fixed X ), epistemic uncertainty is induced by the model choice and the amount of data and can be reduced by additional data and appropriate model selection. Using ˆ p ( y | x ) , we estimate the probability of an example x being in-distribution by defining
[Equation]
which yields a quantification of epistemic uncertainty via ˜ C
( o | x ) = 1 − ˜ C
( i | x ) .
For aleatoric uncertainty estimation, we consider the Shannon entropy of the predicted class probabilities
[Equation]
[Equation]
This is a sensible definition since we showed that ˆ p ( y | x )
→ p ( y | x ) for | S | → ∞ .
If the real p ( y | x ) is close to a uniform distribution over the classes (which maximizes the Shannon entropy) we have a high uncertainty and vice versa.
For epistemic uncertainty ˜ C ( i | x ) can be considered as a proxy for p ( i | x ) , which results in the epistemic uncertainty by 1 − ˜ C
( i | x ) .
In addition, we generate for each class OoC examples with a conditional GAN.
A joint training of classifier and GAN is introduced in the upcoming section 3.2.
3.2 GAN Architecture
Similar to [27], we combine our classification model with a GAN and train both alternatingly.
The assumptions that we made for lemma 1 are standard in statistical learning theory, however it is important to notice that we exclude the GAN-generated data from the statement.
By incorporating
GAN-generated data into the training of our classification model introduced in section 3.1, we are violating this assumption.
However, in section 4 we demonstrate empirically that this does not harm our classification model performance-wise.
The Wasserstein GAN with gradient penalty proposed by [11] serves a basis for our conditional GAN (cGAN).
Additionally, we condition the generator as well as the critic on the class labels to generate class specific OoC examples.
Inspired by [40, 50] where the latent space of a variational autoencoder (vAE) is utilized for GAN training, we proceed analogously, however using a vanilla conditional autoencoder (cAE) as we observed reconstructions with higher visual quality for this choice.
Training the cGAN on a latent space, we do not generate adversarial noise examples and can use less complex generators and critics.
Prior to the cGAN training, we train the cAE on in-distribution data and then freeze the weights during the cGAN and classifier training.
The optimization objective of the cAE is given as pixel-wise binary cross-entropy
[Equation]
with ˆ x i =
A dec ( z, y ) the decoded latent variable, z =
A enc ( x ) being the encoded example, x i the i -th pixel of example x and N x the number of pixels belonging to x .
Therein, the pixel values are assumed to be in the interval [0 , 1] , while 0 · log(0) = 0 .
The cGAN is trained using the objective function
[Equation]
) with D the conditional critic, z
=
A enc ( x ) , ˜ z
= G ( e, y )
the latent embedding produced by the conditional generator, e ∼ U (0 , 1) noise from a uniform distribution, y a class label and L gp the gradient penalty from [11].
Integrating the classification objective into the cGAN objective, we alternate between
[Equation]
and [Equation] C
[Equation]
with λ real ∈ [0 , 1] being an interpolation factor between real and generated OoC examples and L R being an additional regularization loss for the generated latent codes with hyperparameter λ R ≥ 0 , which we introduce in section 3.3.
The latent embeddings produced by the cGAN are decoded with the pretrained cAE, thus ˜ x
= A dec (˜ z, y ) =
A dec ( G ( e, y ) , y ) .
That is, the cGAN is trained on the latent space while the classification model is trained on the original feature space.
Our entire
GAN-architecture is visualized in figure 2.
3.3 Low-Dimensional Regularizer
In low dimensional latent spaces we found it to be advantageous to apply an additional regularizer to the generated latent embeddings ˜ z to improve class shielding.
Let ( z, y ) be the latent embedding of an example x with its corresponding class label y and Z ( z, y ) =
{ ˜ z − z | ˜ z
= G ( e, y ) , e ∼ U (0 , 1) } =
(cid:110) ¯ z 1 , . .
, ¯ z N zy (cid:111) all generated latent codes with the same class label and normalized to origin z .
We encourage the generator to produce latent codes that more uniformly shield the class y by maximizing the average angular distance between all ¯ z ∈ Z ( z, y ) , which corresponds to minimizing
[Equation]
with ∗ being the dot-product.
The logarithm introduces an exponential scaling for very small angular distances, encouraging a more evenly spread distribution of the generated latent codes.
This loss is then averaged over all class labels and training data examples
[Equation]
with N y =
|{ ( x, y ′ ) |
y ′ =
y }| the number of examples with class label y .
In appendix B a more detailed explanation of this regularization loss is provided.
During our experiments we studied different regularizer losses such as Manhattan/Euclidean distance, infinity norm and standard cosine similarity.
In experiments, we found that for our purpose equation (11) performed best.
We argue that this can be attributed to the independence of the latent space [Table] [Figure] examples value range, which can have a large impact on the p -norm distance metrics, and to the exponential scaling for very small angular distances.
To this end, the basic variant of our method does not account for model uncertainty.
Thus, we also include results with MC-Dropout, which also demonstrates the compatibility of our model with existing methods.
Another limitation of our approach is that we are not explicitly accounting for adversarial attacks because during training in the cAE latent space we are removing any adversarial directions.
Experiments
We compare our method with a number of related approaches (cf.
table 1).
While the first two methods are simple baselines, the subsequent three ones are Bayesian ones and the final two methods are
GAN-based (cf.
section 2).
Following the publications [40, 50, 37, 15], we consider four experimental setups using the MNIST ( 28 × 28 , 10 classes) [26], CIFAR10 ( 32 × 32 , 10 classes) [21], CIFAR ( 32 × 32 , 100 classes) [21] and Tiny ImageNet ( 64 × 64 , 200 classes) [25] datasets as in-distribution, respectively.
Similar to [40, 50] and others, we split the datasets class-wise into two non-overlapping sets, i.e., MNIST 0-4 / 5-9, CIFAR10 0-4 / 5-9, CIFAR100 0-49 / 50-99 and Tiny ImageNet 0-99 / 100-199.
While the first half serves as in-distribution data, the second half constitutes OoD cases close to the training data and therefore difficult to detect.
For the MNIST 0-4 dataset, we consider the
MNIST 5-9, EMNIST-Letters [4], Fashion-MNIST [53], Omniglot [23], SVHN [33] and CIFAR datasets as OoD examples.
For the CIFAR10 0-4 datasets, we use CIFAR10 5-9, LSUN [55], SVHN, Fashion-MNIST and MNIST as OoD examples.
The same OoD datasets are used for CIFAR except CIFAR10 5-9 being replaced by CIFAR100 50-99.
For the Tiny ImageNet 0-99 dataset we use Tiny ImageNet 100-199, SVHN, Fashion-MNIST and MNIST as OoD examples.
These selections yield compositions of training and OoD examples with strongly varying difficulty for state-of-the-art OoD detection.
Besides that, we examine our method’s behavior on a 2D toy example with two overlapping Gaussians (having trivial covariance structure), see figure 1.
Additionally, we split the official training sets into 80% / 20% training / validation sets, where the latter are used for hyperparameter tuning and model selection.
Like related works, we utilize the LeNet-5 architecture on MNIST and a small ResNet on CIFAR10, CIFAR100 and Tiny ImageNet as classification models.
To ensure fair conditions, we re-implemented all aforementioned methods while following the authors recommendations for hyperparameters and their reference implementations.
For methods involving more complex architectures, e.g. a GAN or a VAE as in [27, 40], we used the proposed architectures for those components, while for the sake of comparability sticking to our choice of classifier models.
All implementations are using PyTorch [36] and can be found in the associated repository 1 .
For each method, we selected the network checkpoint with maximal validation accuracy during training.
For a more detailed overview of the hyperparameters used in our experiments, we refer to appendix D.
For evaluation we use the following well established metrics:
• Classification accuracy on the in-distribution datasets. [Table]
[Table] • Area under the Receiver Operating Characteristic Curve (AUROC).
We apply the AUROC to the binary classification tasks in-/out-of-distribution (via the score from equation (4)) and TP/FP (Success/Failure) (via the score from equation (5)).
• Expected Calibration Error (ECE) [32] applied to the estimated class probabilities ˆ p ( y | x ) for in-distribution examples x , computed on 15 bins.
• Area under the Precision Recall Curve (AUPR) w.r
[Table] t. the binary in-/out-of-distribution decision (via the score from equation (4)).
We further distinguish between AUPR-In and AUPR-Out.
For AUPR-in the in-distribution class is the positive one, while for AUPR-Out the out-of-distribution class is the positive one.
• FPR @ 95% TPR computes the False Positive Rate (FPR) at the decision threshold on the OoD score from equation (4) ensuring a True Positive Rate (TPR) of 95%.
Before discussing our results on MNIST, CIFAR10, CIFAR100 and Tiny ImageNet
[Table]
we briefly discuss our findings on the 2D example.
As can be seen in figure 1, the generated OoC examples are nicely shielding the respective in-distribution classes.
OoC examples of one class can be in-distribution examples of other classes.
This is an intended feature and to this end, the loss term for the synthesized OoC examples in equation (9) is class conditional.
This feature is supposed to make our one-vs-all classifier predict a high OoC probability in the OoC regime.
One can also observe that the estimated epistemic and aleatoric uncertainties are complementary, resulting in a high aleatoric uncertainty in the overlapping region of the Gaussians while also having a low epistemic uncertainty there.
This is one of the main advantages that sets our approach apart from related methods.
Results for a slightly more challenging 2D toy example on the two moons dataset and on a grid of Gaussians are presented in appendix C. We now demonstrate that this result generalizes to higher dimensional problems.
For MNIST and CIFAR10, figure 3 shows the OoC examples produced at the end of the generator training.
Due to using a conditional GAN and an AE, we are able to generate OoC examples (instead of only out-of-distribution as in related works) during test time.
It can be seen that the resulting examples resemble a lot of semantic similarities with the original class while still being distinguishable from them. [Table] [Table]
All presented results are computed on the respective (official) test sets of the datasets.
We also conducted an extensive parameter study on the validation sets, which is summarized in appendix E.
The conclusion of this parameter study is that the performance of our framework is in general stable w.r.t.
the choice of the hyperparameters.
Increasing λ reg positively impacts the model performance up to a certain maximum.
The best performance is obtained by choosing latent dimensions such that the cAE is able to compute reconstructions of good visual quality.
Across all datasets, choosing λ real ∈ [0 . 5 , 0 . 6] achieves the best detection scores, also indicating a positive influence of the generated OoC examples on the model’s classification accuracy.
Tables 2 to 5 present the results of our experiments.
The scores in the columns of the section
In-Distribution are solely computed on the respective in-distribution dataset.
The scores in the columns of the section Out-of-Distribution are displaying the OoD detection performance when presenting examples from the respective in-distribution dataset as well as from the entirety of all assigned OoD datasets.
Note that we did not apply any balancing in the OoD datasets but included the respective test sets as is (see appendix D for the sizes of the test sets).
As an upper bound on the OoD detection performance we also show results for two oracle models, supplied with the real
OoD training datasets they are evaluated on.
One of them is trained with the standard softmax and binary-cross-entropy to maximize entropy on OoD examples and the other one with our proposed loss function, cf.
equation (9).
We first discuss the in-distribution performance of our method.
W.r.t.
MNIST, the results given in the left section of table 2 show that we are on par with state-of-the-art GAN-based approaches while still having a similar ECE, only being surpassed by Deep-Ensembles and the other baselines by a fairly small margin.
However, considering the respective CIFAR10 results in the left section of table 3, we clearly outperform state-of-the-art GAN-based methods as well as all other baseline methods by a large margin.
Noteworthily, we achieve an accuracy of 90 .
26% which is 5 to 8 percent points (pp.)
above the other classifiers and an AUROC S/F of 89 .
19% which is 4 to 6 pp.
higher than for the other methods.
This corresponds to a relative improvement of 33% in accuracy and 26% in AUROC
S/F compared to the second best method.
A similar improvement in accuracy can be observed for
CIFAR100 and Tiny ImageNet (tables 4 and 5) where the AUROC S/F is slightly lower but still on par with other approaches.
Considering ECE on CIFAR10/100 and Tiny ImageNet, our MC-Dropout variant is outperforming nearly all related methods, except for CIFAR100 and Tiny ImageNet where it is ranked second.
This signals that, although we incorporate generated OoC examples impurifying the distribution of training data presented to the classifier, empirically there is no evidence that this harms the learned classifier, neither w.r.t.
calibration, nor w.r.t.
separation.
Considering the OoD results from the right-hand sections of tables 2 to 5, the superiority of our method compared to the other ones is now consistent over all four in-distribution datasets.
On the MNIST dataset we are outperforming previously published works, especially considering the
AUPR-In and FPR @ 95% TPR metrics, with a 25% and 27% relative improvement over the second best method, respectively.
This is consistent with the results for CIFAR10 and CIFAR100 as indistribution datasets where we achieve for both AUROC and AUPR-In a relative improvement of 19% – 26% and 3% – 15% , respectively, over the second best method. On the higher dimensional Tiny
ImageNet dataset, which has 20 × more classes than MNIST/CIFAR10 and 4 × more input pixels, the results are even stronger with an 36% – 67% relative improvement over the second best competitor.
Comparing our results with the ones of the oracles, two observations become apparent.
Firstly, in some OoD experiments the GAN-generated OoC examples achieve results fairly close to or even surpassing the ones of the oracles while also in some of them there is still room for improvement left (in particular w.r.t. FPR@95%TPR).
Secondly, GAN-generated OoC examples can help improve generalization (in terms of classification accuracy) while real OoD data might be too far away from the in-distribution data.
An OoD-dataset-wise breakdown of the results in tables 2 to 5 is provided in appendix G. For MNIST, this breakdown reveals that our method performs particularly well in the difficult task of separating MNIST 0-4 and MNIST 5-9.
On the other MNIST-related tasks we achieve mid-tier results, being slightly behind the other GAN-based methods.
The same holds for CIFAR100 0-49 and CIFAR100 50-99.
However, with regards to CIFAR10 and Tiny ImageNet we are consistently outperforming the other methods by large margins.
In appendix F we present results of an experiment where we perform FP and OoD detection jointly on the computed uncertainty scores.
The main observations there are that our method outperforms other GAN-based methods and that our method including dropout achieves the overall best detection performance.
Conclusion
In this work, we introduced a GAN-based model yielding a one-vs-all classifier with complete uncertainty quantification.
Our model distinguishes uncertainty between classes (in large sample limit approaching aleatoric uncertainty) from OoD uncertainty (approaching epistemic uncertainty).
We have demonstrated in numerical experiments that our model sets a new state-of-the-art w.r.t.
OoD as well as FP detection.
The generated OoC examples do not harm the training success in terms of calibration, but even improve it in terms of accuracy.
We have seen that incorporating MC dropout to account for model uncertainty can further improve the results.
Broader Impact
We are contributing generally applicable methodology which can be used in any real world application.
The general direction of making the deployment of models more feasible due to improved quality of uncertainties might ultimately result in a reduction of the number of jobs in the respective sectors.
However, as of now, it is also important to note that this method cannot give any guarantees on the estimated uncertainties and thus these should be used with caution and never solely relied upon. Acknowledgment
M.R. acknowledges useful and interesting discussions with Hanno Gottschalk.
Funding
No third-party funding or support has been received for this work.
A Theoretical Consideration of the One-vs-All Classifier
Let C ( i | x, y ) , y ∈ { 1 , . . . , n } be an ensemble of binary classifiers with C ( o | x, y )
= 1 − C
( i | x, y ) .
Furthermore we define the joint distribution
[Equation]
12) w.r.t.
a uniform class distribution, i.e., p U ( y ) ≡ 1 n ∀ y ∈ Y .
Lastly we define
[Equation]
[Equation] Additionally, ˆ p ( y ) , ∀ y ∈ Y , are the estimated relative class frequencies.
Recalling (1), our proposed training objective for the ensemble of binary classifiers is defined by
[Equation]
Assumption 1.
We make the following assumptions for our one-vs-all classifier C 1.
We sample S ∼ p x , y ) i.i.d.
and there is no GAN-generated data involved
Let H =
{ C } the set of all realizable one-vs-all classifiers.
We assume, there exists a C ∗ ∈ H such that ˆ p ( y | x ) =
p ( y | x ) , i.e., p ( y | x ) is realizable; 3.
We can compute an empirical risk minimizer, i.e., we can determine a C S ∈ H which minimizes (1) for a given sample S .
Note that the above assumptions are typical assumptions in statistical learning theory [42, 49].
Under these assumptions, the empirical risk minimizer converges to the desired hypothesis C ∗ for | S | → ∞ .
Furthermore, (deep) neural networks have an asymptotic (i.e., for increasing network capacity) universal approximation property [54] which makes assumption 2 fairly realistic.
Lemma 1 (Class posterior) .
Under assumption 1 and training C on equation (1) it holds that for | S |
[Equation]
∞ [Equation]
Proof.
Without loss of generality consider a single one-vs-all classifier C
( i | x, y ∗ ) with y ∗ ∈ Y fixed and define ¯ y ∗ :
= Y \ { y ∗ } as the counter-part class of class y ∗ (class “not y ∗ ”).
If we now sample S
[Equation]
p [Equation]
y ) , with ˜ p
y ∗ ( y ∗ )
= 12 and ˜ p
y ∗ ( y ) =
1 2( n − 1) , [Equation] ∈
Y \ { y ∗ } , we are weighting y ∗ and ¯ y ∗ equally.
The loss contribution of C ( i | x, y ∗ ) in equation (1) then becomes
[Equation]
which is the binary cross entropy loss for equal class weights of y ∗ and ¯ y ∗ .
This shows that our chosen loss function (1) yields a balanced one-vs-all classifier.
As the change in sampling from the classes does not affect p ( x | y ) , by assumptions 1–3 we obtain for | S | → ∞ that
[Equation]
z ¯ z
i ¯ z
j α
This implies that the re-weighted classifier ˜ C for | S | → ∞ fulfills
[Equation]
By the preceding convergence
[Equation]
we obtain
[Equation] [Equation]
for | S | → ∞ [Equation] which concludes the proof.
B Low Dimensional Regularizer
In this section we explain how our low dimensional regularizer behaves on a simple example, aiming at providing the reader with a clearer intuition on the role of that regularizer.
Recalling (11), the low dimensional regularizer applied to our GAN training is defined as
[Equation]
with
[Equation]
where for a given example ( x, y ) ∈ S , z
= A enc ( x ) is the latent embedding of x , Z ( z, y )
=
{ ˜ z − z | ˜ z
= G ( e, y ) , e ∼ U (0 , 1) } =
(cid:110)
¯ z 1 , . .
, ¯ z N zy (cid:111) are all, by the GAN, generated latent codes but normalized to origin z and N y
=
|{ ( x, y ′ ) |
y ′
=
y }| are the number of examples x with class label y .
As the regularizer loss is class conditional let us consider a simple example with a single class.
In figure 4 you can see an illustration similar to the left Gaussian in figure 1.
In this example the cosine similarity between ¯ z i and ¯ z
j can be computed as
[Equation]
(26) where cos( α )
= − 1 implies that ¯ z i and ¯ z j point in opposite directions and cos( α )
= 1 implies that they point into the same direction.
In order to get a distance measure that is taking values in [0 , 1] , we compute the angle α in radians and normalize the result by 1 /π , i.e.,
[Equation]
This is now the same quantity as in equation (10).
By maximizing the average angular distance between all unique pairs ¯ z i , ¯ z j ∈ Z ( z, y ) , i < j , we are forcing the generator to spread all generated latent codes on the boundary of the distribution represented by the class-specific data example.
Transforming these angular distances via a logarithm and averaging over all ( x, y ) ∈ S , yields our low dimensional regularizer in equation (11).
Figure 5 shows OoC examples generated by GANs who where trained with different weights for the low dimensional regularizer ( λ reg ).
Especially in the MNIST 0-4 example one can see that
the
GAN trained with λ reg =
32 produces much more diverse samples compared to no low-dimensional regularization.
C Additional Toy Examples
As a more challenging 2D example, we also present a result on the two moons dataset.
In figure 6, the results of an experiment with two separable classes is shown.
In the top row of the figure, the training data is class-wise separable.
In that case, we observe that the decision boundary also belongs to the
OoD regime (top left panel), which is true as there is no in-distribution data present.
Our model is able to learn this since the classes are shielded tightly enough such that the generated OoC examples are in part also located in the vicinity of the decision boundary.
To better visualize the distribution of generated data, we depict estimated densities of the generated OoC data in the top right panel.
For the aleatoric uncertainty in the top center panel, we observe that due to numerical issues, aleatoric uncertainty increases further away from the in-distribution data.
However this can be accounted for by first considering epistemic uncertainty and then the aleatoric one.
By this procedure, most of the examples close to the decision boundary would be correctly classified as OoD which is also correct since there is only a minor amount of aleatoric uncertainty involved in this example due to moderate sample size not being reflected by the data.
In the bottom row example, an experiment analogous
Note that for data points far away from the in-distribution regime, all C
( i | x, y ) take values close [Figure]
to zero. In practice this requires the inclusion of a small ε > 0 in the denominator to circumvent numerical problems in the logarithmic loss terms.
In our experiments this also results in a high aleatoric uncertainty far away from the in-distribution as all estimated probabilities uniformly take the lower bound’s value ε .
However, a joint consideration of aleatoric and epistemic uncertainty disentangles this, since a high estimated probability of being OoD means that the estimate of aleatoric uncertainty can be neglected.
This also becomes evident in the center panels where one can observe high aleatoric uncertainty H ( x ) outside the in-distribution regime, which can however be masked out by the OoD probability ˜ C
( o | x ) .
Figure 7 shows a toy example on a 3 × 3 grid of Gaussians.
In the top row each Gaussian belongs to its own class, resulting in 9 classes in total, while in the bottom row multiple Gaussians belong to one class, resulting in disconnected class regions.
In both cases our method is able to predict a high aleatoric uncertainty between class boundaries and high epistemic uncertainty away from the training data.
We can also observe the high aleatoric uncertainty far away from the training data as in figure 6, which can also be disentangled by a joint consideration of aleatoric and epistemic uncertainty.
D Hyperparameter Settings for Experiments
For the Bayes-by-Backprop implementation we use spike-and-slap priors in combination with diagonal Gaussian posterior distributions as described in [2].
MC-Dropout uses a 50% dropout probability on all weight layers.
Both mentioned methods average their predictions over 50 forward passes.
The deep-ensembles were built by averaging 5 networks.
Implementations of Confident
Classifier and GEN use the architectures and hyperparameters recommended by the authors and we followed their reference code where possible.
Parameter studies showed that our method is mostly stable w.r.t.
the hyperparameter selection.
We used λ gp = 10 as proposed in [11], λ cl =for MNIST/Tiny Imagenet and λ cl = 4 for CIFAR10/100, λ real = 0 .
6 , λ R = 32 for MNIST/ Tiny ImageNet and λ R = 1 for CIFAR10/100.
The latent dimension for MNIST was set to 32 while using 128 dimensions for CIFAR10/100 and
Tiny ImageNet. We used batch stochastic gradient descent with the ADAM [19] optimizer and a batch size of 256 .
The learning rate was initialized to 10 − 3 for the classification model and 2 · 10 −for the GAN while linearly decaying them to 10 − 5 over the course of all training iterations.
Training on the MNIST dataset required 2 000 generator iterations while taking 10 000 iterations for the CIFAR10/100 and Tiny ImageNet datasets (one iteration is considered to be one gradient step on the generator).
As recommended in [11], we use batch normalization only in the generator, while the critic as well as the classifier do not use any type of layer normalization.
We also adopt the alternating training scheme from the just mentioned work.
For each generator iteration the critic as well as classifier are performing 5 optimization steps on the same batch.
We do apply some mild data augmentation by using random horizontal flipping where appropriate.
The test set sizes used for computing the numerical results can be found in table 6.
Besides the already mentioned LeNet and ResNet architectures for the classification model, the cAE uses a small convolutional architecture for MNIST and a ResNet architecture for CIFAR10/100 and Tiny ImageNet.
The generator and discriminator are both implemented as fully connected networks with (1024 , 512 , 256) neurons for the generator and (512 , 512 , 512) neurons for the discriminator.
We experimented with different sizes of the generator and observed low to no influence on the final performance of the classifier.
All experiments were performed on a Nvidia RTX 3090, Tesla P100 or A100 GPU but models with less VRAM are also sufficient as the cGAN itself is very small.
On the RTX 3090 training takes approximately 50 minutes, 3 hours, 3 . 5 hours and 5 .
5 hours for MNIST, CIFAR10, CIFAR100 and
Tiny ImageNet, respectively.
[Table]
E Parameter Study
In order to examine the influence of hyperparameter selection onto our framework we conducted an extensive experimental study.
We displayed all mentioned evaluation metrics from section 4 while varying λ cl , λ real , λ reg and the chosen latent dimension for the cAE and cGAN.
For λ cl in equation (8), which controls the influence of the classifier predictions onto the generated OoC examples, figureshows clearly that for MNIST λ cl = 2 and for CIFAR10 λ cl = 4 are locally optimal values w.r.t. maximum performance.
While larger λ cl tend to increase the in-distribution accuracy slightly it greatly decreases all other evaluation metrics.
A very interesting observation in figure 10 about the influence of λ real from equation (9) is that both extremes ( λ real ∈ { 0 , 1 } ) are greatly decreasing the results.
This shows clearly that the generated OoC examples have a positive effect on the OoD detection performance and in-distribution separability.
In terms of the dimensionality of the latent space, figure 11 shows that 32 and 128 dimensions are the optimal values for MNIST and CIFAR10, respectively.
This is coherent with the visual quality of the examples decoded by the cAE, which does not improve much with higher dimensions.
Analysing the influence of λ reg in figure 12 one can observe a positive effect on the results on the MNIST dataset by increasing the value of the parameter up to λ reg = 32 where we reach a local maximum.
It is also very apparent, that for λ reg = {+
 the results+} are comparatively bad, emphasizing the role of the low dimensional regularizer in our model.
For CIFAR10 the effect is not as clear as for the MNIST dataset, but figure 12 also shows a locally [Figure] [Figure] b) optimal setting of λ reg ∈ [1 , 2] .
We believe that the higher latent dimension required for the CIFAR dataset and thus the curse of dimensionality is the main factor behind this finding.
Figure 5 shows qualitatively the influence of λ reg on the generated OoC examples.
We can observe that for a training with a higher λ reg we obtain much more diverse examples compared to when using no regularizer. This is especially apparent in the MNIST setting. Figure 8 shows the OoD detection performance w.r.t. AUROC and the accuracy on the in-distribution set while increasing the number of classes present during training.
The hyperparameters as well as all model architectures were kept fixed for this experiment.
We used the Tiny ImageNet dataset with varying class-wise subsets as in-distribution data and the remaining Tiny ImageNet classes,
SVHN, Fashion-MNIST and MNIST datasets as OoD examples.
All methods were trained on our training subset while the figure displays the results on the respective test sets.
For GEN we faced numerical problems with exploding evidence values.
Due to this, we chose different hyperparameter settings for different numbers of classes, which also results in larger standard deviation values for
GEN in tables 5 and 11.
The study shows that increasing the number of classes also increases the
OoD detection performance of our approach. This is also true for GEN, which is why we argue that the gain in performance can in part be attributed to the use of an autoencoder. As the number of classes increases, so does the number of examples in the training dataset, improving the ability of the autoencoder to produce diverse embeddings. When observing the accuracy on the in-distribution data the most apparent observation is that for all methods the accuracy decreases for a higher number of classes.
This is not surprising as we kept the classification model fixed.
In general we observe that our approach with MC-dropout has the overall highest performance, being equal to standard
MC-Dropout and Ensembles from 150 classes and above. Our approach without dropout achieves mid-tier results while still being superior to GEN. F Joint Detection of OoD and FP in the Wild In this section, we perform CIFAR10-based OoD and FP detection in the wild, i.e., we perform both tasks jointly while presenting in-distribution and OoD data in the same mix as in table 3 to the
M e t r i c i n %
M N I S
T
M e t r i c i n %
Accuracy AUROC
AUPR-Out AUROC-S/F
AUPR-In FPR@95TPR
ECE        128 λ cl
M e t r i c i n %        128 λ cl
C
I F
A
R
M e t r i c i n %
[Table]
classifier. To this end, we apply gradient boosting to the uncertainty scores provided by the respective methods to predict TP, FP and OoD. In more detail, we use the following uncertainty scores:
• Ours: OoD uncertainty C ( o | x ) and entropy H ( x ) of the estimated class probabilites • Ours with MC dropout: C ( o | x ) , H ( x ) and the standard deviations of ˆ p ( y | x ) summed over all y = 1 , . . . , n under MC dropout for 50 forward passes.
• One-vs-All Baseline: Same as “Ours”.
• Max softmax: Maximum softmax probability.
• Entropy: Entropy over estimated class probabilities.
• Bayes-by-Backprop: For 50 samples from the posterior we compute a = 1 K (cid:80) K 1 H (ˆ p ( y | x ))
(aleatoric uncertainty) and b = H ( 1 K (cid:80) K {+
+} ˆ p ( y | x )) − a (epistemic uncertainty) as in [18].
• MC-Dropout: Entropy of estimated class probabilities averaged over 50 forward passes, standard deviation of the class probabilities summed over all y = 1 , . . . , n .
[Figure]
c i
[Figure]
• Deep-Ensembles: Entropy of estimated class probabilites averaged over 5 ensemble members, standard deviation of the class probabilities summed over all y = 1 , . . . , n .
• Confident Classifier: Entropy over estimated class probabilities.
• GEN: Entropy over estimated class probabilities resulting of the estimated evidence of the Dirichlet distribution.
The corresponding results are given in table 7 in terms of class-wise accuracy.
While the right-hand half of table 7 presents results for gradient boosting applied to the uncertainty scores of each method, aiming to predict TP, FP and OoD, the left half of the table shows analogous results while additionally using the estimated class probabilities ˆ p ( y | x ) as inputs for gradient boosting.
We do so for the sake of accounting for other possible transformations of ˆ p ( y | x ) that are not explicitly constructed.
The main observations are that our method outperforms the other GAN-based methods and that our method including dropout achieves the overall best performance.
It can be observed that the Entropy Oracle performs very strong while using only a single uncertainty score.
At a second glance, this is not surprising since a FP mostly involves the confusion of two classes while training the DNN to output maximal entropy on OoD examples is likely to result in the confusion of up to five classes, therefore yielding different entropy levels.
Also in the left part as well as the right part of the table, our method including dropout is fairly close the best oracle, which is the entropy oracle.
Apart from the oracle, in both studies including and excluding the estimated class probabilities ˆ p ( y | x ) , our method including
MC-dropout outperforms all other methods.
However, reviewing the result in an absolute sense, there still remains plenty of room for improvement.
G Detailed Results on Individual OoD Datasets
In section 4 we have presented results on the in-distribution datasets MNIST 0-4, CIFAR10 0-4 and
CIFAR100 0-49 versus the entirety of all respective OoD datasets.
To give more detailed insights, this appendix section contains comparisons of the respective in-distribution dataset and each of the single corresponding OoD datasets.
[-Examining the results of our OoD experiments with CIFAR
-]
M e t r i c i n %
M N I S
T
M e t r i c i n %
Accuracy AUROC
AUPR [Figure] Out AUROC-S/F
AUPR-In FPR@95TPR
ECE       512 Latent Dimension
M e t r i c i n %       512 Latent Dimension
C
I F
A
R
[Figure]
t r i [Figure] i
[Figure] dimension The comparison by dataset for the MNIST 0-4 as in-distribution set in the OoD-dataset-wise breakdown given in table 8 shows that we achieve mid-tier results compared to the other methods, except for when MNIST 5-9 is considered as the OoD dataset. In that challenging case, we achieve stronger results compared to the other methods.
Examining the results of our OoD experiments with CIFAR 0-4 being the in-distribution dataset in table 9, it becomes apparent that we consistently outperform all other methods on each single OoD dataset.
The performance gains are particularly pronounced when using the very similar datasets CIFAR10 5-9 and LSUN as OoD datasets.
For CIFAR100 0we have a similar situation as for MNIST, where our approach performs particularly well on the difficult task of CIFAR100 0-49 vs. CIFAR100 50-99 while achieving mid-tier results on the other tasks.
This consistency supports the finding that our method – especially in the case of OoD datasets very similar to the in-distribution dataset – shows the most improvement compared to other methods.
This finding might be to some extent attributable to our tight class shielding.
M e t r i c i n %
M N I S
T
M e t r i c i n %
Accuracy AUROC
AUPR-Out AUROC-S/F
AUPR-In FPR@95TPR
ECE        128 λ reg 82 .85 .
M e t r i c i n %        128 λ reg
C
I F
A
R
M e t r i c i n %
[Table] [Table]
[Table] [Table]