U NSUPERVISED T EMPERATURE S CALING : R OBUST P OST - PROCESSING C ALIBRATION FOR D OMAIN S HIFT
Anonymous authors
Paper under double-blind review
A BSTRACT
The uncertainty estimation is critical in real-world decision making applications, especially when distributional shift between the training and test data are prevalent.
Many calibration methods in the literature have been proposed to improve the predictive uncertainty of DNNs which are generally not well-calibrated.
However, none of them is speciﬁcally designed to work properly under domain shift condition.
In this paper, we propose Unsupervised Temperature Scaling (UTS) as a robust calibration method to domain shift.
It exploits unlabeled test samples instead of the training one to adjust the uncertainty prediction of deep models towards the test distribution.
UTS utilizes a novel loss function, weighted NLL, which allows unsupervised calibration.
We evaluate UTS on a wide range of model-datasets to show the possibility of calibration without labels and demonstrate the robustness of UTS compared to other methods (e.g., TS, MC-dropout, SVI, ensembles) in shifted domains.
I NTRODUCTION
The predictive distributions provided by Deep Neural Networks (DNNs) have been increasingly used for decision-support systems, for applications ranging from medical diagnoses assistance (Esteva et al., 2017) to self-driving cars (Bojarski et al., 2016).
In DNNs, the predictive distributions usually corresponds to the output of a softmax layer, which is typically interpreted as the conﬁdence over the different classes.
The i.i.d hypothesis made in learning usually assumes that the data distributions over the classes are the same at learning and inference time.
However, in real-world applications, the distribution of data at inference time (i.e., the test data) may shift and actually be different from the original training distribution – corresponding to distribution shift in representation of data which we refer that as domain shift.
For instance, in image classiﬁcation problem, domain shift happens when the test images are different in illumination, view point, resolution, background or intensity noise from the training set.
However, they are the same classiﬁcation problem with the same objects occurance rate.
Arguably, building DNNs that are robust to the domain shift problem is necessary for its safe deployment in decision-making systems.
Dealing with this, predictive uncertainty is the key to obtain a meaningful estimation for practitioners to know when prediction accuracy is degrading and allows a system to abstain from making decisions due to low conﬁdence.
The predicted uncertainty in DNNs usually are not calibrated with a tendency to be overconﬁdent.
Many probabilistic and post-processing calibration methods have been proposed under i.i.d assumptions to adjust the certainty of DNNs.
In recent studies (Ovadia et al., 2019; Maddox et al., 2019), uncertainty under domain shift condition gets more attention and the common calibration methods have been assessed regarding to the domain shift, although they are not designed to be robust under such condition.
In this paper, for the ﬁrst time, we speciﬁcally focused on calibration for the domain shift in image classiﬁcation.
We show post-processing calibration approaches that use Negative Log
Likelihood (NLL) as the calibration loss like Temperature Scaling (TS) (Guo et al., 2017) may become robust to the domain shift problem if they calibrate the model using the test samples.
However, they need labels of the samples to apply calibration.
Labeling the test samples even for the small set is not always an easy task and need human experts effort which can be accompanied with the labeling noise and huge time burden.
Neuron cells classiﬁcation taken by electron microscope (Ostroff &
Zeng, 2015), pathology images (Khosravi et al., 2018) and skin disease classiﬁcation (Kolkur et al.,
2018) are three examples of applications that have expensive labeling procedure with high risk of labeling noise that need senior experts to label them.
In this work, we propose a new approach called Unsupervised Temperature Scaling (UTS) with similar framework of TS and using unlabeled test samples for calibrating the pre-trained model.
This novel idea brings the chance of robust calibration to the domain shift.
Possibility of using the test samples to calibrate, makes UTS a proper solution not only for domain shift but also for many practical calibration problems like calibrating off-the-shelf-models.
More speciﬁcally, UTS is proposed with following contributions and foreseen impacts:
• Unsupervised post-processing calibration: UTS brings a new look to NLL loss function which is used as the calibration loss in several post-processing methods.
UTS approximates a weight function to estimate the per class distribution of data to compute NLL.
This new way of computing NLL makes it independent of the labels.
In addition, computing weighted NLL has the same order of time and memory complexity as the classic NLL, without any additional hyper-parameter to ﬁne-tune.
• Robustness to the domain shift : UTS is a robust calibration solution to shifted domains.
It adjusts the the model uncertainty based on the test and not the training domain.
Therefore by change of distribution in the test domain, UTS can follow the distribution shift easily.
• Calibration of off-the-shelf models : The pre-trained models for classiﬁcation tasks are usually only trained to achieve higher accuracy rate without paying attention to the predictive uncertainty.
In fact, many of them are released without the training data that removes the possibility of retraining them to calibrate, like available Pytorch pre-trained models.
UTS brings a chance to use these models for decision-making applications by calibrating them on a test data without need of labeling them.
R ELATED W ORK
Calibration of predictive uncertainty for DNNs are widely investigated in recent literature.
Calibration methods can be categorized in two groups: probabilistic or post-processing approaches.
Probabilistic approaches refer to methods that use Bayesian theory (Bernardo & Smith, 2009) for estimating the conditional distribution of data.
As the exact Bayesian inference is not practical, a variety of approximation are proposed such as Laplace approximation (MacKay, 1992; Ritter et al., 2018b;a; Kirkpatrick et al., 2017), Variational Bayesian methods (Molchanov et al., 2017; Louizos & Welling, 2017; Blundell et al., 2015; Louizos & Welling, 2016; Wen et al., 2018) and Monte
Carlo Markov Chains (MCMC) (Neal, 2012; Balan et al., 2015; Chen et al., 2014) to make Bayesian deep networks tractable.
MC-dropout (Gal & Ghahramani, 2016) replaces complicated sampling with simple dropout in training and test phases, which has been shown to approximate Variational
Bayesian inference.
Ensemble of DNNs (Lakshminarayanan et al.
(2017)) is another straightforward probabilistic approach that can achieve better calibrated results than MC-dropout.
This approach is appropriate for parallel computing, with multiple DNNs running at the same time.
However, keeping the models in the memory during the test time brings high memory complexity.
Post-processing approaches are much less complex, albeit less accurate compared to probabilistic calibration.
In post-processing approaches, the main idea is to decrease the miscalibration of the network by minimizing a calibration loss (Gneiting & Raftery, 2007) such as NLL.
In order to train the neural network, NLL is used to simultaneously increase accuracy and decrease miscalibration.
However, it easily gets overﬁtted to conﬁdence and makes the network overconﬁdent (Guo et al., 2017).
Post-processing approaches like TS, Platt-Scaling (Platt et al., 1999), Histogram Binning (Zadrozny & Elkan, 2001), Isotonic Regression (Zadrozny & Elkan, 2002), and Bayesian Binning into Quantiles (Naeini et al., 2015) ﬁne-tunes the softmax layer by keeping the DNNs’ weights unchanged.
They do not need to retrain the deep network from scratch and they only need to ﬁnd the best parameter of softmax softening function by minimizing a calibration loss (like NLL) on a small validation set.
Temperature Scaling is the state-of-the-art among the post-processing approaches which uses NLL as the loss function.
It only uses one parameter T to rescale the logit layer and soften the softmax output.
Therefore with keeping the accuracy unchanged it can calibrate the model with the minimum time and memory complexity.
These features leads us to focus on TS and try to propose a robust post-processing solution for domain shift based on TS framework.
Robustness to the domain shift : Previously, the results of calibrated model were also reported for different domains such as Out-Of-Distribution (OOD) and Adversaries (Lakshminarayanan et al., 2017; Ritter et al., 2018b) to show the model is uncertain about what it does not learn before.
Recently, people get into importance of domain shift problem in calibration and assess how the calibrated methods would behave under domain shift condition (Ovadia et al., 2019; Maddox et al., 2019).
Domain shift concept is different from adversaries and OOD.
In the case of OOD, training and test domains are completely different in task distributions and in the case of adversaries the distribution shifts between the training and test is made with the goal of fooling the classiﬁer.
In domain shift, the training and test domains are distributionally different but related.
The relation between two domains can be used as the prior knowledge to help improving the accuracy or having better calibration.
In the literature of calibration, to the best of our knowledge, there is no work that speciﬁcally designed to calibrate the model considering domain shift assumptions.
In this paper we will focus on Covariate shift as the most famous domain shift setting in image classiﬁcation and propose UTS as a robust calibration method accordingly.
P RELIMINARIES
In this section, we deﬁne the domain shift and calibration setup to clarify UTS objectives.
Then, we explain why NLL can be used as a calibration loss and when optimizing NLL will lead to a calibrated model toward the domain shift settings.
Finally, we bring a deep analysis of the postprocessing method TS which uses NLL as a calibration loss.
We show TS can be a robust calibration solution to the domain shift if it uses labeled samples from the test domain to apply calibration.
We discuss TS sensitivity to the labels of samples as the preliminaries to propose UTS method in the next section.
3. P ROBLEM S ETUP
Considering the domain shift assumptions, the goal of calibration in this work is to improve uncertainty estimation of a pre-trained model for different shifted domains.
In this setting, q s ( x , y ) is considered as the ground-truth distribution of the source domain and q t ( x , y ) is considered as the ground-truth distribution of the target domain where x ∼ X ∈ R d and y ∈ { 1 , 2 , . . .
, K } .
In the setting of domain shift, the source and target domains have different but related distributions .
The relation between the domains is deﬁned by Covariate Shift assumption (Adel &
Wong (2015)) which is: the data distributions q s ( x , y ) (cid:54) =
q t ( x , y ) where the conditional distribution q s ( y | x ) =
q t ( y | x ) , and the task and marginal distributions q s ( y ) =
q t ( y ) and q s ( x ) (cid:54) =
q t ( x ) , respectively.
Let d ( x ) =
{ S y ( x ) , ˆ y } denotes the pre-trained model in which ˆ y is the class prediction and S y ( x ) is its associated conﬁdence.
In domain shift setting, for deep neural networks, model d ( · ) is a DNN trained on the source domain and would be tested on the target domain.
In this setting,
S y ( x ) is the output of the softmax layer which is calibrated when S y ( x ) =
q t ( y | x ) .
Miscalibration of DNNs can be explained in different ways.
Temperature Scaling models the miscalibration as the rescaled logit layers by scaling factor T ∗ .
TS objective is to ﬁnd T ∗ value to rescale the logit layer back and makes the model calibrated.
More speciﬁcally, the calibrated output of TS is deﬁned as S y ( x ; T ∗ ) =
exp( f y ( x ) T ∗ ) / (cid:80) Kj
=
exp
f j ( x ) T ∗ ) where f ( x ) =
[ f 1 ( x ) , f 2 ( x ) , . .
, f k ( x )] (cid:62) is the logit layer of model d ( x ) .
In this paper, considering the same deﬁnition of miscalibration as
TS, we propose UTS under domain shift condition.
UTS objective is to ﬁnd the scaling factor T ∗ that S y ( x ; T ∗ ) =
q t ( y | x ) , given that we have access to the source pre-trained model d ( · ) , unlabeled calibration set C =
{ x i } Li =1 ∼ q t ( x ) and the known task distribution q s ( y ) .
3. R OBUSTNESS TO D OMAIN S HIFT WITH NLL L OSS F UNCTION
To calibrate a model, ﬁrst we need to evaluate the quality of predicted uncertainty of the model.
Evaluating the quality of predictive uncertainty is challenging, as the ground-truth of the uncertainty estimate is usually not available.
Accordingly, scoring rules are deﬁned to measure the quality of predictive uncertainty (Gneiting & Raftery (2007)).
Scoring rules are numerical scores that rank the distribution prediction p θ ( y | x ) by giving lower score to better prediction of true distribution q ( y | x ) .
Let a scoring rule be a function R ( p θ , ( x , y )) that evaluates the quality of the predictive distribution p θ ( y | x ) based on the samples ( x , y ) ∼ q ( x , y ) where q ( x , y ) is the true distribution of the data.
The expected scoring rule is deﬁned by R ( p θ , q )
= (cid:82) q ( x , y ) R ( p θ , ( x , y ))
dyd x .
A proper scoring rule function is one where R ( p θ , q ) ≤ R ( q, q ) with equality if and only if p θ ( y | x ) =
q ( y | x ) for all samples.
Negative Log Likelihood (NLL) is a proper scoring rule based on Gibbs inequality i.e., R
( p θ , q ) =
E q ( x ) q ( y | x ) log p θ ( y | x ) ≤ E q ( x ) q ( y | x ) log q ( y | x ) .
Therefore minimizing NLL w.r.t θ on the samples generated from q ( x , y ) distribution, leads to p θ ( y | x ) →
q ( y | x ) .
Under the domain shift assumption, as the training and test domains have different distributions, the ﬁnal goal of calibration is p θ ( y | x ) =
q t ( y | x ) .
In the case of using NLL as the loss function, if we minimize NLL on the samples that are generated from the test domain, we will have p θ ( y | x ) → q t ( y | x ) and makes the method robust to the domain shift.
One of the post-processing methods that uses NLL as the loss function is TS.
Therefore, TS has the ability to get robust to the domain shift.
3. T EMPERATURE S CALING A NALYSIS
TS (Guo et al.
(2017)) is the state-of-the-art post-processing approach which rescales the logit layer of a deep model by parameter T that is called temperature.
TS is used to soften the output of the softmax layer and makes it more calibrated.
The best value of T will be obtained by minimizing
NLL loss function (explained in Sec.(3.2), why minimizing NLL leads to more calibrated model) respecting to T conditioned by T > 0 on the calibration set as deﬁned in Eq.
[Equation]
where S y i ( x i ; T ) = exp( f yi ( x i ) T ) / (cid:80) Kj =1 exp( f j ( x i ) T ) , is the softed version of softmax by applying parameter T on the logit layer f j ( x ) .
TS has the minimum time and memory complexity with order of O (1) among calibration approaches as it only optimizes one parameter T on small labeled calibration set.
Having only one parameter helps TS not only to be efﬁcient and practical but also not to get overﬁtted to NLL loss function when it is optimized on small calibration set.
TS previously is applied for calibration (Guo et al.
, distilling the knowledge (Hinton et al. (2015)) and enhancing the output of DNNs for better discrimination between the in and out distribution samples (Liang et al.
TS models the uncalibration as the rescaling factor in the logit layer.
By computing the derivative of NLL respecting to T in Eq.
(1), and ﬁnd the minimum, we will have:
[Equation]
It shows regarding to the true label of the samples, TS selects the T value which maximizes the
S k
( x i , T ) for k
= y i and minimize
S k
( x i , T ) for all the other k (cid:54) =
y i .
Therefore for correctly classiﬁed samples that y i = arg max y S y
( x i ) , T approaches 0 to increase the conﬁdence of that class toward 1 and for the misclassiﬁed samples, T goes toward ∞ to decrease the conﬁdence of predicted label.
The balance between the correctly classiﬁed and misclassiﬁed samples brings back the optimal value of T .
TS uses NLL as the loss function then by selecting the calibration set from the test domain instead of the training one, we can make TS robust to the domain shift problem.
We refer to this approach as TS-Target .
TS is highly dependent on the labels of the samples.
however, Labeling the test samples is a challenging task.
When the calibration set contains data with labeling noise or unlabeled samples, TS loses the balance to ﬁnd the optimal T ∗ TS and cannot calibrate the network successfully.
Later, in Sec.
(5.3), we will show even a small portion of the noise has big distortion in TS results.
This brings the idea of Unsupervised Temperature Scaling which makes TS independent of labeled data and robust to the domain shift.
U NSUPERVISED T EMPERATURE S CALING
Considering the assumptions in Sec.
(3.1), its main objective is to ﬁnd T ∗ UTS for the unlabeled calibration set.
UTS the same as TS uses NLL as the proper scoring rule to minimize the calibration gap and ﬁnds the optimal T value.
The ﬁrst step of using NLL in UTS is to make NLL independent of labeled data.
Considering NLL loss function, we can rewrite it with focus on per class distribution, formalized as:
[Equation]
In Eq.
(3), NLL is the summation of K different sample sets, generated from class distribution q ( x , y = k ) where k ∈ { 1 , 2 , . . .
, K } .
When the labels of the samples are available, they can be used as the guide to select the samples set for each class distribution.
But in the absence of the labels, the main question is how to select the samples generated from q t ( x , y = k ) and calculate
NLL.
To come along with this challenge, instead of selecting the samples by labels, UTS applies weights on the samples.
The weight function ˆ W k ( x ; w ∗ ) represents the probability that sample x is drawn from q ( x , y = k ) .
Later, in Sec.
(4.1) we will give speciﬁc details of the weight function ˆ W k ( x ; w ∗ ) and how to approximate it.
By applying weights on the samples, the UTS loss function is deﬁned as the Weighted NLL (WNLL) which is:
[Equation]
4. W EIGHT F UNCTION ˆ W k ( · ; · )
We start the discussion about the weight function by introducing a fact from the Bayes rule (Jin et al.
[Equation]
When a sample has a true label of y =
k it is drawn from distribution q ( x , y = k ) .
However, Eq.(5) shows that even samples with true label of y (cid:54) =
k can be used as the samples drawn from the distribution q ( x , y = k ) by applying weight of q ( y = k | x ) /q
( y (cid:54) =
k | x ) .
Therefore, we can simply use the weight of 1 for the samples with true label of y = k and the weight of q ( y = k | x ) /q
( y (cid:54) =
k | x ) for the samples
y (cid:54) =
k to change all the samples in the calibration set to the samples drawn from q ( x , y = k ) .
Therefore, we deﬁne the weight function as Eq.(6):
[Equation]
To compute W k ( · ) for the samples, we need the ground-truth distribution q ( x , y = k ) that in UTS setting is not available.
However we can approximate it empirically referring to UTS assumptions (Sec. (3.1)).
Proposition 1 : Let d ( · ) be a model which gets miscalibrated with rescaled logit layer by factor w ∗ .
Then, with known q t ( y ) , the empirical approximation of W k ( · ) is equal ˆ W k ( · ; · ) which is deﬁned as :
[Equation]
if
[Equation]
where w ∗ is:
[Equation]
Proposition 1 valid for the domain shift setting with Covariate shift assumption and also for the case that there is no distribution shift between the training and test datasets.
The validity of Proposition 1 for both settings are provided in Appendix A. Fig.
1 illustrates a schematic view of the weight function ˆ W k ( · ; · ) in the feature space.
The color hue is correlated with the weight values.
For the samples that are classiﬁed as ˆ y = k and for the samples with ˆ y (cid:54) =
k located near to the decision boundary, the weight is equal to 1 .
The weight would decrease as the samples fall further from the decision boundary which shows they are less probable to be drawn from distribution q ( x , y = k ) .
Time Complexity of UTS:
Computing ˆ W k ( · ; · ) is a one parameter optimization which has the time complexity of O (1) .
After approximating the weight function ˆ W k ( · ; · ) , UTS minimizes WNLL (Eq.(4)) with the same time complexity to ﬁnd the optimal T ∗ UTS which leads to have UTS with the total time complexity of O (1) .
Algorithm 1 summarizes UTS.
Validity of UTS in Practice: UTS is valid when there is no domain shift or when the there is Covariate Shift between domains.
When the test and training datasets are different in representation but keeps the same proportions of each class occurrence, it is categorized as Covariate shift assumption.
In many applications like medical image classiﬁcations, the probability of happening a class of object is staying the same during the training and test phases which means q s ( y ) =
q t ( y ) but the illumination, capturing noise, resolution, and image size and viewpoint can vary between two domains which means q s ( x ) (cid:54) =
q t ( x ) .
Therefore, in classiﬁcation problems with Covariate Shift assumption or without any shift, UTS only needs to calculate empirically the number of occurrence of each class to the total number of samples in the training set and use it as q t ( y ) to calibrate the model.
E XPERIMENTS
We conduct the experiments to analyze the behavior of UTS in comparison to the other methods for two different calibration scenarios.
First, we compare UTS with several post processing methods that use NLL as the loss function in the experiment with the same training and test domain distributions .
This experiment is designed to be a proof of concept to show that weighted NLL of UTS can indeed calibrate the model without accessing the labels.
Second, in order to show the success of UTS in calibrating the model under domain shift condition, we compare UTS, TS and
[Table]
and test domains with different distributions .
We also study the results of TS-Target that is a TS which selects the calibration set from the target (test) domain.
TS-Target has the most accurate uncertainty prediction among all other baselines for the shifted domain distributions.
However, we will show in the third section of Experiments part, it suffers from the labeling noise which justiﬁes our try to make TS unsupervised.
5. C ALIBRATION WITH THE S AME T RAINING AND T EST D OMAINS
Here we consider the training and the test domains have the same distribution.
Our goal is to show
UTS can calibrate the models without labels in the case of no domain shift.
Experiment Setup We compare UTS with several post-processing baselines which are Temperature
Scaling (TS) (Guo et al.
and Matrix and Vector Scaling (Platt et al.
on a wide range of different state-of-the-art deep convolutional networks with variations in depth which are ResNet (He et al.
, WideResNet (Zagoruyko & Komodakis (2016)), DenseNet (Iandola et al.
LeNet (LeCun et al.
(1998a)), and VGG (Simonyan & Zisserman (2014)).
We test the methods on different datasets such as CIFAR-10 and CIFAR-100 (Krizhevsky & Hinton (2009)), SVHN (Netzer et al.
, MNIST (LeCun et al.
(1998b)), and
Calthec-UCSD Birds
(Wah et al.
We use all the data pre-processing, training procedures and hyper-parameters tuning for each dataset as described in each mentioned reference.
To setup the calibration set, we randomly select 20% of the test dataset.
Then, we consider the rest to be evaluated as a test set.
We repeat each experiment 20 times independently and report the mean of NLL as a calibration metric.
More explanation of experiment setup and the baselines, datasets and calibration metrics are provided in Appendix B.
Results In Table 1, the calibration results based on NLL are compared between TS and UTS, which have only one parameter for ﬁne-tuning the softmax output layer, and Matrix and Vector scaling, which apply a linear function on logit layers.
In all cases, TS calibrates the network better than all the other methods.
Although the results of UTS are not better than TS, UTS shows improvement in calibration for all dataset-models.
It means the weighted NLL as the approximation of NLL with unlabeled samples can work properly to calibrate the model even though it is not as accurate as the
NLL with access to labels.
Although Matrix and Vector Scaling can deﬁne more complex functions to soften the softmax layer, they suffer from over-ﬁtting w.r.t the validation set in conﬁdence.
We also provide the complete results with mean and standard deviation for accuracy as well as other standard calibration metrics (NLL, ECE and Brier Score) in Appendix C.1.
The explanation about the ECE and Brier are given in Appendix B.3.
5. C ALIBRATION U NDER D OMAIN S HIFT S ETTING
In this section, we divide the experiments into two parts.
First, we compare UTS to the uncalibrated model (UNC), TS and TS-Target on different domain shift scenarios.
The goal of this experiment is to compare the gap of calibration between UTS and TS-Target that can be considered as the ground-
[Figure]
[Figure]
truth for UTS when the labels are available.
Later, we also evaluate the robustness of UTS, which was speciﬁcally designed to domain shift and several probabilistic approaches, which only consider the case of calibration for the same distribution setting.
The goal of the experiment is to show that
UTS can be indeed robust for different shifting domain scenarios
Experiment Setup We follow the same experimental setup as Sec (5.1) but with different domain shift assumptions.
We use the benchmark proposed speciﬁcally for domain shift problem in (Ovadia et al.
They model the distribution shift by applying different operations like rotation, translation (rolling), and with different severity levels of intensity corruptions proposed in (Hendrycks & Dietterich (2019)).
In the ﬁrst part of this section, we compare the result of the UTS to uncalibrated, TS and TS-Target on MNIST and CIFAR10 datasets applying rotation, pixel translation and Gaussian noise to the test domain.
In the second part, we add more probabilistic baselines such as LL-Dropout(Gal & Ghahramani (2016)), SVI (Blundell et al.
and Ensemble (Lakshminarayanan et al.
with more variation of the domain shifts in the sense of corruption of intensities.
Speciﬁc details of baselines and experiment can be found in Appendix B.
Results As we can see in Fig.
2, the accuracy of the model degrades by the effect of domain shift.
TS family approaches does not change the accuracy during the calibration therefore, all the methods have the same accuracy as the uncalibrated one.
TS-Target has the same setting as TS with the difference that it uses the labeled calibration set from the target domain.
Then, in ideal situation,
UTS uncertainty prediction would reach the TS-Target performance.
We can see that UTS is working better than uncalibrated model (UNC) and TS which uses the source data for calibration under the domain shift condition.
The gap between UTS and TS-Target is interestingly small in the sense of
Brier Score.
More results for other domain shifts are provided in Appendix C.2.
We also provide the analysis of UTS sensitivity to number of calibration samples in compared to TS and TS-Target in Appendix C.4 which shows UTS obtains stable results in decreasing the number of samples from 20% to 2 .
5% of test detest size.
[Figure]
In Fig.
3 we compare probabilistic approaches to UTS, uncalibrated model (UNC), TS and TSTarget.
As all the calibration metrics are dependent on the accuracy of the models, controlling the accuracy to have fair comparison between the methods is important.
Otherwise, the better calibration can be as the result of having better accuracy and not the calibration itself.
Accordingly, we apply the shifts to the datasets and check the accuracy of the UTS with other approaches, and select the domain shift settings that UTS accuracy is near to the others.
As we can see for different combination of model and datasets, UTS can achieve better results than any other probabilistic approaches and has a small gap with TS-Target which achieves the best results.
It shows that using the test samples to ﬁne-tune the calibration toward test distribution can help the model to be robust to the domain shift problem.
As mentioned before, labeling the test samples is not a trivial task, therefore, using directly
TS-Target might not be possible in many cases which justiﬁes the importance of an unsupervised approaches like UTS.
In the next section, we show that for a weakly supervision of the test samples,
TS-Target cannot be successful in calibration and it needs exact labeling of the test domain samples that might be impractical in many cases.
5. TS S ENSITIVITY TO L ABELING N OISE
When the labeled samples are available for calibration, TS shows the best results with and without domain shifts.
In this section, we will investigate the sensitivity of TS with labeling noise.
We apply different rates of random altering the labels only for the calibration set and evaluate the calibration success of TS, UTS and uncalibrated methods accordingly.
As we can see in Fig.
4, TS is extremely sensitive to the noise of labeling.
Therefore, in order to have a successful calibration for TS in shifted domains, the exact labeling of test samples is essential which might be not feasible for many applications.
UTS is robust to the labeling noise as it is an unsupervised calibration method and it can remove the challenge of labeling the test samples, completely.
More results for more datasetsmodels are provided in Appendix C.3.
D ISCUSSION AND F UTURE W ORK
In this paper, we propose UTS as a robust unsupervised post-processing method to the domain shift calibration challenge.
UTS is a member of TS family approaches which have low time and memory complexity, and can calibrate with few number of samples while preserving the accuracy intact.
UTS utilizes a new calibration loss function, weighted NLL which is independent of the labels.
The computational complexity of weighted NLL is in the same order of NLL which makes UTS a fast and practical calibration solution.
Since UTS uses the test samples to adjust the uncertainty, we show it is robust to domain shift and can make off-the-shelf models calibrated when their training samples are not available anymore.
Recent studies (Maddox et al., 2019; Kumar et al., 2018) mentioned that using TS with probabilistic approaches can even improve the uncertainty prediction of already calibrated models.
Therefore, we believe this work can be extended in the direction of combining UTS with such approaches in order to achieve more robust domain shift solutions.
We also consider another direction of this work towards exploring UTS for more variant domain shift assumptions.
In this paper, we study UTS only for Covariate Shift assumption, however, it can be extended to other shifting scenarios such as
OOD and adversaries, in future.
A P ROOF OF P ROPOSITION
First we investigate the validity of Proposition 1 for the settings with no distribution shift.
Proposition 1 : let W k ( · ) be a weight function deﬁned as:
[Equation]
and let d ( · ) be a model which gets miscalibrated with rescaled logit layer by factor w ∗ .
Then, with known task distribution q ( y ) , the empirical approximation of W k ( · ) is equal ˆ W k ( · ; · ) which is deﬁned as :
[Equation]
where w ∗ is:
[Equation]
Proof : For simplicity we split the proof into two parts.
First, we show that for a known value of w ∗ , ˆ W k ( · ; · ) is the approximation W k ( · ) .
In other words, 1 / exp( 1 w ∗ log( S y =
k
( x ) − 1 − 1))
=
q ( y = k | x ) /q
( y (cid:54) =
k | x ) :
The softmax output of an uncalibrated model d ( · ) with rescaled logit layer by a factor w ∗ , can be formulated as:
[Equation]
Therefore calibrated output will be deﬁned as:
[Equation]
Considering these deﬁnitions:
[Equation]
We consider ˆ y i
=
k as the rough estimation of condition x i ∼ q ( x , y = k ) .
The accuracy of the uncalibrated model is the same as calibrated one when it gets uncalibrated by rescaled logit layer.
Therefore we can use the prediction output of uncalibrated model to have a rough estimation of the samples that x ∼ q ( x , y = k ) .
Now in the second part, we show that w ∗ = arg min w (cid:16)(cid:80)
Kk
[Equation] [Equation]
Li
[Equation]
w ) − q
[Equation]
y
[Equation]
where x i ∈ C ∼ q ( x )
Referring to W k ( · ) deﬁnition, we can simply show:
[Equation]
Which means E q ( x ,y )
[ W k ( x )]
=
q ( y = k ) , and as ˆ W k ( · ; · ) is equal to W k ( · ) , empirically we can show (cid:80) x ci ∈ C ˆ W k
( x i ; w ∗ ) =
q ( y = k ) .
In this problem setting, we assume q ( y ) is known.
Therefore, w ∗ can be found easily by minimizing (cid:16)(cid:80) K
[Equation]
(cid:80)
[Equation]
Now we show the validity of Proposition 1 under Covariate Shift assumptions.
Corollary 1 : Considering the same weight function W k ( · ) deﬁned in Proposition 1, let d ( · ) be a model which gets miscalibrated with rescaled logit layer by factor w ∗ toward the target domain q t ( x , y ) .
Assume covariate shift where q s ( y | x ) =
q t ( y | x ) , q s ( y ) =
q t ( y ) and q s ( x ) (cid:54) =
q t ( x ) .
Then, with known q s ( y ) , the empirical approximation of W k ( · ) is equal ˆ W k ( · ; · ) which is deﬁned as :
[Equation]
otherwise
[Equation]
where w ∗ is:
[Equation]
Proof : The ﬁrst part of the proof is exactly the same as Proposition 1 with considering that w ∗ with new assumptions is the scaling factor that makes the model uncalibrated towards the target domain.
Therefore, we will conclude:
[Equation]
For the second part of the proof, we have:
[Equation]
Referring to covariate shift assumption where q s ( y | x ) =
q t ( y | x ) and q s ( y ) =
q t ( y ) , we can deduce:
[Equation]
Which means E q t ( x ,y )
[ W k ( x )] =
q t ( y = k ) , and as ˆ W k ( · ; · ) is equal to W k ( · ) , empirically we can show (cid:80) x ci ∈ C ˆ W k
( x i ; w ∗ ) =
q t ( y = k ) .
In this problem setting, we assume q s ( y ) is known that is equal to q t ( y ) .
Therefore, w ∗ can be found easily by minimizing
[Equation]
B E XPERIMENTAL S ETUPS B. B ASELINES
• Temperature Scaling (Guo et al.
It is explained in Sec.
(3.3) • Matrix and Vector Scaling (Platt et al.
Matrix Scaling applies a linear transformation on the logits to soften them:
[Equation]
Where σ is the softmax function which takes logit layer f
( x ) as an input.
The parameters θ K × K and b K are optimized with respect to NLL on the validation set.
Vector Scaling is the relaxed version of Matrix Scaling in which θ K × K is a diagonal matrix.
• ll-Dropout Monte-Carlo Dropout(Gal & Ghahramani (2016)), A pre-trained model which is trained with dropout rate p = 0 .
5 only on the activation function before the last layer, and keeping the dropout active during the test with the same rate.
• Ensembles Ensembles of 10 networks trained independently on the entire dataset using the random initialization(Lakshminarayanan et al.
• SVI Stochastic Variational Bayesian Inference for deep learning (Blundell et al.
Wen et al.
(2018) with the speciﬁc settings of training mentioned in (Ovadia et al.
B. D ATASETS
We apply the calibration method on different image classiﬁcation datasets.
For each experiment, the size of validation set is 20% of the test set which is selected randomly.
For all the model-dataset we have trained them on the training set.
CIFAR-10 (Krizhevsky et al.
It contains 60000, 32 × 32 color images of 10 different objects, with 6000 images per class.
The size of training and test sets are 50000 andrespectively.
CIFAR-100 (Krizhevsky et al.
With the same setting as CIFAR-10, except it has 100 classes of different objects containing 600 images in each class.
SVHN (Netzer et al.
It contains 32 × 32 color images of numbers between 0 tothat has 73257 digits for training, 26032 digits for testing.
MNIST (LeCun et al.
(1998b)):
It contains 28 × 28 gray-scale images of numbers between 0 to 9.
It has 60,000 images for training, and 10,000 images for test.
Calthec-UCSD Birds
(Wah et al.
It contains 11,788 color images of 200 different birds species.
We divided randomly into 7073 training, and 4715 testing samples.
B. C ALIBRATION M ETRICS Expected Calibration Error (ECE)
ECE (Naeini et al.
(2015)) measures the average gap between the accuracy and predicted probabilities.
Based on this deﬁnition of calibration, ECE is proposed as empirical expectation error between the accuracy and conﬁdence.
It is calculated by partitioning the range of conﬁdence between [0 , 1] into B equally-spaced conﬁdence bins and then assign the samples to each bin B b where b = { 1 , . . .
, B } by their conﬁdence range.
Later it calculates the weighted absolute difference between the accuracy and conﬁdence for each subset B l .
More speciﬁcally:
[Equation]
(10) where N is the total number of samples.
In this paper, we consider B = 15 to report the ECE error.
ECE is not derivable function.
Therefore mostly it is ignored as the loss function of the post-processing approaches in calibrating the model by gradient decent optimizing methods.
Brier Score
Brier Score (Brier (1950)) is a scoring rule for measuring the accuracy of predicted probabilities.
It is computed as the square error of predicted probability and the one-hot encoding of the correct label.
That is:
[Equation]
C M ORE E XPERIMENTAL R ESULTS C. T ABLES OF A CCURACY , NLL, ECE AND B RIER S CORE
We report additional results of the experiment applied in Sec.
5.1 to evaluate the behavior of UTS in calibration with the same training and test domains.
We report the accuracy, NLL, ECE and Brier
Score in Table 2, 3, 4, and 5, respectively.
Notice that TS family approaches keep the accuracy unchanged while Matrix and Vector Scaling can change the accuracy.
In two cases Matrix and
Vector Scaling improve the accuracy.
However, they get overﬁtted on validation set and lose the accuracy and calibration in general.
We report the results for different calibration score to show that UTS will calibrate the model regarding different calibration evaluation metrics.
NLL and Brier
Score have related deﬁnition of calibration as both of them are proper scoring rule.
But ECE has different calibration deﬁnition.
The detail explanation are given in Sec.
(B.3) for each score.
We can see in Table 4, UTS even can calibrate the model better than TS for two dataset-model combination with ECE deﬁnition of calibration.
[Table] [Table]
[Table] [Table]
C. C OMPARING D IFFERENT TS F AMILY APPROACHES TO UTS FOR D OMAIN S HIFT S CENARIOS
In this section, we provide more results to compare the behavior of UTS with TS and TS-Target in different domain shift applied to CIFAR10 dataset.
Details of shifting operation can be found in (Hendrycks & Dietterich, 2019).
We can see in Fig.
5 that TS-Target has the most calibration robustness to the domain shift and followed by UTS with small gap
. C. M ORE E XPERIMENTAL R ESULTS FOR S ENSITIVITY OF TS TO THE L ABELING N OISE
In this section, we provide more experiments for more models and datasets.
As we can see in Fig.
TS shows a huge sensitivity to the noise of labeling in calibration set.
UTS is completely robust to this noise as it is an unsupervised method.
It shows if TS wants to calibrate the model without available labeled data, the labeling phase should be handled precisely.
Otherwise TS results are not reliable.
C. A NALYSIS OF UTS S ENSITIVITY TO N UMBER OF S AMPLES
In this experiment, we show the impact of number of available calibration samples on TS, UTS and
TS-Target.
As we can see in Fig.7, TS and UTS vary signiﬁcantly when the number of samples are really few (between 30 ∼ 50 ) while TS-Target is not affected severely (the variance of TS-Target comparing to other methods is small then it is not properly shown in the image).
However, by increasing the number of samples to 500, UTS reaches to the optimal T ∗ UTS and after that increasing the number of samples does not consequences better results.
[Figure] [Figure] [Figure]