Covariate Shift Detection via Domain Interpolation Sensitivity
Abstract
Covariate shift is a major roadblock in the reliability of image classifiers in the real world.
Work on covariate shift has been focused on training classifiers to adapt or generalize to unseen domains.
However, for transparent decision making, it is equally desirable to develop covariate shift detection methods that can indicate whether or not a test image belongs to an unseen domain.
In this paper, we introduce a benchmark for covariate shift detection (CSD), that builds upon and complements previous work on domain generalization.
We use state-of-the-art
OOD detection 1 methods as baselines and find them to be worse than simple confidence-based methods on our CSD benchmark.
We propose an interpolationbased technique, Domain Interpolation Sensitivity (DIS), based on the simple hypothesis that interpolation between the test input and randomly sampled inputs from the training domain, offers sufficient information to distinguish between the training domain and unseen domains under covariate shift.
DIS surpasses all OOD detection baselines for CSD on multiple domain generalization benchmarks.
Introduction
Machine learning models such as image classifiers are being increasingly deployed in real-world settings.
Covariate shift is a commonly occurring phenomena, where test images are from the same categories as the training data, but undergo a shift in terms of style.
For instance, the training data may contain images taken during the day under sunny conditions but the classifier may encounter nighttime images or foggy or rainy images.
Models trained under the empirical risk minimization [36] paradigm can only offer performance guarantees under the i i d. setting and are known to fail under various types of covariate shift [33, 17, 2].
To mitigate the risks associated with covariate shift domain generalization algorithms have been developed [1, 38, 40, 10].
However, improving the accuracy of classifiers on unseen domains cannot be the only criteria for reliable decision making – for transparency, methods that detect covariate shift should also be investigated.
Unfortunately, this aspect of reliable decision making has not been previously explored.
In this paper, we investigate covariate shift detection (CSD) for image classifiers.
Methods for detecting “out-of-distribution” (OOD) test examples have been previously developed [18, 24, 23, 20, 3].
However it is important to note that OOD detection algorithms are designed to detect novel categories at test time.
In this paper, we are interested in detecting covariate shift (i.e. detecting test inputs that belong to a previously unseen domain, but one of the classes that the classifier is trained on).
Towards this end, we develop a new benchmark for covariate shift detection.
We utilize common domain generalization benchmarks and train the classifier on one of the domains, and benchmark
CSD methods’ performance in detecting images that belong to other domains.
An example is shown literature [Figure] [Figure] in Figure 1 – we compare the two dimensions of reliable predictions under covariate shift.
Domain generalization algorithms are trained with the aim of making accurate predictions for seen as well as unseen domains.
However in cases where accuracy under domain shift is low, it is equally important to detect, or flag, cases where there may be a covariate shift for safe and reliable use of classifiers.
Interpolation between training examples has been shown to provide unique information suitable for model regularization [31, 21].
Motivated by this, we hypothesize that interpolating test inputs with training inputs offers sufficient information to distinguish between in-domain and out-of-domain examples.
We use test-time interpolations as a powerful tool for understanding the behavior of pre-trained classifiers and detecting covariate shift.
Our motivation is as follows: if interpolations during training benefit model generalization, then interpolating test inputs with training inputs could help us understand how the model might perform on unseen test distributions.
We develop a method, named “Domain Interpolation Sensitivity” (DIS), that achieves state-ofthe-art results on covariate shift detection for image classification and text classification.
We find that methods developed for OOD detection (novel category detection) underperform on the CSD benchmark.
Suprisingly we find that methods that perform better on OOD detection benchmarks than the maximum softmax probability (MSP) baseline by proposed by Hendrycks et al.
[18], perform much worse than MSP on our CSD benchmarks.
Our contributions are summarized below:
• We study covariate shift detection (CSD) as a mechanism for improving the reliability of classifier predictions; CSD is designed to complement domain generalization as a robustness metric.
• We propose CSD benchmarks that are derived from existing benchmarks for domain generalization.
• We develop a interpolation-based technique that outperforms existing outlier and OOD detection methods on four CSD benchmarks (three for image classification, and one for text classification).
Covariate Shift Detection
We will consider classification tasks, for which a neural network f is trained on a dataset D in containing labeled input–output pairs (x , y) , with inputs x ∈ X in and outputs y ∈ Y in .
Let D out denote previously unseen data.
The nature of the shift between D in and D out can take multiple forms.
One such type of distribution shift is the presence of novel categories in D out ,
i.e. if (x , y) ∈
D out , then the categorical label of x , y / ∈ Y out .
An example of this phenomena of novel categories is if D in is a dataset for cat-dog classification, whereas D out contains images of handwritten digits.
Another type of distribution shift can occur when the categorical space remains the same, but domain X out undergoes a covariate shift, i.e. p in (x) ̸ = p out (x) .
For example, a covariate shift exists between D in and D out if D in is a set of real cat-dog images while D out contains cartoons or sketches of cats and dogs.
In this paper, we will consider covariate shift.
Scoring Function for Covariate Shift Detection.
Covariate shift detection can be formulated as a binary classification task.
Given a classifier f trained on distribution D in , the goal is to design a estimator g that estimates whether or not a test input lies within the training domain.
[Equation]
The threshold γ is chosen such that 95% of in-domain data is correctly classified by Eq.
The choice of the scoring function S is the key to improving covariate shift detection.
Previous approaches for
OOD detection have utilized the model’s outputs (for eg.
the maximum softmax probability [18], or energy of the softmax output [24]), or model’s gradient space [20].
In this work, we develop a scoring function S ( x ) by leveraging the interpolation of the test input with training inputs.
Benchmarking Covariate Shift Detection.
We leverage existing domain generalization datasets for benchmarking CSD.
Specifically, we operate under the single-source domain genralization setting [38], where the classifier is trained only on one domain and tested on all domains within the dataset.
This is illustrated in Figure 1 which shows domain generalization on the PACS [22] dataset – the classifier is trained on real-world photos (source domain) and tested on all domains including photos, art-paintings, cartoons, and sketches.
Given a classifier trained on the source domain D i n , the goal of a covariate shift detection algorithm is to use a scoring function S ( x ) to estimate whether or not x belongs to the source domain or not.
Thus, for any domain generalization dataset, we can compare performance of CSD algorithms on the corresponding CSD benchmark.
Domain Interpolation Sensitivity
In this section, we describe our method for covariate shift detection using test-time input interpolation.
Test-Time Input Interpolation.
Consider a randomly sampled training input x i ∈ X in and a test input x .
We define the interpolation of x i and x to be ˆ x = h
(x i , x , ϵ ) for a mixing coefficient ϵ ∈ [0 , 1] .
Note that h (x i , x , 0) =
x and h (x i , x , 1) =
x i .
In practice, h can be implemented in multiple ways; for image classification tasks, we use a simple pixel-wise convex combination.
For text classification, we use a token-wise swapping.
[Equation]
Domain Interpolation Sensitivity.
Let [0 , ϵ, 2 ϵ . . .
Tϵ ] be an increasing sequence of mixing coefficients such that 0 ≤ ϵ ≤ Tϵ ≤ 1 .
We generate a sequence of interpolated images
[Equation]
We obtain a corresponding sequence of softmax predictions probabilities from model f as:
[Equation]
Note that we can generate Y i for each choice of training exemplar X i .
By using n training exemplars, we can obtain an average prediction sequence ¯ Y :
[Equation]
Let c = argmax Y in f (x) be the predicted category for the test input.
Then, the domain interpolation sensitivity curve is defined as the softmax probability of c in each element of ¯Y .
Once we’ve obtained the above DIS curves, we use the area under the DIS curve as the scoring function S ( x ) for covariate shift detection, i.e. S ( x ) =
AUC (¯Y) .
Experiments
Baselines. We use widely adopted OOD detection approaches MSP [18], Energy [24], ODIN [23], and GradNorm [20] as our baselines.
These methods do not rely on any additional training or other modifications to the classifier used for detection and are thus comparable to our own approach.
The key observation is that recent OOD methods perform worse than the baseline MSP [18], in terms of and
Our DIS method improves CSD detection performance on
[Table] Metrics. For comparative evaluation of our method against the baselines, we use two standard metrics [18]; these are: (i) AUROC : area under the ROC curve OOD set the true positive
Datasets. We consider three image classification benchmarks: PACS [22], OfficeHome [37] [Table]
and ColoredMNIST [1], as well as a proposed text review classification benchmark inspired by [19].
PACS contains four domains: photos, art-paintings, cartoons, and sketches.
OfficeHome contains four domains: real images, art, clipart, and product images.
ColoredMNIST contains three domains of digit images with varying degrees of spurious correlations (+90, +80, -90) between the digit and color.
The proposed text classification benchmark contains four sentiment analysis domains collected from different review websites: Yelp, Rotten Tomatoes, IMDB [25], and Amazon [27, 15].
For the image classification benchmarks, we follow the training protocol from DomainBed [13] and train a ResNet-18 model [14] on ‘Photos’ for PACS, ‘Real’ for OfficeHome and the domain with “+90” spurious correlation for ColoredMNIST.
For our text benchmark, we use BERT [6] with a classification head fine-tuned on the Yelp domain and 1000 randomly selected examples from the test sets of the other domains for covariate shift detection.
Hyperparameters.
For image classification experiments, we use n =16 exemplars, step size ϵ =0 . 05 , and number of interpolation steps T =4 .
For text classification, we use n =16 exemplars, step size ϵ =1 token, and number of interpolation steps T equal to a quarter of the total token length.
Results.
Our results on the image classification and text classification benchmarks reveal the strength of the interpolation-based method, with consistent improvements both in terms of AUROC and FPR95 on both tasks.
Figure 2 summarizes our results on the image classification CSD benchmarks.
Interestingly, we observe that Energy, ODIN, and GradNorm, which have been shown to be better than MSP in the OOD detection literature, are in fact, much worse than MSP on all three benchmarks (OfficeHome, PACS, ColoredMNIST).
DIS outperforms all baselines.
Table 1 shows results on the text classification benchmark.
The observations are similar – sophisticated OOD detection methods perform worse than the baseline MSP, while DIS outperforms all methods.  Related Work Distributional Robustness.
Several dimensions of distribution robustness have been studied, which can be broadly classified into adversarial robustness [12, 26], natural distributional robustness, and spurious correlations.
Work on natural distributional robustness includes conditions such as common corruptions [17], variations along style [16], geometric [39] and attribute-level shift [9], different dataset sources [37, 22]. Spurious correlations of features such as background [2, 32] or texture [8] with label space have been studied. In terms of label shift, anomaly/outlier detection, novelty detection, open-set recognition, and OOD detection have been studied [41]. Correlation between ID and OOD performance.
It is well known that models tested on data with covariate shift suffer a drop in performance compared to in-domain (ID) accuracy.
Recently, there have been several studies that find a positive correlation between ID and OOD performance for tasks in both computer vision [29] and natural language processing [28].
However, Teney et al.[34] show that under certain real-world conditions, a negative correlation might exist, i.e. a decrease in ID accuracy may benefit OOD performance.
Moayeri et al.[30] show that there are trade-offs between adversarial and natural distributional robustness.
There is also empirical evidence [11] that suggests that data modification techniques (for instance, data augmentation or data filtering [4]) may have a negative impact on adversarial robustness.
With the context of these findings, there is a large gap in our understanding of different robustness settings – characterizing distribution shift in different ways is therefore crucial as a model selection criteria.
Our work aims to aid investigations in this direction.
Interpolation for Model Selection.
Interpolations have been extensively used for representation learning [43, 42, 31] for training robust classifiers.
Bhattacharjee et al.[3] used interpolation of inputs during training for novel category detection.
SMURF [7] used token interpolation between input texts and a noise process to estimate the robustness of language models based on the average monotonicity of a perplexity measure.
Outlook
In this work we introduced covariate shift detection benchmarks to study a complementary measure of model robustness.
Our experiments reveal that for the CSD task, sophisticated OOD detection methods are worse than even the simple MSP baseline.
We propose a simple interpolation-based detection technique that surpasses all baselines on multiple CSD benchmarks on both image classification and text classification tasks.
The results are promising and suggest that interpolation between training and test inputs can be a powerful tool for understanding and interpreting classification decisions as well as detecting outliers and covariate shift.
We believe that test-time interpolation could also be useful for uncertainty quantification – recent results [ show how anchoring (a variant of interpolation) can be used during training for this purpose.
In the future, we expect theoretical insights to emerge to complement our empirical findings with DIS
Appendix
The tables below show detailed results on each image classification benchmark, split by domain.
These correspond to the summarized results in Figure
[Table] [Table] [Table]