B AYESIAN
U NCERTAINTY
E STIMATION FOR B ATCH N ORMALIZED D EEP N ETWORKS
Anonymous authors
Paper under double-blind review
A BSTRACT
Deep neural networks have led to a series of breakthroughs, dramatically improving the state-of-the-art in many domains.
The techniques driving these advances, however, lack a formal method to account for model uncertainty.
While the Bayesian approach to learning provides a solid theoretical framework to handle uncertainty, inference in Bayesian-inspired deep neural networks is difﬁcult.
In this paper we provide a practical approach to Bayesian learning that relies on a regularization technique found in nearly every modern network, batch normalization.
We show that training a deep network using batch normalization is equivalent to approximate inference in Bayesian models and we demonstrate how this ﬁnding allows us to make useful estimates of the model uncertainty.
Using our approach, it is possible to make meaningful uncertainty estimates using conventional architectures without modifying the network or the training procedure.
Our approach is thoroughly validated in a series of empirical experiments on different tasks and using various measures, showing it to outperform baselines on a majority of datasets with strong statistical signiﬁcance.
I NTRODUCTION
Deep learning has dramatically advanced the state of the art in a number of domains, and now surpasses human-level performance for certain tasks such as recognizing the contents of an image (He et al., 2015) and playing Go (Silver et al., 2017).
But, despite their unprecedented discriminative power, deep networks are prone to make mistakes.
Sometimes, the consequences of mistakes are minor – misidentifying a food dish or a species of ﬂower (Liu et al., 2016) may not be life threatening.
But deep networks can already be found in settings where errors carry serious repercussions such as autonomous vehicles (Chen et al., 2016) and high frequency trading.
In medicine, we can soon expect automated systems to screen for skin cancer (Esteva et al., 2017), breast cancer (Shen, 2017), and to diagnose biopsies (Djuric et al., 2017).
As autonomous systems based on deep learning are increasingly deployed in settings with the potential to cause physical or economic harm, we need to develop a better understanding of when we can be conﬁdent in the estimates produced by deep networks, and when we should be less certain.
Standard deep learning techniques used for supervised learning lack methods to account for uncertainty in the model, although sometimes the classiﬁcation network’s output vector is mistakenly understood to represent the model’s uncertainty.
The lack of a conﬁdence measure can be especially problematic when the network encounters conditions it was not exposed to during training.
For example, if a network trained to recognize dog breeds is given an image of a cat, it may predict it to belong to a breed of small dog with high probability.
When exposed to data outside of the distribution it was trained on, the network is forced to extrapolate, which can lead to unpredictable behavior.
In such cases, if the network can provide information about its uncertainty in addition to its point estimate, disaster may be avoided.
This work focuses on estimating such predictive uncertainties in deep networks (Figure 1).
The Bayesian approach provides a solid theoretical framework for modeling uncertainty (Ghahramani, 2015), which has prompted several attempts to extend neural networks (NN) into a Bayesian setting.
Most notably, Bayesian neural networks (BNNs) have been studied since the 1990’s (Neal, 2012).
Although they are simple to formulate, BNNs require substantially more computational resources than their non-Bayesian counterparts, and inference is difﬁcult.
Importantly, BNNs do
[Figure]
not scale well and struggle to compete with modern deep learning architectures.
Recently, Gal &
Ghahramani (2015) developed a practical solution to obtain uncertainty estimates by casting dropout training in conventional deep networks as an approximate Bayesian model.
They showed that any network trained with dropout is an approximate Bayesian model, and uncertainty estimates can be obtained by computing the variance on multiple predictions with different dropout masks.
This technique, called Monte Carlo Dropout (MCDO), has a very attractive quality: it can be applied to existing NNs without any modiﬁcation to the architecture or the way the network is trained.
Uncertainty estimates come (nearly) for free.
However, in recent years dropout has fallen out of favor, limiting MCDO’s utility.
Google’s Inception network, which won ILSVRC in 2014, did not use dropout (Szegedy et al., 2015), nor did the ILSVRC 2015 winner, Microsoft’s residual learning network (He et al., 2016).
In place of traditional techniques like dropout, most modern networks such as Inception and ResNet have adopted other regularization techniques.
In particular, batch normalization (BN) has become widespread thanks to its ability to stabilize learning with improved generalization (Ioffe & Szegedy, 2015).
An interesting aspect of BN is that the mini-batch statistics used for training each iteration depend on randomly selected batch members.
We exploit this stochasticity and show that training using batch normalization, like dropout, is equivalent to approximate inference in Bayesian models 1 .
We demonstrate how this ﬁnding allows us to make meaningful estimates of the model uncertainty in a technique we call Monte Carlo Batch Normalization (MCBN)
(Figure 1).
The method we propose makes no simplifying assumptions on the use of batch normalization, and applies to any network using BN as it appears in practical applications.
We validate our approach by empirical experiments on eight standard datasets used for uncertainty estimation.
We measure uncertainty quality relative to a baseline of ﬁxed uncertainty, and show that
MCBN outperforms the baseline on nearly all datasets with strong statistical signiﬁcance.
We also show that the uncertainty quality of MCBN is on par with that of MCDO.
As a practical demonstration of MCBN, we apply our method to estimate segmentation uncertainty using a conventional segmentation network (Badrinarayanan et al., 2015).
Finally, as part of our evaluation, we make contributions to the methodology of measuring uncertainty quality by deﬁning performance bounds on existing metrics and proposing a new visualization that provides an intuitive understanding of uncertainty quality.
R ELATED W ORK
Bayesian models provide a natural framework for modeling uncertainty, and several approaches have been developed to adapt NNs to Bayesian reasoning.
A common approach is to place a prior distribution (often a Gaussian) over each weight.
For inﬁnite weights, the resulting model corresponds to a Gaussian process (Neal, 1995), and for a ﬁnite number of weights it corresponds to a Bayesian neural network (MacKay, 1992).
Although simple to formulate, inference in BNNs is difﬁcult (Gal, 2016).
Therefore, focus has shifted to techniques to approximate the posterior distribution, leading to approximate BNNs .
Methods based on variational inference (VI) typically rely on a fully factorized approximate distribution (Kingma & Welling, 2014; Hinton & Van Camp, 1993) but these methods do not scale easily.
To alleviate these difﬁculties, Graves (2011) proposed a model using sampling methods to estimate a factorized posterior.
Another approach, probabilistic backpropagation (PBP), also estimates a factorized posterior based on expectation propagation (Hern´andez-Lobato & Adams, 2015).
Deep Gaussian Processes (DGPs) formulate GPs as Bayesian models capable of working on large datasets with the aid of a number of strategies to address scaling and complexity requirements (Bui et al., 2016).
The authors compare DGP with a number of state-of-the-art approximate BNNs, showing superior performance in terms of RMSE and uncertainty quality 2 .
Another recent approach to Bayesian learning, Bayesian hypernetworks, use a neural network to learn a distribution of paramaters over another neural network (Krueger et al., 2017).
Although these recent techniques address some of the difﬁculties with approximate BNNs, they all require modiﬁcations to the architecture or the way networks are trained, as well as specialized knowledge from practitioners.
Recently, Gal (2016) showed that a network trained with dropout implicitly performs the VI objective.
Therefore any network trained with dropout can be treated as an approx.
Bayesian model by making multiple predictions as forward passes through the network while sampling different dropout masks for each prediction.
An estimate of the posterior can be obtained by computing the mean and variance of the predictions.
This technique, referred to here as MCDO, has been empirically demonstrated to be competitive with other approx.
BNN methods and DGPs in terms of
RMSE and uncertainty quality (Li & Gal, 2017).
However, as the name implies, MCDO depends on dropout.
While once ubiquitous in training deep learning models, dropout has largely been replaced by batch normalization in modern networks, limiting its usefulness.
M ETHOD
The methodology of this work is to pose a deep network trained with batch normalization as a
Bayesian model in order to obtain uncertainty estimates associated with its predictions.
In the following, we brieﬂy introduce Bayesian models and a variational approximation to it using KullbackLeibler (KL) divergence following Gal & Ghahramani (2015).
We continue by showing a batch normalized deep network can be seen as an approximate Bayesian model.
Then, by employing theoretical insights as well as empirical analysis, we study the induced prior on the parameters when using batch normalization.
Finally, we describe the procedure we use for estimating uncertainty of batch normalized deep networks’ output.
3. B AYESIAN M ODELING
We assume a ﬁnite training set D
= { ( x i , y i ) } i =1: N where each ( x i , y i ) is a sample-label pair.
Using D , we are interested in learning an inference function f ω ( x , y ) with parameters ω .
In deterministic models, the estimated label ˆy is obtained as follows:
[Equation]
We assume f ω ( x , y )
=
p ( y | x , ω ) (e.g. in soft-max classiﬁers), and is normalized to a proper probability distribution.
In Bayesian modeling, in contrast to ﬁnding a point estimate of the model parameters, the idea is to estimate an (approximate) posterior distribution of the model parameters p ( ω | D ) to be used for probabilistic prediction:
[Equation]
The predicted label, ˆy , can then be accordingly obtained by sampling p ( y | x , D ) or takings its maxima.
Variational Approximation In approximate Bayesian modeling, it is a common approach to learn a parametrized approximating distribution q θ ( ω )
that minimizes KL ( q θ ( ω ) ||
p ( ω | D )) ; the
Kullback-Leibler (KL) divergence of posterior w.r.t.
its approximation, instead of the true posterior.
Minimizing this KL divergence is equivalent to the following minimization while being free of the data term p ( D ) 3 :
[Equation]
Using Monte Carlo integration to approximate the integral with one realized ˆ
ω
i for each sample i 4 , and optimizing over mini-batches of size M , the approximated objective becomes:
[Equation]
The ﬁrst term is the data likelihood and the second term is divergence of the model prior w.r.t.
the approximated distribution.
We now describe the optimization procedure of a deep network with batch normalization and draw the resemblance to the approximate Bayesian modeling in Eq (1).
3. B ATCH N ORMALIZED D EEP N ETS AS B AYESIAN M ODELING
The inference function of a feed-forward deep network with L layers can be described as:
[Equation]
where a ( . ) is an element-wise nonlinearity function and W l is the weight vector at layer l .
Furthermore, we denote the input to layer l as x l with x 1 = x
and we then set h l = W l x l .
Parenthesized super-index for matrices (e.g. W ( j ) ) and vectors (e.g. x ( j ) ) indicates j th row and element respectively.
Super-index u refers to a speciﬁc unit at layer l , (e.g. W u = W l, ( j ) , h u = h l, ( j ) ).
Batch Normalization Each layer of a deep network is constructed by several linear units whose parameters are the rows of the weight matrix W .
Batch normalization is a unit-wise operation proposed in Ioffe & Szegedy (2015) to standardize the distribution of each unit’s input.
It essentially converts a unit’s output h u in the following way:
[Equation]
where the expectations are computed over the training set 6 .
However, often in deep networks, the weight matrices are optimized using back-propagated errors calculated on mini-batches of data.
Therefore, during training, the estimated mean and variance on the mini-batch B is used, which we denote by µ B and σ B respectively.
This makes the inference at training time for a sample x a stochastic process, varying based on other samples in the mini-batch.
Loss Function and Optimization Training deep networks with mini-batch optimization involves a (regularized) risk minimization with the following form:
[Equation]
Where the ﬁrst term is the empirical loss on the training data and the second term is a regularization penalty acting as a prior on model parameters ω .
If the loss l is cross-entropy for classiﬁcation or sum-of-squares for regression problems (assuming i.i.d.
Gaussian noise on labels), the ﬁrst term is equivalent to minimizing the negative log-likelihood:
[Equation]
with τ = 1 for classiﬁcation.
In a batch normalized network the model parameters are { W 1: L , γ 1: L , β 1: L , µ 1: L B , σ 1: L B } .
If we decouple the learnable parameters θ = { W 1: L , γ 1: L , β 1: L } from the stochastic parameters ω
= { µ 1: L B , σ 1: L B } , we get the following objective at each step of the mini-batch optimization of a batch normalized network:
[Equation]
where ˆ ω i is the mean and variances for sample i ’s mini-batch at a certain training step.
Note that while ˆ ω i formally needs to be i.i.d.
for each training example, a batch normalized network samples the stochastic parameters once per training step (mini-batch).
For a large number of epochs, however, the distribution of sampled batch members for a given training example converges to the i.i.d. case.
Comparing Eq.
(1) and Eq.
(2) reveals that the optimization objectives are identical, if there exists a prior p ( ω ) corresponding to Ω( θ ) such that ∂∂θ KL ( q θ ( ω ) || p ( ω ))
=
Nτ ∂∂θ Ω( θ ) .
In a batch normalized network, q θ ( ω ) corresponds to the joint distribution of the normalization parameters µ 1: L B , σ 1: L B , as implied by the repeated sampling from D during training.
This is an approximation of the true posterior, where we have restricted the posterior to lie within the domain of our parametric network and source of randomness.
With that we can use a pre-trained batch normalized network to estimate the uncertainty of its prediction using the inherent stochasticity of BN.
Before that, we brieﬂy discuss what Bayesian prior is induced in a typical batch normalized network.
3. P RIOR p ( ω )
The purpose of Ω( θ ) is to reduce variance in deep networks.
L2-regularization, also referred to as weight decay ( Ω( θ ) =
λ (cid:80) l =1: L || W l || 2 ), is a popular technique in deep learning.
The induced prior from L2-regularization is studied in Appendix 6.5.
Under some approximations as outlined in the
Appendix, we ﬁnd that BN for a deep network with FC layers and ReLU activations induce Gaussian distributions over BN unit’s means and standard deviations, centered around the population values given by D (Eq.
(6), details in Appendix 6.3).
Factorizing this distribution across all stochastic parameters and assuming Gaussian priors, we ﬁnd the approximate corresponding priors:
[Equation]
where J l − 1 is the dimensionality of the layer’s inputs and x is the average input over D for all input units.
In the absence of scale and shift transformations from the previous BN layer, it converges towards an exact prior for large training datasets and deep networks (under the assumptions of the factorized distribution).
The mean and variance for the BN unit’s standard deviation, µ p and σ 2 p , have no relevance for the reconciliation of optimization objectives of
3. P REDICTIVE U NCERTAINTY IN B ATCH N ORMALIZED D EEP N ETS
In the absence of the true posterior we rely on the approximate posterior to express an approximate predictive distribution:
[Equation]
Following Gal & Ghahramani (2015) we estimate the ﬁrst and second moment of the predictive distribution empirically (see Appendix 6.4 for details).
For regression, the ﬁrst two moments are:
[Equation]
where each ˆ ω i corresponds to sampling the net’s stochastic parameters
ω
= { µ 1: L B , σ 1: L B } the same way as during training.
Sampling ˆ ω i therefore involves sampling a batch B from the training set and updating the parameters in the BN units, just as if we were taking a training step with B .
Recall that from a VA perspective, training the network amounted to minimizing KL ( q θ ( ω ) || p ( ω | D ))
wrt θ .
Sampling ˆ ω
i from the training set, and keeping the size of B consistent with the mini-batch size used during training, ensures that q θ ( ω ) during inference remains identical to the approximate posterior optimized during training.
After each update of the net’s stochastic parameters, we take a forward pass with input x , producing output f
ˆ ω
i ( x ) .
After T such stochastic forward passes, we compute the mean and sample variance of outputs to ﬁnd the mean E p ∗ [ y ] and variance Cov p ∗ [ y ] of the approximate predictive distribution.
Note that Cov p ∗ [ y ] also requires addition of constant variance from observation noise, τ − 1 I .
The network is trained just as a regular BN network.
The difference is in using the trained network for prediction.
Instead of replacing ω = { µ 1: L B , σ 1: L B } with population values from D , we update these parameters stochastically, once for each forward pass .
The form of p ∗ can be approximated by a Gassuian for each output dimension (for regression).
We assume bounded domains for each input dimension, wide layers throughout the network, and a unimodal distribution of weights centered at 0.
By the Liapounov CLT condition, the ﬁrst layer then receives approximately Gaussian inputs (a proof can be found in Lehmann (1999)).
Having sampled µ u B and σ u B from a mini-batch, each BN unit’s output is bounded.
CLT thereby continues to hold for deeper layers, including f ω ( x ) =
W L x L .
A similar motivation for a Gaussian approximation of
Dropout has been presented by Wang & Manning (2013).
The actual form of p ∗ is likely to be highly multimodal, as can be seen immediately from f ω ( x ) =
W L x L with elements in x L normalized, scaled and shifted differently.
Gal & Ghahramani (2015) note the multimodality as well, since MCDO implies a bimodal variational distribution over each weight matrix column.
E XPERIMENTS AND R ESULTS
We assess the uncertainty quality of MCBN quantitatively and qualitatively.
Our quantitative analysis relies on eight standard regression datasets, listed in Table 1.
Publicly available from the
UCI Machine Learning Repository (University of California, 2017) and Delve (Ghahramani, 1996), these datasets have been used to benchmark comparative models in recent related literature (see
Hern´andez-Lobato & Adams (2015), Gal & Ghahramani (2015), Bui et al.
and Li & Gal (2017)).
We report results using standard metrics, and also propose useful upper and lower bounds to normalize these metrics for a more meaningful interpretation in Section 4.2.
This would alleviate having to store D for use during prediction.
In our experiments we used D to sample ˆ ω
i however, and leave the evaluation of the modeled q θ ( ω ) for future research.
[Table]
Our qualitative results consist of three parts.
First, in Figure 1 we demonstrate that MCBN produces reasonable uncertainty bounds on a toy dataset in the style of (Karpathy, 2015).
Second, we develop a new visualization of uncertainty quality by plotting test errors sorted by predicted variance in
Figure 2.
Finally, we apply MCBN to SegNet (Kendall et al., 2015), demonstrating the beneﬁts of
MCBN in an existing batch normalized network.
4. M ETRICS
We evaluate uncertainty quality based on two metrics, described below: Predictive Log Likelihood (PLL) and Continuous Ranked Probability Score (CRPS).
We also propose upper and lower bounds for these metrics which can be used to normalize them and provide a more meaningful interpretation.
Predictive Log Likelihood (PLL) Predictive Log Likelihood is a widely accepted metric for uncertainty quality, used as the main uncertainty quality metric for regression (e.g. (Hern ´ andez-Lobato & Adams, 2015), (Gal & Ghahramani, 2015), (Bui et al., 2016) and (Li & Gal, 2017)).
A key property is that PLL makes no assumtions about the form of the distribution.
The measure is deﬁned for a probabilistic model f ω ( x ) and a single observation ( y i , x i ) as:
[Equation]
, x i
[Equation] [Equation]
where p ( y i | f ω ( x i )) is the model’s predicted PDF evaluated at y i , given the input x i .
A more detailed description is given in Appendix 6.4.
The metric is unbounded and maximized by a perfect prediction (mode at y i ) with no variance.
As the predictive mode moves away from y i , increasing the variance tends to increase PLL (by maximizing probability mass at y i ).
While PLL is an elegant measure, it has been criticized for allowing outliers to have an overly negative effect on the score (Selten, 1998).
Continuous Ranked Probability Score (CRPS) Continuous Ranked Probability Score is a less sensitive measure that takes the full predicted PDF into account.
A prediction with low variance that is slightly offset from the true observation will receive a higher score form CRPS than PLL.
In order for CRPS to be analytically tractable, we need to assume a Gaussian unimodal predictive distribution.
CRPS is deﬁned as
[Equation]
where F ( y ) is the predictive CDF, and 1 ( y ≥ y i )
=
if y ≥ y i and 0 otherwise (for univariate distributions) (Gneiting & Raftery, 2007).
CRPS is interpreted as the sum of the squared area between the CDF and 0 where y < y i and between the CDF and 1 where y ≥ y
i .
A perfect prediction with no variance yields a CRPS of 0; for all other cases the value is larger.
CRPS has no upper bound.
4. B ENCHMARK MODELS AND NORMALIZED METRICS
In order to establish a lower bound on useful performance for uncertainty estimates, we deﬁne a baseline that predicts constant variance regardless of input.
This benchmark model produces identical point estimates as MCBN, which yield the same predictive means.
The variance is set to a ﬁxed value that optimizes CRPS on validation data.
This model reﬂects our best guess of constant variance on test data - any improvement in uncertainty quality from MCBN would indicate a sensible estimate of uncertainty.
We call this model Constant Uncertainty BN (CUBN).
Implementing
MCDO as a comparative model, we similarly deﬁne a baseline for dropout, Constant Uncertainty
Dropout (CUDO).
The difference in variance modeling between MCBN, CUBN, MCDO and CUDO are visualized in plots of uncertainty bounds on toy data in Figure 1.
For a probabilistic model f , an upper bound on uncertainty performance can also be deﬁned for
CRPS and PLL.
For each observation ( y i , x i ) , a value for the predictive variance T i can be chosen that maximizes PLL or minimizes CRPS 8 .
Using CUBN as a lower bound and the optimized
CRPS score as the upper bound, uncertainty estimates can be normalized between these bounds ( indicating optimal performance, and 0 indicating performance on par with ﬁxed uncertainty).
We call this normalized measure CRPS =
[Equation]
100 , and the PLL analogue PLL =
[Equation]
This normalized measure gives an intuitive understanding of how close a Bayesian model is to estimating the perfect uncertainty for each prediction.
We also evaluate CRPS and PLL for an adaptation of the authors’ implementation of Multiplicative
Normalizing Flows (MNF) for variational Bayesian networks (Louizos & Welling, 2017).
This is a recent model specialized to allow a more ﬂexible posterior what is achievable by e.g. MCDO’s bimodal variational over weight columns.
MNF uses auxillary variables on which the posterior is a latent.
By applying normalizing ﬂows to the auxillary variable such that it can take on complex distributions, the approximate posterior becomes highly ﬂexible.
4. TEST SETUP
Our evaluation of MCBN and MCDO is largely comparable to that of Hern ´ andez-Lobato & Adams (2015), in that we use similar datasets and metrics.
This setup was later also followed by Gal & Ghahramani (2015), where we in comparison implement a different hyperparameter selection, allow for a larger range of dropout rates, and use larger networks with two hidden layers.
With the exception of Protein Tertiary Structure 9 , all our models share a similar architecture: two hidden layers with 50 units each, using ReLU activations.
Input and output data were normalized during training.
Results were averaged over ﬁve random splits of 20% test and 80% training and cross-validation (CV) data.
For each split, 5-fold CV by grid search with a RMSE minimization objective was used to ﬁnd training hyperparameters and optimal n.o. epochs.
For BN-based models, the hyperparameter grid consisted of a weight decay factor ranging from 0 .
1 to 1 − 15 by a log 10 scale, and a batch size range from 32 to 1024 by a log 2 scale.
For DO-based models, the hyperparameter grid consisted of the same weight decay range, and dropout probabilities in { 0 . 2 , 0 . 1 , 0 . 05 , 0 . 01 , 0 . 005 , 0 . 001 } .
DO-based models used a batch size of 32 in all evaluations.
The model with optimal training hyperparameters was used to optimize τ numerically.
This optimization was made in terms of average CV CRPS for MCBN, CUBN, MCDO, and CUDO respectively, before evaluation on the test data.
All estimates for the predictive distribution were obtained by taking 500 stochastic forward passes through the network, throughout training and testing.
The implementation was done with TensorFlow.
The Adam optimizer was used to train all networks, with a learning rate of 0.001.
The extensive part of the experiments (i.e. training and cross validation) was done on Amazon web services using 3000 machine-hours.
All code necessary for reproducing both the quantitative and qualitative results is released in an anonymous github repository (https://github.com/iclr-mcbn/mcbn).
4. TEST RESULTS
A summary of the results measuring uncertainty quality of MCBN, MCDO and MNF are provided in Table 2.
Tests are run over eight datasets using 5 random 80-20 splits of the data with 5 different random seeds each split.
We report CRPS and PLL, expressed as a percentage, which reﬂects how close the model is to the upper bound.
The upper bounds and lower bounds for each metric are de-
[Table]
[Figure]
scribed in Section 4.2.
We check to see if the reported values of CRPS and PLL signiﬁcantly exceed the lower bound models (CUBN and CUDO) using a one sample t-test, where the signiﬁcance level is indicated by *’s.
Further details from the experiment are available in Appendix 6.6.
In Figure 2, we provide a novel visualization of uncertainty
Qualitative results for Bayesian SegNet using MCBN was produced by using the main CamVid model in Kendall et al.
The pre-trained model was obtained from the online model zoo and was used without modiﬁcation.
10 instances of mini-batches with size 6 were used to estimate the mean and variance of MCBN.
Qualitative results can be found in Figure 3 depicting intuitive uncertainty at object boundaries.
Quantitative measures on various segmentation datasets can be obtained and is beyond the scope of this work.
We provide additional experimental results in Appendix 6.6.
In Tables 3 and 4, we show the mean
CRPS and PLL values for MCBN and MCDO.
These results indicate that MCBN performs on par with MCDO across several datasets.
In Table 6 we provide RMSE results of the MCBN and
MCDO networks in comparison with non-stochastic BN and DO networks.
These results indicate that the procedure of multiple forward passes in MCBN and MCDO show slight improvements in the predictive accuracy of the network.
D ISCUSSION
The results presented in Table 2 and Appendix 6.6 indicate that MCBN generates meaningful uncertainty estimates which correlate with actual errors in the model’s prediction.
We show statistically signiﬁcant improvements over CUBN in the majority of the datasets, both in terms of CRPS and
PLL.
The visualizations in Figure 2 and in Appendix 6.6 show clear correlations between the estimated model uncertainty and actual errors produced by the network.
We perform the same experiments using MCDO, and ﬁnd that MCBN generally performs on par with MCDO.
Looking closer, in terms of CRPS, MCBN performs better than MCDO in more cases than not.
However, care must be used when comparing different models.
The learned network parameters are different, leading to different predictive means which can confound direct comparison.
The results on the Yacht Hydrodynamics dataset seem contradictory.
The CRPS score for MCBN is extremely negative, while the PLL score is extremely positive.
The opposite trend is observed for MCDO.
To add to the puzzle, the visualization in Figure 2 depicts an extremely promising uncertainty estimation that models the predictive errors with high ﬁdelity.
We hypothesize that this strange behavior is due to the small size of the data set, which only contains 60 test samples, or due to the Gaussian assumption of CRPS.
There is also a large variability in the model’s accuracy on this dataset, which further confounds the measurements for such limited data.
One might criticize the overall quality of the uncertainty estimates of MCBN and MCDO based on the magnitude of the CRPS and PLL scores in Table 2.
The scores rarely exceed 10% improvement over the lower bound.
However, we caution that these measures should be taken in context.
The upper bound is very difﬁcult to achieve in practice (it is optimized for each test sample individually ), and the lower bound is a quite reasonable estimate for uncertainty.
We have further compared against the recent work of Louizos & Welling (2017), and ﬁnd comparable results to their MNF-based variational technique speciﬁcally targeted to increase the ﬂexibility of the approximate posterior.
Our approximation of the implied prior in Appendix 6.5 also provides a new interpretation of the empirical evidence that signiﬁcantly lower λ should be used in batch normalized networks (Ioffe &
Szegedy, 2015).
From a VA perspective, too strong a regularization for a given dataset size could be seen as constraining the prior distribution of BN units’ means, effectively narrowing the approximate posterior.
In this work, we have shown that training a deep network using batch normalization is equivalent to approximate inference in Bayesian models.
Using our approach, it is possible to make meaningful uncertainty estimates using conventional architectures without modifying the network or the training procedure.
We show evidence that the uncertainty estimates from MCBN correlate with actual errors in the model’s prediction, and are useful for practical tasks such as regression or semantic image segmentation.
Our experiments show that MCBN yields an improvement over the baseline of optimized constant uncertainty on par with MCDO and MNF.
Finally, we make contributions to the evaluation of uncertainty quality by suggesting new evaluation metrics based on useful baselines and upper bounds, and proposing a new visualization tool which gives an intuitive visual explanation of uncertainty quality.
Finally, it should be noted that, over the past few years, batch normalization has become an integral part of most-if-not-all cutting edge deep networks which signiﬁes the relevance of our work for estimating model uncertainty.
A PPENDIX 6. V ARIATIONAL A PPROXIMATION
Assume we were to come up with a faimly of distributions parametrised by θ in order to approximate the posterior, q θ ( ω ) .
Our goal is to set θ such that q θ ( ω ) is as similar to p ( ω | D ) as possible.
One strategy is to minimizing KL ( q θ ( ω )
|| p ( ω | D )) , the KL divergence of p ( ω | D )
wrt q θ ( ω ) .
Minimizing KL ( q θ ( ω ) || p ( ω | D )) is equivalent to maximizing the ELBO:
[Equation]
Assuming i.i.d.
observation noise, this is equivalent to minimizing:
[Equation]
Instead of making the optimization on the full training set, we can use a subsampling (yielding an unbiased estimate of L VA ( θ ) ) for iterative optimization (as in mini-batch optimization):
[Equation]
We now make a reparametrisation: set ω =
g ( θ , (cid:15) ) where (cid:15) is a RV.
The function g and the distribution of (cid:15) must be such that p ( g ( θ , (cid:15) ))
=
q θ ( ω ) .
Assume q θ ( ω ) can be written (cid:82) (cid:15) q θ ( ω | (cid:15) ) p ( (cid:15) )
d (cid:15) where q θ ( ω | (cid:15) )
=
δ ( ω − g ( θ , (cid:15) )) .
Using this reparametrisation we get:
[Equation]
6. KL D IVERGENCE OF FACTORIZED G AUSSIANS
If q θ ( ω ) and p ( ω ) factorize over all stochastic parameters:
[Equation]
such that KL ( q θ ( ω ) || p ( ω )) is the sum of the KL divergence terms for the individual stochastic parameters ω i .
If the factorized distributions are Gaussians, where q θ ( ω i ) =
N ( µ q , σ 2 q ) and p ( ω i ) =
N ( µ p , σ 2 p ) we get:
[Equation]
for each KL divergence term.
Here H ( q θ ( ω i ))
= 12 (1 + ln(2 πσ 2 q )) is the differential entropy of q θ ( ω i ) .
6. D ISTRIBUTION OF µ u B , σ u B
Here we approximate the distribution of mean and standard deviation of a mini-batch, separately to two Gaussians.
For the mean we get:
[Equation]
where x m are the examples in the sampled batch.
We will assume these are sampled i.i.d.
Samples of the random variable W ( j ) x m are then i.i.d..
Then by central limit theorem (CLT) the following holds for sufﬁciently large M (often ≥ 30 ):
[Equation]
For standard deviation:
[Equation]
Then
[Equation]
We want to rewrite (cid:113) Σ
[Equation]
=1 ( W
[Equation]
x
[Equation]
We take a Taylor expansion of f ( x ) = √ x around a = σ 2 .
With x = Σ Mm =
( W
[Equation]
j
[Equation]
x
[Equation]
µ B
[Equation]
2 M :
[Equation]
so
[Equation]
consider Σ Mm
=1 ( W ( j ) x m − µ B ) 2 .
We know that E [ W ( j ) x m ] = µ and write Σ Mm =1 ( W ( j ) x m − µ B )=
Σ Mm=1 (( W ( j ) x m − µ ) − ( µ B − µ ))=
Σ Mm=1 (( W ( j ) x m − µ ) 2 + ( µ B − µ ) 2 − 2( W ( j ) x m − µ )( µ B − µ )) = Σ Mm=1 ( W ( j ) x m − µ ) 2 + M ( µ B − µ ) 2 − 2( µ B − µ )Σ Mm=1 ( W ( j ) x m − µ ) =
Σ Mm=1 ( W ( j ) x m − µ ) 2 − M ( µ B − µ )=
Σ Mm=1 (( W (
[Table]
−
[Table]
−
[Table] [Table]
then
[Equation]
We go through each term in turn
Term A
We have
[Equation]
where Σ Mm=1 ( W ( j ) x m − µ ) 2 is the sum of M RVs ( W ( j ) x m − µ ) 2 .
Note that since E [ W ( j ) x m ] =
µ
it holds that E [( W ( j ) x m − µ ) 2 ] = σ 2 .
Since ( W ( j ) x m − µ ) 2 is sampled approximately iid (by assumptions above), for large enough M by CLT it holds approximately that
[Equation]
where
Var( ( W ( j ) x m − µ ) 2 ) =
E [
[Equation]
Then Σ
[Equation]
so
Term A
[Equation] [Equation]
Term B
We have
[Equation]
Consider ( µ B − µ ) .
As µ B p −→ µ when M → ∞ we have µ B − µ p −→ 0 .
We also have
[Equation]
which by CLT is approximately Gaussian for large M .
We can then make use of the Cramer-Slutzky
Theorem, which states that if ( X n ) n ≥ 1 and ( Y n ) n ≥ 1 are two sequences such that X n d −→ X
and
Y n p −→ a as n → ∞ where a is a constant, then as n → ∞ , it holds that X n ∗ Y n d −→ X ∗ a .
Thus,
Term B is approximately 0 for large M.
Term C
We have
[Equation]
Since E [( W ( j ) x m − µ ) 2 ] = σ 2 we can make the same use of Cramer-Slutzky as for Term B , such that Term C is approximately 0 for large M.
Finalizing the distribution
We have approximately
[Equation]
so
[Equation]
6. PREDICTIVE DISTRIBUTION PROPERTIES
This section provides derivations of properties of the predictive distribution p ∗ ( y | x , D ) in section 3.4, following Gal (2016).
We ﬁrst ﬁnd the approximate predictive mean and variance for the approximate predictive distribution, then show how to estimate the predictive log likelihood, a measure of uncertainty quality used in the evaluation 4.
Predictive mean Assuming Gaussian iid noise deﬁned by model precision τ , i.e. f ω ( x , y ) =
p
[Equation]
y | f ω ( x ))
=
N
[Equation]
y
[Equation]
f ω
[Equation] [Equation]
I ) :
[Equation]
where we take the MC Integral with T samples of ω for the approximation in the ﬁnal step.
Predictive variance Our goal is to estimate:
[Equation]
We ﬁnd that:
[Equation]
where we use MC integration with T samples for the ﬁnal step.
The predictive covariance matrix is given by:
[Equation]
which is the sum of the variance from observation noise and the sample covariance from T stochastic forward passes though the network.
Predictive Log Likelihood We use the Predictive Log Likelihood (PLL) as a measure to estimate the model’s uncertainty quality.
For a certain test point ( y i , x i ) , the PLL deﬁnition and approximation can be expressed as:
[Equation]
where ˆ ω j represents a sampled set of stochastic parameters from the approximate posterior distrubtion q θ ( ω ) and we take a MC integration with T samples.
For regression, due to the iid Gaussian noise, we can further develop the derivation into the form we use when sampling:
[Equation]
Note that PLL makes no assumption on the form of the approximate predictive distribution.
The measure is based on repeated sampling ˆ ω j from q θ ( ω ) , which may be highly multimodal (see section 3.4).
6. P RIOR
We assume training by SGD with mini-batch size M , L2-regularization on weights and Fully Connected layers.
With θ k ∈ θ , equivalence between the objectives of Eq.
(1) and (2) then requires:
[Equation]
To proceed with the LHS of Eq.
(5) we ﬁrst need to ﬁnd the approximate posterior q θ ( ω ) that batch normalization induces.
As shown in Appendix 6.3, with some weak assumptions and approximations the Central Limit Theorem (CLT) yields Gaussian distributions of the stochastic variables µ u B , σ u B , for large enough M :
[Equation]
where µ u and σ u are the population-level moments (i.e. moments over D ), and h u is the BN unit’s input.
We use i as an index of the set of stochastic variables, i.e. ω i ∈ { µ 1: L B , σ 1: L B } , and denote by ω li the stochastic variables in a certain layer, ω li ∈ { µ l B , σ l B } .
We assume q θ ( ω ) and p ( ω ) factorize over all individual ω i , i.e. independence between all stochastic variables.
As shown in Eq.
(3) in
Appendix 6.2, the factorized distributions yield:
[Equation]
Note that each BN unit produces two KL ( q θ ( ω i )
|| p ( ω i ))
terms: one for ω i = µ u B and one for ω
i =
σ u B .
We assume a Gaussian prior p ( ω i ) =
N ( µ p , σ 2 p ) and, for consistency, use the notation q θ ( ω i ) =
N ( µ q , σ 2 q ) .
As shown in Eq.
(4) in Appendix 6.2:
[Equation]
Then, letting ( · ) (cid:48) denote ∂ ∂θ k ( · ) :
[Equation]
where the last step makes use of the fact that µ (cid:48) p = 0 and σ (cid:48)
p = 0 (as p ( ω i ) cannot depend on θ k , which changes during training).
We assume that only parameters preceding a BN unit in the same layer affects the unit’s stochastic parameters, such that the stochastic variables in the j :th BN unit are only affected by weights in θ k ∈ W l, ( j ) .
Let the vector of average inputs over D from the preceding layers be denoted by ¯ x .
We denote a weight connecting the m :th input unit to the j :th BN unit by W ( j,m ) .
For such weights,
[Figure]
we need to derive µ (cid:48) q and σ (cid:48) q , for both ω i = µ u B and ω i = σ u B .
Starting with ω i = µ u B :
[Equation]
NM
[Equation]
NM =
Using the result that σ (cid:48) q = 0 , one can easily ﬁnd for ω
i =
σ u B that µ (cid:48) q = 0 and σ (cid:48)
q = 0 , nullifying
Eq.
We need only consider the partial derivatives of the KL divergence terms where ω i = µ u B .
If we let µ p = 0 , Eq.
(7) reduces to:
[Equation]
for each BN unit and connecting weights from the previous layer, W ( j,m ) .
Taking partial derivatives for all KL ( q θ ( ω i )
|| p ( ω i ))
components in the layer:
[Equation]
We consider ReLU activations, such that for large N , ¯ x ( m ) > 0 ∀ m .
Note that this does not hold for the ﬁrst layer (which is possibly normalized), but the effect of including these weights in the
L2-regularization would be smaller the deeper the network.
We assume most outputs from previous layer’s BN units remain normalized through the scale and shift transformation, such that we can approximate ¯ x ( m ) by the average of all input units over test data, x in Eq.
With J l − 1 units in the input layer, setting σ 2 p =
J l − 1 x 2 2 Nλ l , such that p ( µ u B ) =
N (0 , J l − 1 x 2 2 Nτλ l ) would then reconcile Eq.
(5), for any Gaussian p ( σ u B ) .
6. E XTENDED EXPERIMENTAL RESULTS
Below, we provide extended results measuring uncertainty quality.
In Tables 3 and 4, we provide tables showing the mean CRPS and PLL values for MCBN and MCDO.
These results indicate that MCBN performs on par or better than MCDO across several datasets.
In Table 5 we provide the raw PLL and CRPS results for MCBN and MCDO.
In Table 6 we provide RMSE results of the MCBN and MCDO networks in comparison with non-stochastic BN and DO networks.
These results indicate that the procedure of multiple forward passes in MCBN and MCDO show slight improvements in the accuracy of the network.
In Figure 5 and Figure 6, we provide a full set of our uncertainty quality visualization plots, where errors in predictions are sorted by estimated uncertainty.
The shaded areas show the model uncertainty and gray dots show absolute prediction errors on the test set.
A gray line depicts a running
[Table] [Table]
[Table]
6. B ATCH NORMALIZATION STATISTICS
In Figure 7 and Figure
[Table]
we provide statistics on the batch normalization parameters used for training.
The plots show the distribution of BN mean and BN variance over different mini-batches
[Table]
P r ed i c t i on e rr o r
Boston Housing MCBN 95% CI 50% CI
P r ed i c t i on e rr o r
Boston Housing MCDO 95% CI 50% CI
P r ed i c t i o n e rr o r
ConcreteMCBN 95% CI 50% CI
P r ed i c t i o n e rr o r
ConcreteMCDO 95% CI 50% CI 0.
P r ed i c t i on e rr o r
EnergyMCBN 95% CI 50% CI 0.
P r ed i c t i on e rr o r
EnergyMCDO 95% CI 50% CI 0.
P r ed i c t i on e rr o r
KinematicsMCBN 95% CI 50% CI 0.
P r ed i c t i on e rr o r
KinematicsMCDO 95% CI 50% CI
P r ed i c t i on e rr o r
Power Plant MCBN 95% CI 50% CI
P r ed i c t i on e rr o r
Power Plant MCDO 95% CI 50% CI
[Figure] [Figure]
[Figure]
P r ed i c t i on e rr o r
[Figure]
i
[Figure]
t
i
[Figure]
P r ed i c t i on e rr o r
YachtMCBN
[Figure]
i
[Figure]
t
i
[Figure]
YachtMCDO
[Figure]
[Figure] [Figure]