T EST T IME R OBUSTIFICATION OF D EEP M ODELS VIA A DAPTATION AND A UGMENTATION
Anonymous authors
Paper under double-blind review
A BSTRACT
While deep neural networks can attain good accuracy on in-distribution test points, many applications require robustness even in the face of unexpected perturbations in the input, changes in the domain, or other sources of distribution shift.
We study the problem of test time robustiﬁcation , i.e., using the test input to improve model robustness.
Recent prior works have proposed methods for test time adaptation, however, they each introduce additional assumptions, such as access to multiple test points, that prevent widespread adoption.
In this work, we aim to study and devise methods that make no assumptions about the model training process and are broadly applicable at test time.
We propose a simple approach that can be used in any test setting where the model is probabilistic and adaptable: when presented with a test example, perform different data augmentations on the data point, and then adapt (all of) the model parameters by minimizing the entropy of the model’s average, or marginal , output distribution across the augmentations.
Intuitively, this objective encourages the model to make the same prediction across different augmentations, thus enforcing the invariances encoded in these augmentations, while also maintaining conﬁdence in its predictions.
In our experiments, we demonstrate that this approach consistently improves robust ResNet and vision transformer models, achieving accuracy gains of 1-8% over standard model evaluation and also generally outperforming prior augmentation and adaptation strategies.
For the setting in which only one test point is available, we achieve state-of-the-art results on the ImageNet-C, ImageNet-R, and, among ResNet-50 models, ImageNet-A distribution shift benchmarks.
I NTRODUCTION
Deep neural network models have achieved excellent performance on many machine learning problems, such as image classiﬁcation, but are often brittle and susceptible to issues stemming from distribution shift .
For example, deep image classiﬁers may degrade precipitously in accuracy when encountering input perturbations, such as noise or changes in lighting (Hendrycks & Dietterich, 2019) or domain shifts which occur naturally in real world applications (Koh et al., 2021).
Therefore, robustiﬁcation of deep models against these test shifts is an important and active area of study.
Most prior works in this area have focused on techniques for training time robustiﬁcation, including utilizing larger models and datasets (Orhan, 2019), various forms of adversarial training (Sagawa et al., 2020;
Wong et al., 2020), and aggressive data augmentation (Yin et al., 2019; Hendrycks et al., 2020;
Li et al., 2021; Hendrycks et al., 2021a).
Employing these techniques requires modifying the training process, which may not be feasible if, e.g., it involves heavy computation or non-public data.
Furthermore, these techniques do not rely on any information about the test points that the model must predict on, even though these test points may provide signiﬁcant information for improving model robustness.
Recently, several works have proposed methods for improving accuracy via adaptation after seeing the test data, typically by updating a subset of the model’s weights (Sun et al., 2020), normalization statistics (Schneider et al., 2020), or both (Wang et al., 2021; Zhang et al., 2021).
Though effective at handling test shifts, these methods sometimes still require specialized training procedures, and they typically rely on extracting distributional information via batches or even entire sets of test inputs, thus introducing additional assumptions.
We are interested in studying and devising methods for improving model robustness that are “plug and play”, i.e., they can be readily used with a wide variety of pretrained models and test settings.
Such methods may simply constitute a different, more robust way to perform inference with preexisting models, under virtually the same assumptions as standard test time inference.
In this work, we focus on methods for test time robustness , in which the speciﬁc test input may be leveraged in order to improve the model’s prediction on that point.
Though broad applicability is our primary goal, we also want methods that synergize with other robustiﬁcation techniques, in order to achieve greater performance than using either set of techniques in isolation.
To satisfy both of these desiderata, we devise a novel test time robustness method based on adaptation and augmentation.
As illustrated in Figure 1, when presented with a test point, we propose to adapt the model by augmenting the test point in different ways and ensuring that the model makes the same predictions across these augmentations, thus respecting the invariances encoded in the data augmentations.
We further encourage the model to make conﬁdent predictions, thus arriving at the proposed method: minimize the marginal entropy of the model’s predictions across the augmented versions of the test point.
We refer to the proposed method as m arginal e ntropy m inimization with e nsembled augmentations (MEME), and this is the primary contribution of our work.
MEME makes direct use of pretrained models without any assumptions about their particular training procedure or architecture, while requiring only a single test input for adaptation.
In Section 4, we demonstrate empirically that MEME consistently improves the performance of ResNet (He et al., 2016) and vision transformer (Dosovitskiy et al., 2021) models on several challenging ImageNet distribution shift benchmarks, achieving several new state-of-the-art results for these models in the setting in which only one test point is available.
In particular, MEME consistently outperforms non adaptive marginal distribution predictions (between 1-10% improvement) on corruption and rendition shifts – tested by the ImageNet-C (Hendrycks & Dietterich, 2019) and
ImageNet-R
(Hendrycks et al., 2021a) datasets, respectively – indicating that adaptation plays a crucial role in improving predictive accuracy.
MEME encourages both invariance across augmentations and conﬁdent predictions, and an ablation study in Section 4 shows that both components are important for maximal performance gains.
Also, MEME is, to the best of our knowledge, the ﬁrst adaptation method to improve performance (by 1-4% over standard model evaluation) on ImageNet-A
(Hendrycks et al., 2021b), demonstrating that MEME is more broadly applicable on a wide range of distribution shifts.
R ELATED WORK
The general problem of distribution shift has been studied under a number of frameworks (Quiñonero
Candela et al., 2009), including domain adaptation (Shimodaira, 2000; Csurka, 2017; Wilson &
Cook, 2020), domain generalization (Blanchard et al., 2011; Muandet et al., 2013; Gulrajani &
Lopez-Paz, 2021), and distributionally robust optimization (Ben-Tal et al., 2013; Hu et al., 2018;
Sagawa et al., 2020), to name just a few.
These frameworks typically leverage additional training or test assumptions in order to make the distribution shift problem more tractable.
Largely separate from these frameworks, various empirical methods have also been proposed for dealing with shift, such as increasing the model and training dataset size or using heavy training augmentations (Orhan, 2019;
Yin et al., 2019; Hendrycks et al., 2021a).
The focus of this work is complementary to these efforts: the proposed MEME method is applicable to a wide range of pretrained models, including those trained via robustness methods, and can achieve further performance gains via test time adaptation.
Prior test time adaptation methods generally either make signiﬁcant training or test time assumptions.
Some methods update the model using batches or even entire datasets of test inputs, such as by computing batch normalization (BN) statistics on the test set (Li et al., 2017; Kaku et al., 2020;
Nado et al., 2020; Schneider et al., 2020), or minimizing the (conditional) entropy of model predictions across a batch of test data (Wang et al., 2021).
The latter approach is closely related to MEME.
The differences are that MEME minimizes marginal entropy using single test points and data augmentation and adapts all of the model parameters rather than just those associated with normalization layers, thus not requiring multiple test points or speciﬁc model architectures.
Other test time adaptation methods can be applied to single test points but require speciﬁc training procedures or models (Sun et al., 2020;
Huang et al., 2020; Schneider et al., 2020).
Test time training (TTT) (Sun et al., 2020) requires a specialized model with a rotation prediction head, as well as a different procedure for training this model.
Schneider et al.
(2020) show that BN adaptation can be effective even with only one test point, and we refer to this approach as “single point” BN adaptation.
As we discuss in
Section 3, MEME synergizes well with single point BN adaptation.
A number of works have noted that varying forms of strong data augmentation on the training set can improve the resulting model’s robustness (Yin et al., 2019;
Hendrycks et al., 2020; Li et al., 2021;
Hendrycks et al., 2021a).
Data augmentations are also sometimes used on the test data directly by averaging the model’s outputs across augmented copies of the test point (Krizhevsky et al., 2012;
Shorten & Khoshgoftaar, 2019), i.e., predicting according to the model’s marginal output distribution.
This technique, which we refer to as test time augmentation (TTA), has been shown to be useful both for improving model accuracy and calibration (Ashukha et al., 2020) as well as handling distribution shift (Molchanov et al., 2020).
We take this idea one step further by explicitly adapting the model such that its marginal output distribution has low entropy.
This extracts an additional learning signal for improving the model, and furthermore, the adapted model can then make its ﬁnal prediction on the clean test point rather than the augmented copies.
We empirically show in Section 4 that these differences lead to improved performance over this non adaptive TTA baseline.
R OBUSTNESS VIA A DAPTATION AND A UGMENTATION
Data augmentations are typically used to train the model to respect certain invariances – e.g., changes in lighting or viewpoint do not change the underlying class label – but, especially when faced with distribution shift, the model is not guaranteed to obey the same invariances at test time.
In this section, we introduce MEME, a method for test time robustness that adapts the model such that it respects these invariances on the test input.
We use “test time robustness” speciﬁcally to refer to techniques that operate directly on pretrained models and single test inputs – single point BN adaptation and
TTA, as described in Section 2, are examples of prior test time robustness methods.
In the test time robustness setting, we are given a trained model f θ : X → Y with parameters θ ∈ Θ .
We do not require any special training procedure and do not make any assumptions about the model, except that θ is adaptable and that f θ produces a conditional output distribution p θ ( y | x ) that is differentiable with respect to θ .
1 All standard deep neural network models satisfy these assumptions.
A single point x ∈ X is presented to f θ , for which it must predict a label ˆ y ∈ Y immediately.
Note that this is precisely identical to the standard test time inference procedure for regular supervised learning models – in effect, we are simply modifying how inference is done, without any additional assumptions on the training process or on test time data availability.
This makes test time robustness methods a simple “slot-in” replacement for the ubiquitous and standard test time inference process.
We assume sampling access to a set of augmentation functions
A (cid:44) { a 1 , . . .
, a M } that can be applied to the test point x .
Due to the compositionality of many commonly used augmentations, the set size
M may be extremely large or even inﬁnite.
We use these augmentations and the self-supervised objective detailed below to adapt the model before it predicts on x .
When given a set of test data { x (1) , . .
, x ( N ) } , the model adapts and predicts on each test point independently, i.e., in the same way as standard non adaptive models.
Note that we do not assume access to any ground truth labels.
3. M ARGINAL ENTROPY MINIMIZATION WITH ENSEMBLED AUGMENTATIONS
Given a test point x and set of augmentation functions A , we sample B augmentations from A and apply them to x in order to produce a batch of augmented data ˜ x 1 , . . . , ˜ x B .
The model’s average, or marginal , output distribution with respect to the augmented points is given by
[Equation]
where the expectation is with respect to uniformly sampled augmentations a ∼ U ( A ) .
What properties do we desire from this marginal distribution?
To answer this question, consider the role that data augmentation typically serves during model training.
For each training point ( x train , y train ) , the model f θ encounters multiple augmented forms of the input ˜ x train 1 , . . .
, ˜ x train E , where
E usually corresponds to the number of epochs of training, all with the same label y train .
In this way, f is trained to obey the invariances between the augmentations and the label – no matter the augmentation, f should predict the same label y train for x train , and furthermore, it should do so conﬁdently.
We seek to devise a similar learning signal during test time, when no ground truth labels are available.
That is, we wish to accomplish two goals after adapting the model on a test point: (1) the model f θ predictions should be invariant across augmented versions of
the
test point, and (2) the model f θ
should be conﬁdent in its predictions, even for heavily augmented versions of the test point, due to the additional knowledge that all versions have the same underlying label. Optimizing the model for more conﬁdent predictions can be justiﬁed from the assumption that the true underlying decision boundaries between classes lie in low density regions of the data space (Grandvalet & Bengio, 2005).
With these two goals in mind, we propose to adapt the model using the entropy of its marginal output distribution over augmentations (Equation 1), i.e.,
[Equation]
Given that θ is adaptable and p θ ( y | x ) is differentiable with respect to θ , we can directly use gradient based optimization to adapt θ according to this objective.
After this step, we can use the adapted model, which we denote f θ (cid:48) , to predict on the original test input x .
Algorithm 1 presents the overall method MEME for test time adaptation.
Though prior test time adaptation methods must carefully choose which parameters to adapt in order to avoid degenerate solutions (Wang et al., 2021), our adaptation procedure simply adapts all of the model’s parameters θ (line 3).
Note that, as discussed above, the model f θ adapts using augmented data but makes its ﬁnal prediction on the original point (line 4), which may be easier to predict on.
C OMPOSING MEME WITH PRIOR METHODS
An additional beneﬁt of MEME is that it synergizes with other approaches for handling distribution shift.
In particular, MEME can be composed with prior methods for training robust models and adapting model statistics, thus leveraging the performance improvements of each technique.
Pretrained robust models.
Since MEME makes no assumptions about, or modiﬁcations to, the model training procedure, performing adaptation on top of pretrained robust models, such as those trained with heavy data augmentations, is as simple as using any other pretrained model.
Crucially, we ﬁnd that, in practice, the set of augmentations that we use at test time A does not have to match the augmentations that were used to train the model.
This is important as we require a few properties from the test time augmentations: that they can be easily sampled, ideally can be applied in parallel, and are applied directly to the model input x .
These properties do not hold for, e.g., data augmentation techniques based on image translation models, such as DeepAugment (Hendrycks et al., 2021a), or feature mixing, such as moment exchange (Li et al., 2021).
However, we can still use models trained with these data augmentation techniques as our starting point for adaptation, thus allowing us to improve upon their state-of-the-art results.
As noted above, using pretrained models is not as easily accomplished for adaptation methods which require complicated or specialized training procedures and model architectures, such as TTT (Sun et al., 2020) or ARM (Zhang et al., 2021).
In our experiments, we use AugMix as our set of augmentations (Hendrycks et al., 2020), as it satisﬁes the above properties and still yields signiﬁcant diversity when applied, as depicted in Figure 2.
Adapting BN statistics.
Schneider et al.
(2020) showed that, even when presented with just a single test point, partially adapting the estimated mean and variance of the activations in each batch normalization (BN) layer of the model can still be effective in some cases for handling distribution shift.
In this setting, to prevent overﬁtting to the test point, the channelwise mean and variance [ µ test , σ 2 test ] estimated from this point are mixed with the the mean and variance [ µ train , σ 2 train ] computed during training according to a prior strength N , i.e.,
[Equation]
This technique is also straightforward to combine with MEME: we simply use the adapted BN statistics whenever computing the model’s output distribution. That is, we always use single point BN adaptation in conjunction with MEME.
Following the suggestion in Schneider et al.
, we set N = 16 for all of our experiments in the next section.
E XPERIMENTS
Our experiments aim to answer the following questions:
(1) How does MEME compare to prior methods for test time adaptation, which make additional training and test assumptions, and test time robustness?
(2) Can MEME be successfully combined with a wide range of pretrained models?
(3) Which aspects of MEME are the most important for strong performance?
We conduct experiments on two distribution shift benchmarks for CIFAR-10 (Krizhevsky, 2009) and three distribution shift benchmarks for ImageNet (Russakovsky et al., 2015).
Speciﬁcally, for
CIFAR-10, we evaluate on the CIFAR-10-C (Hendrycks & Dietterich, 2019) and CIFAR-10.1 (Recht et al., 2018) test sets, and for ImageNet, we evaluate on the ImageNet-C (Hendrycks & Dietterich, 2019), ImageNet-R (Hendrycks et al., 2021a), and ImageNet-A (Hendrycks et al., 2021b) test sets.
To answer question (1), we compare to test time training (TTT) (Sun et al., 2020) in the CIFAR10 experiments, for which we train ResNet-26 models following their protocol and specialized architecture.
We do not compare to TTT for the ImageNet experiments due to the computational demands of training state-of-the-art models and because Sun et al.
(2020) do not report competitive
ImageNet results.
For the ImageNet experiments, we compare to Tent (Wang et al., 2021) and BN adaptation, which can be used with pretrained models but require multiple test inputs (or even the entire test set) for adaptation.
We provide BN adaptation with 256 test inputs at a time and, following Schneider et al.
(2020), set the prior strength N = 256 accordingly.
For Tent, we use test batch sizes of 64 and run online adaptation for the entire epoch through the test set (Wang et al., 2021). Note that the evaluation protocols are different for these two methods: whereas MEME is tasked with predicting on each test point immediately after adaptation, BN adaptation predicts on a batch of 256 test points after computing BN statistics on the batch, and Tent predicts on a batch of 64 inputs after adaptation but also continually adapts throughout evaluation.
In all experiments, we further compare to single point BN adaptation (Schneider et al., 2020) and the TTA baseline that simply predicts according to the model’s marginal output distribution over augmentations ¯ p θ ( y | x ) (Equation 1) (Krizhevsky et al., 2012; Ashukha et al., 2020).
Full details on our experimental protocol are provided in Appendix A.
To answer question (2), we apply MEME on top of multiple pretrained models with different architectures, trained via several different procedures.
For CIFAR-10, we train our own ResNet26 (He et al., 2016) models.
For ImageNet, we use the best performing ResNet-50 robust models from prior work, which includes those trained with DeepAugment and AugMix augmentations (Hendrycks et al., 2021a) as well as those trained with moment exchange and CutMix (Li et al., 2021).
To evaluate the generality of prior test time robustness methods and MEME, we also evaluate the small robust vision transformer (RVT ∗ -small), which provides superior performance on all three ImageNet distribution shift benchmarks compared to the robust ResNet-50 models (Mao et al., 2021).
Finally, to answer (3), we conduct ablative studies in subsection 4.2: ﬁrst to determine the relative importance of maximizing conﬁdence (via entropy minimization) versus enforcing invariant predictions across augmented copies of each test point, and second to determine the importance of the particular augmentation functions used.
The comparison to the non adaptive TTA baseline also helps determine whether simply augmenting the test point is sufﬁcient or if adaptation is additionally helpful.
4. M AIN RESULTS
We summarize results for CIFAR-10, CIFAR-10.1, and CIFAR-10-C in Table 1, with full CIFAR-10C results in Appendix B. We use indentations to indicate composition, e.g., TTT is performed at test time on top of their specialized joint training procedure.
Across all corruption types in CIFAR-10-C, MEME consistently improves test error compared to the baselines, non adaptive TTA, and TTT.
MEME also provides a larger performance gain on CIFAR-10.1 compared to TTT.
We ﬁnd that the non adaptive TTA baseline is competitive for these relatively simple test sets, though it is worse than MEME for CIFAR-10-C. Of these three test sets, CIFAR-10-C is the only benchmark that explicitly introduces distribution shift, which suggests that adaptation is useful when the test shifts are more prominent.
Both TTA and MEME are also effective at improving performance for the original CIFAR-10 test set where there is no distribution shift, providing further support for the widespread use of augmentations in standard evaluation protocols (Krizhevsky et al., 2012; Ashukha et al., 2020).
[Table] [Table]
[Table]
(+5 . 1) 99 . 1 (+0 . 9) + BN ( N = 256 , n = 256 ) 61 .
(+15 .
7 (+4 . 2) 99 .
8 (+0 . 2)
+ Tent (Wang et al., 2021) 54 .
4 (+22 . 3) 57 .
(+6 . 2) 99 .
8 (+0 . 2) + DeepAugment+AugMix
(Hendrycks et al., 2021a)
53 .53 .96 .+
TTA 55 .
2 ( − 1 . 6) 51 .
(+2 . 2) 93 .
5 (+2 .
+ Single point BN 51 .
3 (+2 . 3) 51 .
2 (+2 . 0)
4 (+0 . 7) + MEME (ours) 49 .
8 (+ 3 . 8 ) 49 .
2 (+ 4 . 0 ) 94 .
8 (+1 . 3) + BN ( N = 256 , n = 256 ) 45 .
4 (+8 . 2) 48 .
8 (+4 . 4) 96 . 8 ( − 0 .
+ Tent (Wang et al., 2021) 43 .
5 (+ 10 . 1 ) 46 .
9 (+ 6 . 3 ) 96 .
7 ( − 0 .
+ MoEx+CutMix (Li et al., 2021)
74 .64 .91 .+
TTA 75 .
7 ( − 0 . 9) 62 .
7 (+1 .
5 (+2 . 4)
+ Single point BN 71 .
(+3 .
6 (+1 . 9) 91 .
1 (+0 . 8) + MEME (ours) 69 .
1 (+5 . 7) 59 .
4 (+3 . 3) 89 .
(+ 2 . 9 ) + BN ( N = 256 , n = 256 ) 60 .
9 (+13 . 9) 61 .
6 (+2 . 9) 93 .
9 ( − 2 . 0)
+ Tent (Wang et al., 2021) 54 .
[Table]
[Table]
We summarize results for ImageNet-C, ImageNet-R, and ImageNet-A in Table 2, with complete
ImageNet-C results in Appendix B. We again use indentations to indicate composition, e.g., the best results on ImageNet-C for our setting are attained through a combination of starting from a model trained with DeepAugment and AugMix (Hendrycks et al., 2021a) and using MEME on top.
For both ImageNet-C and ImageNet-R, and for both the ResNet-50 and RVT ∗ -small models, combining MEME with robust training techniques leads to new state of the art performance among methods that observe only one test point at a time.
We highlight in gray the methods that require multiple test points for adaptation, and we list in bold the best results from these methods which outperform the test time robustness methods.
As Table 2 and prior work both show (Schneider et al., 2020; Wang et al., 2021), accessing multiple test points can be powerful for benchmarks such as ImageNet-C and ImageNet-R, in which inferred statistics from the test input distribution may aid in prediction.
In the case of Tent, which adapts online, the model has adapted using the entire test set by the
[Table] [Table]
end of evaluation. However, these methods do not help, and oftentimes even hurt, for ImageNet-A. Furthermore, we ﬁnd that these methods are less effective with the RVT ∗ -small model, which may indicate their sensitivity to model architecture choices.
MEME results in substantial improvement for ImageNet-A and is competitive with TTA on this problem.
No prior test time adaptation methods have reported improvements on ImageNet-A, and some have reported explicit negative results (Schneider et al., 2020).
As discussed, it is reasonable for adaptation methods that rely on multiple test points to achieve greater success on other benchmarks such as ImageNet-C, in which a batch of inputs provides signiﬁcant information about the speciﬁc corruption that must be dealt with.
In contrast, ImageNet-A does not have such obvious characteristics associated with the input distribution, as it is simply a collection of images that are difﬁcult to classify.
As MEME instead extracts a learning signal from single test points, it is, to the best of our knowledge, the ﬁrst test time adaptation method to report successful results on this testbed.
When used on top of a model trained with moment exchange and CutMix (Li et al., 2021), MEME achieves stateof-the-art performance among ResNet-50 models and single test point methods.
TTA generally offers larger performance gains on ImageNet-A and also results in the highest overall accuracy when combined with the RVT ∗ -small model; however, TTA performs worse than MEME on ImageNet-R and consistently decreases accuracy on ImageNet-C compared to standard evaluation.
4. A BLATIVE STUDY
MEME increases model robustness at test time via adaptation and augmentation, and in this section, we ablate both of these axes to understand which design choices are the most important.
Adaptation.
From the results above, we conclude that adaptation generally provides additional beneﬁts beyond simply using TTA to predict via the marginal output distribution ¯ p θ ( y | x ) .
However, we can disentangle two distinct self-supervised learning signals that may be effective for adaptation: encouraging invariant predictions across different augmentations of the test point, and encouraging conﬁdence via entropy minimization.
The marginal entropy objective in Equation 2 encapsulates both of these learning signals, but it cannot easily be decomposed into these pieces.
Thus, we instead use two ablative adaptation methods that each only make use of one of these learning signals.
First, we consider optimizing the pairwise cross entropy between each pair of augmented points, i [Equation] e.,
[Equation]
Where ˜ x i again refers to the i -th sampled augmentation applied to x and SG is the stop gradient operator.
Intuitively, this loss function encourages the model to adapt such that it produces the same predictive distribution for all augmentations of the test point, but it does not encourage the model to produce conﬁdent predictions.
Conversely, as an objective that encourages conﬁdence but not invariance, we also consider optimizing conditional entropy on the batch of augmented points, i.e.,
[Equation]
This ablation is effectively a version of Tent (Wang et al., 2021) that is suitable for our test setting.
That is, instead of assuming a batch of test inputs for adaptation, we instead copy and randomly augment a single test input into a batch.
We evaluate these ablations on the CIFAR-10 test sets.
We use the same adaptation procedure outlined in Algorithm 1, with (cid:96) replaced with the above objectives, and we keep the same hyperparameter values B = 32 and η = 0 .
The results are presented in Table 3.
We see that MEME, i.e., marginal entropy minimization, generally performs better than adaptation with either of the alternative objectives.
This supports the hypothesis that both invariance across augmentations and conﬁdence are important learning signals for self-supervised adaptation.
When faced with more extreme distribution shifts on CIFAR-10-C, we see poor performance from the pairwise cross entropy based adaptation.
The conditional entropy based adaptation performs reasonably well on CIFAR-10-C, though worse than MEME.
Augmentation.
We also wish to understand the importance of the choice of augmentation functions
A .
As mentioned, we used AugMix (Hendrycks et al., 2020) in the previous experiments as it best ﬁt our criteria:
AugMix can be computed in parallel efﬁciently, requires only the input x , and leads to diverse augmented data points.
A simple alternative is to instead use the “standard” set of augmentations commonly used in ImageNet training, i.e., random resized cropping and random horizontal ﬂipping.
We evaluate this ablation of using MEME with standard augmentations also on the CIFAR-10 test sets, again with the same hyperparameter values.
From the results in Table 4, we can see that MEME is still effective with simpler augmentation functions.
This is true particularly for the cases where there is no test shift, as in the original CIFAR-10 test set, or subtle shifts as in CIFAR10.1; however, for the more severe and systematic CIFAR-10-C shifts, using heavier AugMix data augmentations leads to greater performance gains over the standard augmentations.
Furthermore, this ablation was conducted using the ResNet-26 model, which was trained with standard augmentations – for robust models such as those in Table 2, AugMix may offer greater advantages at test time since these models were exposed to heavy augmentations during training.
D ISCUSSION
We presented MEME, a method for test time robustiﬁcation again distribution shift via adaptation and augmentation.
MEME does not require access or changes to the model training procedure and is thus broadly applicable for a wide range of pretrained models.
Furthermore, MEME adapts at test time using single test inputs, thus it does not assume access to multiple test points as in several recent methods for test time adaptation (Schneider et al., 2020; Wang et al., 2021; Zhang et al., 2021).
On a range of distribution shift benchmarks for CIFAR-10 and ImageNet classiﬁcation, and for both
ResNet and vision transformer models, MEME consistently improves performance at test time and achieves several new state-of-the-art results for these models in the single test point setting.
Inference via MEME is more computationally expensive than standard model inference, primarily because adaptation is performed per test point and thus inference cannot be batched.
One interesting direction for future work is to develop techniques for selectively determining when to adapt the model in order to achieve more efﬁcient inference.
Additionally, it would be interesting to explore MEME in the test setting where the model is allowed to continually adapt as more test data is observed.
In our preliminary experiments in this setting, MEME tended to lead to degenerate solutions, e.g., the model predicting a constant label with maximal conﬁdence, and this may potentially be rectiﬁed by carefully choosing which parameters to adapt (Wang et al., 2021) or regularizing the model such that it does not change too drastically from the pretrained model.
E THICS S TATEMENT
Distribution shift, in general, lies at the heart of many ethical concerns in machine learning.
When machine learning models and research do not adhere to ethical principles such as “contribute to society and to human well-being”, “avoid harm”, and “be fair and take action to avoid discrimination”, it can oftentimes be attributed at least partially to issues stemming from distribution shift.
As such, research into ways to combat and mitigate shift contribute to furthering the ethical goals and principles laid out by this conference and the broader community.
Related to this work, we may imagine that models that are more robust or adaptable to shift may produce more fair results when considering underrepresented subpopulations and could be more trustworthy in safety critical applications.
However, as mentioned in Section 5, the proposed method is also more computationally intensive, and care must be taken in general to not place the most powerful machine learning tools exclusively in the hands of the most privileged and resource rich individuals and organizations.
Beyond this, we do not see any immediate ethical concerns regarding the content, presentation, or methodology of this work.
R EPRODUCIBILITY S TATEMENT
The proposed method is relatively simple and, to the best of our ability, explained fully in Sectionand Algorithm 1.
This explanation is bolstered by a complete description of all hyperparameters in
Appendix A as well as the example code provided in the supplementary materials.
As brieﬂy explained in the README in the example code, all datasets were downloaded from publicly accessible links and preprocessed only following the standard protocols.
Upon publication, we will include a link to the full (non anonymous) code release containing full instructions for setting up the code, downloading the datasets, and reproducing the results.
A E XPERIMENTAL PROTOCOL
We select hyperparameters using the four disjoint validation corruptions provided with CIFAR-10-C and ImageNet-C (Hendrycks & Dietterich, 2019).
As the other benchmarks are only test sets and do not provide validation sets, we use the same hyperparameters found using the corruption validation sets and do not perform any additional tuning.
For the ResNet models that we evaluate, we use stochastic gradients as the update rule G ; for ResNet-26 models, we set the number of augmentations
B = 32 and the learning rate η = 0 .
005 ; and for ResNet-50 models, we set B = 64 and η = 0 .
For the robust vision transformer, we use AdamW (Loshchilov & Hutter, 2019) as the update rule G , with learning rate η = 0 .
00001 and weight decay 0 . 01 , and B = 64 .
In the CIFAR evaluation, we compare to TTT, which, as noted, can also be applied to single test inputs but requires a specialized training procedure (Sun et al., 2020).
Thus, the ResNet-26 model we use for our method closely follows the modiﬁcations that Sun et al.
(2020) propose, in order to provide a fair point of comparison.
In particular, Sun et al.
(2020) elect to use group normalization (Wu & He, 2018) rather than BN, thus single point BN adaptation is not applicable for this model architecture.
As noted before, TTT also requires the joint training of a separate rotation prediction head, thus further changing the model architecture, while MEME directly adapts the standard pretrained model.
The TTA results are obtained using the same AugMix augmentations as for MEME.
The single point BN adaptation results use N = 16 , as suggested by Schneider et al.
As noted, the
BN adaptation results (using multiple test points) are obtained using N = 256 as the prior strength and batches of 256 test inputs for adaptation.
For Tent, we use the hyperparameters suggested in
Wang et al.
(2021): we use stochastic gradients with learning rate 0 .
00025 and momentum 0 .
9 , the adaptation is performed with test batches of 64 inputs, and the method is run online, i.e., prediction and adaptation occur simultaneously and the model is allowed to continuously adapt through the entire test epoch.
Since Wang et al.
(2021) did not experiment with transformer models, we also attempted to run Tent with Adam (Kingma & Ba, 2015) and AdamW (Loshchilov & Hutter, 2019) and various hyperparameters for the RVT ∗ -small model; however, we found that this generally resulted in worse performance than using stochastic gradient updates with the aforementioned hyperparameters.
We obtain the baseline ResNet-50 parameters directly from the torchvision library.
The parameters for the ResNet-50 trained with DeepAugment and AugMix are obtained from https://drive.google.com/file/d/1QKmc_p6-qDkh51WvsaS9HKFv8bX5jLnP .
The parameters for the ResNet-50 trained with moment exchange and CutMix are obtained from https://drive.google.com/file/d/1cCvhQKV93pY-jj8f5jITywkB9EabiQDA .
The parameters for the small robust vision transformer (RVT ∗ -small) model are obtained from https://drive.google.com/file/d/1g40huqDVthjS2H5sQV3ppcfcWEzn9ekv .
B F ULL CIFAR-10-C AND I MAGE N ET -C RESULTS
In the tables on the next page, we present test results broken down by corruption and level for
CIFAR-10-C for the methods evaluated in Table 1.
We omit joint training and TTT because these results are available from Sun et al.
Our test results for ImageNet-C can be obtained from https://docs.google.com/spreadsheets/d/1U5hUIJ1sRoMGwZY2WI8vH0VJTXvdX5vHMy6nej4PHE4 .
[Table] [Table]
[Table] [Table]
[Table] [Table]