<?xml-model href='http://www.tei-c.org/release/xml/tei/custom/schema/relaxng/tei_all.rng' schematypens='http://relaxng.org/ns/structure/1.0'?><TEI xmlns="http://www.tei-c.org/ns/1.0">
	<teiHeader>
		<fileDesc>
			<titleStmt><title level='a'>Augmentation by Counterfactual Explanation--Fixing an Overconfident Classifier</title></titleStmt>
			<publicationStmt>
				<publisher></publisher>
				<date>01/01/2022</date>
			</publicationStmt>
			<sourceDesc>
				<bibl> 
					<idno type="par_id">10388288</idno>
					<idno type="doi"></idno>
					<title level='j'>IEEE Winter Conference on Applications of Computer Vision</title>
<idno>2472-6737</idno>
<biblScope unit="volume"></biblScope>
<biblScope unit="issue"></biblScope>					

					<author>Sumedha Singla</author><author>Nihal Murali</author><author>Forough Arabshahi</author><author>Sofia Triantafyllou</author><author>Kayhan Batmanghelich</author>
				</bibl>
			</sourceDesc>
		</fileDesc>
		<profileDesc>
			<abstract><ab><![CDATA[A highly accurate but overconfident model is ill-suited for deployment in critical applications such as healthcare and autonomous driving. The classification outcome should reflect a high uncertainty on ambiguous in-distribution samples that lie close to the decision boundary. The model should also refrain from making overconfident decisions on samples that lie far outside its training distribution, far-out-of-distribution (far-OOD), or on unseen samples from novel classes that lie near its training distribution (near-OOD). This paper proposes an application of counterfactual explanations in fixing an over-confident classifier. Specifically, we propose to fine-tune a given pre-trained classifier using augmentations from a counterfactual explainer (ACE) to fix its uncertainty characteristics while retaining its predictive performance. We perform extensive experiments with detecting far-OOD, near-OOD, and ambiguous samples. Our empirical results show that the revised model has improved uncertainty measures, and its performance is competitive to the state-of-the-art methods.]]></ab></abstract>
		</profileDesc>
	</teiHeader>
	<text><body xmlns="http://www.tei-c.org/ns/1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xlink="http://www.w3.org/1999/xlink">
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="1.">Introduction</head><p>Deep neural networks (DNN) are increasingly being used in decision-making pipelines for real-world highstake applications such as medical diagnostics <ref type="bibr">[6]</ref> and autonomous driving <ref type="bibr">[7]</ref>. For optimal decision making, the DNN should produce accurate predictions as well as quantify uncertainty over its predictions <ref type="bibr">[8,</ref><ref type="bibr">38]</ref>. While substantial efforts are made to engineer highly accurate architectures <ref type="bibr">[23]</ref>, many existing state-of-the-art DNNs do not capture the uncertainty correctly <ref type="bibr">[9]</ref>.</p><p>We consider two types of uncertainty: epistemic uncer-* Equal contribution tainty, caused due to limited data and knowledge of the model, and aleatoric uncertainty, caused by inherent noise or ambiguity in the data <ref type="bibr">[30]</ref>. We evaluate these uncertainties with respect to three test distributions (see Fig <ref type="figure">1</ref>):</p><p>&#8226; Ambiguous in-Distribution (AiD): These are the samples within the training distribution that have an inherent ambiguity in their class labels. Such ambiguity represents high aleatoric uncertainty arising from class overlap or noise <ref type="bibr">[60]</ref>, e.g. an image of a '5' that is similar to a '6'.</p><p>&#8226; Near-OOD: Near-OOD represents a label shift where label space is different between ID and OOD data. It has high epistemic uncertainty arising from the classifier's limited information on unseen data. We use samples from unseen classes of the training distribution as near-OOD.</p><p>&#8226; Far-OOD: Far-OOD represents data distribution that is significantly different from the training distribution. It has high epistemic uncertainty arising from mismatch between different data distributions.</p><p>Much of the earlier work focuses on threshold-based detectors that use information from a pre-trained DNN to identify OOD samples <ref type="bibr">[15,</ref><ref type="bibr">19,</ref><ref type="bibr">24,</ref><ref type="bibr">68,</ref><ref type="bibr">21]</ref>. Such methods focus on far-OOD detection and often do not address the overconfidence problem in DNN. In another line of research, variants of Bayesian models <ref type="bibr">[52,</ref><ref type="bibr">9]</ref> and ensemble learning <ref type="bibr">[22,</ref><ref type="bibr">33]</ref> were explored to provide reliable uncertainty estimates. Recently, there is a shift towards designing generalizable DNN that provide robust uncertainty estimates in a single forward pass <ref type="bibr">[65,</ref><ref type="bibr">4,</ref><ref type="bibr">48]</ref>. Such methods usually propose changes to the DNN architecture <ref type="bibr">[62]</ref>, training procedure <ref type="bibr">[71]</ref> or loss functions <ref type="bibr">[50]</ref> to encourage separation between ID and OOD data. Popular methods include, Comparison of the uncertainty estimates from the baseline, before (dotted line) and after (solid line) fine-tuning with augmentation by counterfactual explanation (ACE). The plots visualize the distribution of predicted entropy (columns A-C) from the classifier and density score from the discriminator (column D). The y-axis of this density plot is the probability density function whose value is meaningful only for relative comparisons between groups, summarized in the legend. A) visualizes the impact of fine-tuning on the in-distribution (iD) samples. A large overlap suggests minimum changes to classification outcome for iD samples. Next columns visualize change in the distribution for ambiguous iD (AiD) (B) and near-OOD samples (C). The peak of the distribution for AiD and near-OOD samples shifted right, thus assigning higher uncertainty and reducing overlap with iD samples. D) compares the density score from discriminator for iD (blue solid) and far-OOD (orange solid) samples. The overlap between the distributions is minimum, resulting in a high AUC-ROC for binary classification over uncertain samples and iD samples. Our method improved the uncertainty estimates across the spectrum.</p><p>training deterministic DNN with a distance-aware feature space <ref type="bibr">[66,</ref><ref type="bibr">42]</ref> and regularizing DNN training with a generative model that simulates OOD data <ref type="bibr">[36]</ref>. However, these methods require a DNN model to be trained from scratch and are not compatible with an existing pre-trained DNN. Also, they may use auxiliary data to learn to distinguish OOD inputs <ref type="bibr">[43]</ref>.</p><p>Most of the DNN-based classification models are trained to improve accuracy on a test set. Accuracy only captures the proportion of samples that are on the correct side of the decision boundary. However, it ignores the relative distance of a sample from the decision boundary <ref type="bibr">[31]</ref>. Ideally, samples closer to the boundary should have high uncertainty. The actual predicted value from the classifier should reflect this uncertainty via a low confidence score <ref type="bibr">[25]</ref>. Conventionally, DNNs are trained on hard-label datasets to minimize a negative log-likelihood (NLL) loss. Such models tend to over-saturate on NLL and end-up learning very sharp decision boundaries <ref type="bibr">[16,</ref><ref type="bibr">49]</ref>. The resulting classifiers extrapolate over-confidently on ambiguous, near boundary samples, and the problem amplifies as we move to OOD regions <ref type="bibr">[8]</ref>.</p><p>In this paper, we propose to mitigate the overconfidence problem of a pre-trained DNN by fine-tuning it with augmentations derived from a counterfactual explainer (ACE). We derived counterfactuals using a progressive counterfactual explainer (PCE) that create a series of perturbations of an input image, such that the classification decision is changed to a different class <ref type="bibr">[58,</ref><ref type="bibr">34]</ref>. PCE is trained to generate on-manifold samples in the regions between the classes. These samples along with soft labels that mimics their distance from the decision boundary, are used to finetuned the classifier. We hypothesis that fine-tuning on such data would broaden the classifier's decision boundary. Our empirical results show the fine-tuned classifier exhibits better uncertainty quantification over ambiguous-iD and OOD samples. Our contributions are as follows: <ref type="bibr">(1)</ref> We present a novel strategy to fine-tune an existing pre-trained DNN using ACE, to improve its uncertainty estimates. (2) We proposed a refined architecture to generate counterfactual explanations that takes into account continuous condition and multiple target classes. (3) We used the discriminator of our GAN-based counterfactual explainer as a selection function to reject far-OOD samples. (4) The fine-tuned classifier with rejection head, successfully captures uncertainty over ambiguous-iD and OOD samples, and also exhibits better robustness to popular adversarial attacks.</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="2.">Method</head><p>In this paper, we consider a pre-trained DNN classifier, f &#10003; , with good prediction accuracy but sub-optimal uncertainty estimates. We assume f &#10003; is a differentiable function and we have access to its gradient with respect to the input, r x f &#10003; (x), and to its final prediction outcome f &#10003; (x). We also assume access to either the training data for f &#10003; , or an equivalent dataset with competitive prediction accuracy. We further assume that the training dataset for f &#10003; has hard labels {0, 1} for all the classes.    Our goal is to improve the pre-trained classifier f &#10003; such that the revised model provides better uncertainty estimates, while retaining its original predictive accuracy. To enable this, we follow a two step approach. First, we fine-tune f &#10003; on counterfactually augmented data. The fine-tuning helps in widening the classification boundary of f &#10003; , resulting in improved uncertainty estimates on ambiguous and near-OOD samples. Second, we use a density estimator to identify and reject far-OOD samples.</p><p>We adapted previously proposed PCE <ref type="bibr">[58]</ref> to generate counterfactually augmented data. We improved the existing implementations of PCE, by adopting a StyleGANv2based backbone for the conditional-GAN in PCE. This allows using continuous vector f &#10003; (x) as condition for conditional generation. Further, we used the discriminator of cGAN as a selection function to abstain revised f &#10003;+ from making prediction on far-OOD samples (see Fig. <ref type="figure">2</ref>).</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head>Notation:</head><p>The classification function is defined as f &#10003; : R d ! R K , where &#10003; represents model parameters. The training dataset for f &#10003; is defined as D = {X , Y}, where x 2 X represents an input space and y 2 Y = {1, 2, &#8226; &#8226; &#8226; , K} is a label set over K classes. The classifier produces point estimates to approximate the posterior probability P(y|x, D).</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="2.1.">Progressive Counterfactual Explainer (PCE)</head><p>We designed the PCE network to take a query image (x 2 R d ) and a desired classification outcome (c 2 R K ) as input, and create a perturbation of a query image (x) such that f &#10003; (x) &#8673; c. Our formulation, x = G(x, c) allows us to use c to traverse through the decision boundary of f &#10003; from the original class to a counterfactual class. Following previous work <ref type="bibr">[34,</ref><ref type="bibr">58,</ref><ref type="bibr">59]</ref>, we design the PCE to satisfy the following three properties:</p><p>1. Data consistency: The perturbed image, x should be realistic and should resemble samples in X .</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="2.">Classifier consistency:</head><p>The perturbed image, x should produce the desired output from the classifier</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="3.">Self consistency:</head><p>Using the original classification decision f &#10003; (x) as condition, the PCE should produce a perturbation that is very similar to the query image,</p><p>Data Consistency: We formulate the PCE as a cGAN that learns the underlying data distribution of the input space X without an explicit likelihood assumption. The GAN model comprised of two networks -the generator G(&#8226;) and the discriminator D(&#8226;). The G(&#8226;) learns to generate fake data, while the D(&#8226;) is trained to distinguish between the real and fake samples. We jointly train G, D to optimize the following logistic adversarial loss <ref type="bibr">[12]</ref>,</p><p>The earlier implementations of PCE <ref type="bibr">[58]</ref>, have a hard constraint of representing the condition c as discrete variables. f &#10003; (x) is a continuous variable in range [0, 1]. We adapted StyleGANv2 <ref type="bibr">[1]</ref> as the backbone of the cGAN. This formulation allow us to use c 2 R K as condition.</p><p>We formulate the generator as G(x, c) = g(e(x), c), a composite of two functions, an image encoder e(&#8226;) and a conditional decoder g(&#8226;) <ref type="bibr">[1]</ref>. The encoder function e : X ! W + , learns a mapping from the input space X to an extended latent space W + . The detailed architecture is provided in Fig. <ref type="figure">3</ref>. Further, we also extended the discriminator network D(&#8226;) to have auxiliary information from the classifier f &#10003; . Specifically, we concatenate the penultimate activations from the f &#10003; (x) with the penultimate activations from the D(x), to obtain a revised representation before the final fully-connected layer of the discriminator. The detailed architecture is summarized in supplementary material (SM).</p><p>x &lt; l a t e x i t s h a 1 _ b a s e 6 4 = " k t T 5 k y Z q 9 6 p 4 O K 5 We also borrow the concept of path-length regularization L reg (G) from StyleGANv2 to enforce smoother latent space interpolations for the generator.</p><p>, where x denotes random images from the training data, J w is the Jacobian matrix, and a is a constant that is set dynamically during optimization.</p><p>Classifier consistency: By default, GAN training is independent of the classifier f &#10003; . We add a classifierconsistency loss to regularize the generator and ensure that the actual classification outcome for the generated image x, is similar to the condition c used for generation. We enforce classification-consistency by a KullbackLeibler (KL) divergence loss as follow <ref type="bibr">[58,</ref><ref type="bibr">59]</ref>,</p><p>Self consistency: We define the following reconstruction loss to regularize and constraint the Generator to preserve maximum information between the original image x and its reconstruction x,</p><p>Here, first term is an L1 distance loss between the input and the reconstructed image, and the second term is a style reconstruction L1 loss adapted from StyleGANv2 <ref type="bibr">[1]</ref>. We minimize this loss to satisfy the identify constraint on self reconstruction using xself = G(x, f &#10003; (x)). We further insure that the PCE learns a reversible perturbation by recovering the original image from a given perturbed image x as xcyclic = G(x, f &#10003; (x)), where x = G(x, c) with some condition c. Our final reconstruction loss is defined as,</p><p>Objective function: Finally, we trained our model in an endto-end fashion to learn parameters for the two networks, while keeping the classifier f &#10003; fixed. Our overall objective function is</p><p>where, 's are the hyper-parameters to balance each of the loss terms. </p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="2.2.">Augmentation by Counterfactual Explanation</head><p>Ideally, the predicted confidence from NN should be indicative of the distance from the decision boundary. Samples that lies close to the decision boundary should have low confidence, and confidence should increase as we move away from the decision boundary. We used c as a pseudo indicator of confidence to generate synthetic augmentation. Our augmentations are essentially showing how the query image x should be modified to have low/high confidence.</p><p>To generate counterfactual augmentations, we randomly sample a subset of real training data as X r &#8674;X . Next, for each x 2 X r we generate multiple augmentations (x = G(x, c)) by randomly sampling c[k] 2 [0, 1]. We used c as soft label for the generate sample while fine-tuning the f &#10003; . The X c represents our pool of generated augmentation images. Finally, we create a new dataset by randomly sampling images from X and X c . We fine-tune the f &#10003; on this new dataset, for only a few epochs, to obtain a revised classifier given as f &#10003;+ . In our experiments, we show that the revised decision function f &#10003; provides improved confidence estimates for AiD and near OOD samples and demonstrate robustness to adversarial attacks, as compared to given classifier f &#10003; . </p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="2.3.">Discriminator as a Selection Function</head><p>where, f &#10003;+ is the fine-tuned classifier and D(&#8226;) is a discriminator network from the PCE which serves as a selection function that permits f to make prediction if D(x) exceeds a threshold h and abstain otherwise.</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="3.">Related Work</head><p>Uncertainty estimation in pre-trained DNN models: Much of the prior work focused on deriving uncertainty measurements from a pre-trained DNN output <ref type="bibr">[19,</ref><ref type="bibr">15,</ref><ref type="bibr">39,</ref><ref type="bibr">43]</ref>, feature representations <ref type="bibr">[41,</ref><ref type="bibr">37]</ref> or gradients <ref type="bibr">[24]</ref>. Such methods use a threshold-based scoring function to identify OOD samples. The scoring function is derived from softmax confidence scores <ref type="bibr">[19]</ref>, scaled logit <ref type="bibr">[15,</ref><ref type="bibr">41]</ref>, energybased scores <ref type="bibr">[43,</ref><ref type="bibr">68]</ref> or gradient-based scores <ref type="bibr">[24]</ref>. These methods help in identifying OOD samples but did not address the over-confidence problem of DNN, that made identifying OOD non-trivial in the first place <ref type="bibr">[18,</ref><ref type="bibr">54]</ref>. We propose to mitigate the over-confidence issue by fine-tuning the pre-trained classifier using ACE. Further, we used a hard threshold on the density score provided by the discriminator of the GAN-generator, to identify OOD samples.</p><p>DNN designs for improved uncertainty estimation: The Bayesian neural networks are the gold standard for reliable uncertainty quantification <ref type="bibr">[52]</ref>. Multiple approximate Bayesian approaches have been proposed to achieve tractable inference and to reduce computational complexity <ref type="bibr">[14,</ref><ref type="bibr">2,</ref><ref type="bibr">28,</ref><ref type="bibr">9]</ref>. Popular non-Bayesian methods include deep ensembles <ref type="bibr">[33]</ref> and their variant <ref type="bibr">[22,</ref><ref type="bibr">10]</ref>. However, most of these methods are computationally expensive and requires multiple passes during inference. An alternative approach is to modify DNN training <ref type="bibr">[63,</ref><ref type="bibr">71,</ref><ref type="bibr">67]</ref>, loss function <ref type="bibr">[50]</ref>, architecture <ref type="bibr">[62,</ref><ref type="bibr">42,</ref><ref type="bibr">11]</ref> or end-layers <ref type="bibr">[66,</ref><ref type="bibr">21]</ref> to support improved uncertainty estimates in a single forwardpass. Further, methods such as DUQ <ref type="bibr">[66]</ref> and DDU <ref type="bibr">[48]</ref> proposed modifications to enable the separation between aleatoric and epistemic uncertainty. Unlike these methods, our approach improves the uncertainty estimates of any existing pre-trained classifier, without changing its architecture or training procedure. We used the discriminative head of the fine-tuned classifier to capture aleatoric uncertainty and the density estimation from the GAN-generator to capture epistemic uncertainty.</p><p>Uncertainty estimation using GAN: A popular technique to fix an over-confident classifier is to regularize the model with an auxiliary OOD data which is either realistic <ref type="bibr">[20,</ref><ref type="bibr">46,</ref><ref type="bibr">55,</ref><ref type="bibr">4,</ref><ref type="bibr">40]</ref> or is generated using GAN <ref type="bibr">[56,</ref><ref type="bibr">36,</ref><ref type="bibr">45,</ref><ref type="bibr">70,</ref><ref type="bibr">57]</ref>. Such regularization helps the classifier to assign lower confidence to anomalous samples, which usually lies in the low-density regions. Defining the scope of OOD a-priori is generally hard and can potentially cause a selection bias in the learning. Alternative approaches resort to estimating in-distribution density <ref type="bibr">[61]</ref>. Our work fixed the scope of GAN-generation to counterfactual generation. Rather than merging the classifier and the GAN training, we train the GAN in a post-hoc manner to explain the decision of an existing classifier. This strategy defines OOD in the context of pre-trained classifier's decision boundary. Previously, training with CAD have shown to improved generalization performance on OOD samples <ref type="bibr">[27]</ref>. However, this work is limited to Natural Language Processing, and requires human intervention while curating CAD <ref type="bibr">[26]</ref>. In contrast, we train a GAN-based counterfactual explainer <ref type="bibr">[59,</ref><ref type="bibr">34]</ref> to derive CAD.</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="4.">Experiment</head><p>We consider four classification problems, in increasing level of difficulty:</p><p>1. AFHQ <ref type="bibr">[5]</ref>: We consider binary classification over well separated classes, cat vs dog.</p><p>2. Dirty MNIST <ref type="bibr">[48]</ref>: We consider multi-class classification over hand-written digits 0-6. The dataset is a combination of original MNIST <ref type="bibr">[35]</ref> and simulated samples from a variational decoder. The samples are generated by combining latent representation of different digits, to simulate ambiguous samples, with multiple plausible labels <ref type="bibr">[48]</ref>.</p><p>3. CelebA <ref type="bibr">[44]</ref>: We consider a multi-label classification setting over 'young' and 'smiling' attributes. Without age labels, identifying 'young' faces is a challenging task.</p><p>4. Skin lesion (HAM10K) <ref type="bibr">[64]</ref>: We consider a binary classification to separate Melanocytic nevus (nv) from Melanoma (mel) and Benign Keratosis (bkl) lesions. Skin lesion classification is a challenging task as different lesions may exhibit similar features <ref type="bibr">[51]</ref>.</p><p>Architecture details: We consider state-of-the-art DenseNet <ref type="bibr">[23]</ref> architecture for the baseline. The pretrained DenseNet model followed the training procedures as described in <ref type="bibr">[23]</ref>. In order to keep the architecture and training procedure of PCE simple, we consider the default training parameters from <ref type="bibr">[1]</ref> for training the Style-GANv2. This encourages reproducibility as we didn't do hyper-parameter tuning for each dataset and classification model. For training StyelGANv2, we use a randomly sampled subset (&#8672; 50%) of the baseline model's training data. For multi-class classification, we consider all pairs Comparison methods: Our baseline is a standard DNN classifier f &#10003; trained with cross-entropy loss. For baseline and its post-hoc variant with temperature-scaling (TS), we used threshold over predictive entropy (PE) to identify OOD. PE is defined as</p><p>Next, we compared against following five methods: mixup: baseline model with mixup training using &#8629; = 0.2 <ref type="bibr">[71]</ref>; deterministic uncertainty quantification (DUQ) <ref type="bibr">[66]</ref>: baseline model with radial basis function as end-layer; DDU: that use the closest kernel distance to quantify uncertainties; MC Dropout (with 20 dropout samples) <ref type="bibr">[9]</ref>; and five independent runs of baseline as 5-Ensemble <ref type="bibr">[33]</ref>. The ensemble approaches are an upper bound for UQ.</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="4.1.">Identifying AiD samples</head><p>We do not have access to ground truth labels marking the samples that are AiD. Hence, we used the PE estimates from an MC Dropout classifier to obtain pseudo-ground truth for AiD classification. Specifically, we sort the test set using PE and consider the top 5 to 10% samples as AiD. In Fig. <ref type="figure">1</ref>, we qualitatively compare the PE distribution from the given baseline and its fine-tuned version (baseline + ACE). Finetuning resulted in minor changes to the PE distribution of the iD samples (Fig. <ref type="figure">1</ref>.A). We observe a significant separation in the PE distribution of AiD samples and the rest of the test set (Fig. <ref type="figure">1</ref>.B), even on the baseline. This suggests that the PE correctly captures the aleatoric uncertainty.</p><p>Table <ref type="table">1</ref> compares our model to several baselines. We report the test set accuracy, the AUC-ROC for the binary task of identifying AiD samples and the true negative rate (TNR) at 95% true positive rate (TPR) (TNR@TPR95), which simulates an application requirement that the recall of in-distribution data should be 95% <ref type="bibr">[21]</ref>. For all metrics higher value is better. Our model outperformed other deterministic models in identifying AiD samples with a high AUC-ROC and TNR@TPR95 across all datasets.</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="4.2.">Detecting OOD samples</head><p>We consider two tasks to evaluate the model's OOD detection performance. First, a standard OOD task where OOD samples are derived from a separate dataset. Second, a difficult near-OOD detection task where OOD samples belongs to novel classes from the same dataset, which are not seen during training. We consider the following OOD datasets:</p><p>1. AFHQ <ref type="bibr">[5]</ref>: We consider "wild" class from AFHQ to define near-OOD samples. For the far-OOD detection task, we use the CelebA dataset, and also cat/dog images from CIFAR10 <ref type="bibr">[32]</ref>.</p><p>2. Dirty MNIST <ref type="bibr">[48]</ref>: We consider digits 7-9 as near-OOD samples. For far-OOD detection, we use SVHN <ref type="bibr">[53]</ref> and fashion MNIST <ref type="bibr">[69]</ref> datasets.</p><p>3. CelebA <ref type="bibr">[44]</ref>: We consider images of kids in agegroup: 0-11 from the UTKFace <ref type="bibr">[72]</ref> dataset to define the near-OOD samples. For far-OOD detection task, we use the AFHQ and CIFAR10 datasets.</p><p>4. Skin lesion (HAM10K) <ref type="bibr">[64]</ref>: We consider samples from lesion types: Actinic Keratoses and Intraepithelial Carcinoma (akiec), Basal Cell Carcinoma (bcc), Dermatofibroma (df) and Vascular skin lesions (vasc) as near-OOD. For far-OOD, we consider CelebA and an additional simulated dataset with different skin textures/tones.</p><p>In Fig. <ref type="figure">1</ref>, we observe much overlap between the PE distribution of the near-OOD samples and in-distribution samples in Fig. <ref type="figure">1</ref>.C. Further, in Fig. <ref type="figure">1</ref>.D, we see that our model successfully disentangles OOD samples from the in-distribution samples by using density estimates from the discriminator of the PCE. In Table <ref type="table">2</ref>, we report the AUC-ROC and TNR@TPR95 scores on detecting the two types of OOD samples. We first use the discriminator from the PCE to detect far-OOD samples. The discriminator achieved near-perfect AUC-ROC for detecting far-OOD samples. We used the PE estimates from the finetuned model (baseline + ACE) to detect near-OOD samples. Overall our model outperformed other methods on both near and far-OOD detection tasks with high TNR@TPR95. MC Dropout <ref type="bibr">[9]</ref> 84.90&#177;1.17 0.85&#177;0.06 43.78&#177;1.9 5-Ensemble <ref type="bibr">[33]</ref> 87.89&#177;0.13 0.86&#177;0.02 40.49&#177;5.1</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="4.3.">Robustness to Adversarial Attacks</head><p>We compared the baseline model before and after finetuning (baseline + ACE) in their robustness to three adversarial attacks: Fast Gradient Sign Method (FGSM) <ref type="bibr">[13]</ref>, Carlini-Wagner (CW) <ref type="bibr">[3]</ref>, and DeepFool <ref type="bibr">[47]</ref>.</p><p>For each attack setting, we transformed the test set into an adversarial set. In Fig. <ref type="figure">5</ref>, we report the AUC-ROC over the adversarial set as we gradually increase the magnitude of the attack. For FGSM, we use the maximum perturbation (&#9999;) to specify the attack's magnitude. For CW, we gradually increase the number of iterations to an achieve a higher magnitude attack. We set box-constraint parameter as c = 1, learning rate &#8629; = 0.01 and confidence &#63743; = 0, 5. For DeepFool (&#8984; = 0.02), we show results on the best attack. Our improved model (baseline + ACE) consistently out-performed the baseline model in test AUC-ROC, thus showing an improved robustness to all three attacks. </p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="5.">Conclusion</head><p>We propose a novel application of counterfactual explanations in improving the uncertainty quantification of a pre-trained DNN. We improved upon the existing work on counterfactual explanations, by proposing a StyleGANv2based backbone. Fine-tuning on augmented data, with soft labels helps in improving the decision boundary and the fine-tuned model, combined with the discriminator of the PCE can successfully capture uncertainty over ambiguous samples, unseen near-OOD samples with label shift and far-OOD samples from independent datasets. We out-performed state-of-the-art methods for uncertainty quantification on four datasets, and our improved model also exhibits robustness to adversarial attacks.</p><p>6. Supplemental Material 6.1. Implementation Details</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="6.1.1">Dataset</head><p>We focus on improving classification models based on deep convolution neural networks (CNN) as most state-of-theart performance models fall in this regime. In our experiments, we consider classification models trained on following datasets:</p><p>1. AFHQ <ref type="bibr">[5]</ref>: Animal face high quality (AFHQ) dataset is a high resolution dataset of animal faces with 16K images from cat, dog and wild labels. In our experiments, we consider a multi-class classifier over cat and dog labels. We consider images with "wild" label as near-OOD. The classifier is trained at an image resolution of 256 &#8677; 256.</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="2.">Dirty MNIST [48]:</head><p>The dataset is a combination of original MNIST <ref type="bibr">[35]</ref> and simulated Ambiguous-MNIST dataset. Each sample in Ambiguous-MNIST is constructed by decoding a linear combination of latent representations of two different MNIST digits from a pre-trained VAE <ref type="bibr">[29]</ref>. The training dataset of the classifier comprises of 60K clean-MNIST and 60K Ambiguous-MNIST samples, with one-hot labels.</p><p>In our experiments, we consider classifier trained on seven classes over digits '0' -'6'. We consider images from digits '7' -'9' as near-OOD samples. The original dataset consists of grayscale images of size 28&#8677;28 pixels. We consider a classification model trained on 64&#8677;64 resolution.</p><p>3. Skin lesion (HAM10K) <ref type="bibr">[64]</ref>: The HAM10000 is a dataset of 100K dermatoscopic images of pigmented skin lesions. It contains seven different lesion types -Melanocytic Nevi (nv), Melanoma (mel), Benign Keratosis (bkl), Actinic Keratoses and Intraepithelial Carcinoma (akiec), Basal Cell Carcinoma (bcc), Dermatofibroma (df), Vascular skin lesions (vasc). In our experiments, we consider classifier trained to distinguish the majority class nv from mel and bkl. We consider images from rest of the lesions as near-OOD. The classifier is trained at an image resolution of 256&#8677;256.</p><p>4. CelebA <ref type="bibr">[44]</ref> : Celeb Faces Attributes Dataset (CelebA) is a large-scale face attributes dataset with more than 200K celebrity images, each with 40 binary attributes annotations per image. In our experiments, we consider a two-class classifier over attributes "Young" and "Smiling" trained on CelebA dataset. Our AiD samples comprises of middle-aged people who are arguably neither young nor old. To obtain such data, we use aleatoric uncertainty estimates  from MC-Dropout averaged across 50 runs on test-set of CelebA. The classifier is trained at an image resolution of 256 &#8677; 256. We center-crop the images as a pre-processing step.</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="6.1.2">Classification Model</head><p>We used DenseNet architecture as the classification model. In DenseNet, each layer implements a non-linear transformation based on composite functions such as Batch Normalization (BN), rectified linear unit (ReLU), pooling, or convolution. The resulting feature map at each layer is used as input for all the subsequent layers, leading to a highly convoluted multi-level multi-layer non-linear convolutional neural network. We aim to improve such a model in a posthoc manner without accessing the parameters learned by any layer or knowing the architectural details. Our proposed approach can be used for any DNN architecture.</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="6.2.">Progressive Counterfactual Explainer</head><p>We formulate the progressive counterfactual explainer (PCE) as a composite of two functions, an image encoder e(&#8226;) and a conditional decoder (g(&#8226;)) <ref type="bibr">[1]</ref>. Our architecture for the conditional decoder is adapted from Style-GANv2 <ref type="bibr">[1]</ref>. The image encoder converts the input image x into l different latent codes (w l 2 R 512 ), for each of the L layers of the decoder. The decoder further transforms the layer-specific latent representation into a layerspecific style-vector as s l = A l ([w l , (c)]) where, A l is an affine transformation and (c) is an embedding for c. For generating counterfactually augmented data, we first consider a randomly selected subset of real training data as X r 2 X. For each image in X r , we generate four augmented images by randomly selecting the c[k]. For each augmented image, we used the condition used to generate the image as the soft label while fine-tuning. Fig. <ref type="figure">7</ref> shows an example of our data augmentation. We denote the pool of the augmented images as X c . In Fig. <ref type="figure">6</ref>, we show examples of counterfactual augmentation from different datasets.</p><p>For fine-tuning the given baseline with consider a combination of the original training dataset X and the augmented data X c . We randomly selected a subset of samples from the two distributions and fine-tune the baseline for 5 to 10 epochs. We used the expected calibration error and the testset accuracy to choose the final checkpoint. Our model does not require access to OOD or AiD dataset during finetuning. During evaluation we compute predicted entropy (PE) for original test-set and OOD samples and measure for a range of thresholds how well the two are separated. We report the AUC-ROC and the true negative rate (TNR) at 95% true positive rate (TPR) (TNR@TPR95) in our results (see Table <ref type="table">1</ref> and<ref type="table">2</ref>).</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="6.3.">Toy-Setup: Two-Moons</head><p>In this section, we demonstrate our method on a toy setup: the Two Moons dataset. We used the experimental set-up from DDU <ref type="bibr">[48]</ref> for this experiment. We use scikitlearn's datasets package to generate 2000 samples with a noise rate of 0.1. For baseline classification model, we use a 2-layer dense-layer architecture, with ReLU activation and batch normalization. The 2-D input data is projected to a 64-D latent space and then to 1D space to make final binary prediction. In Fig. <ref type="figure">8</ref>.a, we show the uncertainty estimates (predicted entropy PE) from the baseline classifier. The baseline classifier is uncertain only along the decision boundary, and certain elsewhere (low PE).</p><p>Given the baseline classifier, we train a PCE to gener- </p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="6.4.">Additional Results</head><p>Much of the prior work has focused on obtaining uncertainty estimates from a pre-trained DNN output using threshold-based scoring functions. Liu et al <ref type="bibr">[43]</ref> in their paper show how energy functions can be used not only as scoring functions but also as a trainable cost-function to shape the energy surface explicitly for OOD-detection. Hendrycks et al <ref type="bibr">[20]</ref> propose the Outlier Exposure method which regularizes the softmax outputs to be a uniform distribution for outlier data. We compare these commonly-used methods against our technique (ACE) and show the results in Tables <ref type="table">3</ref> and<ref type="table">4</ref>. Our method is consistent and competitive, if not outperforming, across all datasets and AiD/OOD categories.</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="6.5.">Ablation Study</head><p>We conducted an ablation study over the three loss terms of PCE in Eq. 5. The three terms of the loss function enforces three properties of counterfactual explanation, data consistency: explanations should be realistic looking images, classifier consistency: explanations should produce a desired outcome from the classifier and self consistency: explanation image should retain the identity of the query image. For ablation study we consider the cat and dog classifier. We train three PCE, in each run we ablate one term from the final loss function. In Fig. <ref type="figure">9</ref>, we show qualitative example of the counterfactual data augmentation generated through each PCE. Without data consistency, the images are blur and are no longer realistic. Without classifier consistency loss, though the images are realistic, but the output Further, in Fig. <ref type="figure">10</ref> we present quantitatively compare the uncertainty estimates from the baseline, before and after the fine-tuning with ACE. In each row, we represent a different ablation over the three loss terms. Fig. <ref type="figure">10</ref>.A. shows the predicted entropy (PE) of in-distribution (iD) samples. Ideally, fine-tuning should minimally effect the PE distribution over iD samples. Without classification consistency loss (second row), the PE distribution of iD samples changed significantly. Fig. <ref type="figure">10</ref>.B and Fig. <ref type="figure">10</ref>.C shows the PE distribution over ambiguous in-distribution (AiD) samples and near-OOD samples, respectively. The data augmentation derived from PCE without adversarial loss or reconstruction loss, is not able to separate AiD samples or near-OOD from rest of the test set. In Fig. <ref type="figure">10</ref>.D, we use the discriminator of the PCE to identify far-OOD samples. In all three rows, we observe sub-optimal performance of the discriminator in identifying and rejecting far-OOD samples. The legend shows the AUC-ROC for binary classification over uncertain samples and iD samples. Hence, all three loss terms are important to improve the uncertainty estimates of the baseline over all samples across the uncertainty spectrum.</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="6.6.">Robust Generalization</head><p>In this experiment, we establish a connection between loss landscape plots and generalization of classifiers. In or-</p></div></body>
		</text>
</TEI>
