Year: 2019

Abstract:
We introduce a general approach, called test-time training, for improving the performance of predictive models when training and test data come from different distributions. Test-time training turns a single unlabeled test instance into a selfsupervised learning problem, on which we update the model parameters before making a prediction on this instance. We show that this simple idea leads to surprising improvements on diverse image classification benchmarks aimed at evaluating robustness to distribution shifts. Theoretical investigations on a convex model reveal helpful intuitions for when we can expect our approach to help.

heading: 1 INTRODUCTION
text: Supervised learning remains notoriously weak at generalization under distribution shifts. Unless training and test data are drawn from the same distribution, even seemingly minor differences turn out to defeat state-of-the-art models. Transfer learning, domain adaptation and adversarial robustness are but a few existing paradigms that anticipate differences of sorts between the training and test distribution. In this work, we explore a new take on generalization, without any mathematical structure or data available at training-time to anticipate the distribution shifts.
We start from a simple observation. The unlabeled test instance x presented at test-time gives us a hint about the distribution from which it was drawn. Our approach, called test-time training, allows the model parameters θ to depend on the test instance x, but not its unknown label y. This variable decision boundary θ(x) is powerful in theory (see Appendix A), and raises new challenges in practice that we only begin to address here.
Our algorithm creates a self-supervised learning problem based on this single test instance x, updating θ at test-time before making a prediction. Self-supervised learning uses an auxiliary task that automatically creates labels from unlabeled inputs. For the visual data we work with, the task rotates an image x by a multiple of 90 degrees, and assigns the angle as the label (Gidaris et al., 2018).
Our approach can also be easily modified to work outside the standard supervised learning setting. If several test instances arrive in a batch, we can use the entire batch for test-time training. If test instances arrive online sequentially, we obtain further improvements by keeping the state of the parameters. After all, prediction is rarely a single event. The online setting can be the natural mode of deployment in practice, and shows the strongest improvements.
We experiment with test-time training for generalization under distribution shifts in the context of object recognition on several benchmarks. These include images with diverse types of corruption at various levels (Hendrycks & Dietterich, 2019), video frames of moving objects (Shankar et al., 2019), and a new test set of unknown shifts collected by Recht et al. (2018). Our algorithm does not hurt on the original distribution, but makes substantial improvements under distribution shifts.
In all our experiments, we compare with a strong baseline (labeled joint training) that uses both supervised and self-supervised learning at training-time, but keeps the model fixed at test-time. Very recent work shows that additional training-time self-supervision improves robustness Hendrycks et al. (2019b). The joint training baseline we use corresponds to an improved implementation of their work. We are also inspired by Sun et al. (2019), which performs joint training with a selfsupervised task in the context of unsupervised domain adaptation, simultaneously on the source and target domain. A comprehensive review of related work follows in section 5.
We complement the empirical results with theoretical investigations in section 4, of when test-time training is expected to help on a convex model, and establish an intuitive sufficient condition, which, roughly speaking, is to have correlated gradients between the loss functions of the two tasks.

heading: 2 METHOD
text: Next we describe the algorithmic details of our method. To setup notations, consider a standard Klayer neural network with parameters θk for layer k. The stacked parameter vector θ = (θ1, . . . , θK) specifies the entire model for a classification task with loss function lm(x, y;θ) on the test instance (x, y). We call this the main task, as indicated by the subscript of the loss function.
We assume to have training data (x1, y1), . . . , (xn, yn) drawn i.i.d. from a distribution P . Standard empirical risk minimization corresponds to solving the optimization problem:
min θ
1
n n∑ i=1 lm(xi, yi;θ). (1)
Our method requires a self-supervised auxiliary task with loss function ls(x). In this paper, we choose the rotation prediction task (Gidaris et al., 2018), which has been demonstrated to be simple and effective at feature learning for neural networks. The task simply rotates x on the image plane by one of 0, 90, 180 and 270 degrees and have the model predict the angle of rotation as a four-way classification problem. Other self-supervised tasks in section 5 might also be used for our method.
The auxiliary task shares some of the model parameters θe = (θ1, . . . , θκ) up to a certain κ ∈ {1, . . . ,K}. We think of those κ layers as a shared feature extractor. The auxiliary task uses its own task-specific parameters θs = (θ′κ+1, . . . , θ ′ K). We call the unshared parameters θs the selfsupervised task branch, and θm = (θκ+1, . . . , θK) the main task branch. Pictorially, the joint architecture is a Y -structure with a shared bottom and two branches. For our experiments, the selfsupervised task branch has the exact same architecture as the main branch, except for the output dimensionality of the last layer due to the different number of classes in the two tasks.
Training is done in the fashion of multi-task learning (Caruana, 1997); the model is trained on both tasks on the same data drawn from P . Losses for both tasks are added together, and gradients are taken for the collection of all parameters. The joint training problem is therefore
min θe,θm,θs
1
n n∑ i=1 lm(xi, yi;θm,θe) + ls(xi;θs,θe). (2)
Now we describe the standard version of test-time training on a single test instance x. Simply put, test-time training finetunes the shared feature extractor θe by minimizing the auxiliary task loss on x. This can be formulated as
min θe ls(x;θs,θe). (3)
Denote θ∗e the (approximate) minimizer of Equation 3. The model then makes a prediction using the updated parameters θ(x) = (θ∗e ,θm). Empirically, the difference is negligible between minimizing Equation 3 over θe versus over both θe and θs. Theoretically, there exists a difference only when optimization is done with more than one step of gradient descent.
In the standard version of our method, the optimization problem in Equation 3 is always initialized with parameters θ = (θe,θs) obtained by minimizing Equation 2 on data from P . After making a prediction on x, θ∗e is discarded. Outside of the standard supervised learning setting, when the test instances arrive online sequentially, the online version of test-time training solves the same optimization problem as in Equation 3 to update the shared feature extractor θe. However, on test instance xt, θ is instead initialized with θ(xt−1) updated on the previous instance xt−1. This allows θ(xt) to take advantage of the distributional information available in x1, . . . , xt−1 as well as xt.
Test-time training naturally benefits from standard data augmentation techniques. On each test instance x, we perform the exact same set of random transformations as used for data augmentation during training to form a batch only containing these augmented copies of x for test-time training.

heading: 3 EMPIRICAL RESULTS
text: We experiment with both versions of our method (standard and online) on three kinds of benchmarks for distribution shifts, presented here in the order of visually low to high-level, which is roughly also the order of easy to hard. Our code will be released once the paper is accepted.
Network details. Our architecture and hyper-parameters are consistent across all experiments. We use Residual Networks (ResNets) (He et al., 2016b), which are constructed differently for CIFAR10 1 (26-layer) and ImageNet 2 (18-layer). ResNets on ImageNet have four groups, each containing convolutional layers with the same number of channels and size of feature maps; our splitting point is the end of the third group. ResNets on CIFAR-10 have three groups; our splitting point is the end of the second group. In addition, Batch Normalization (BN), a popular module in deep networks, is ineffective when training on small batches, for which the estimated batch statistics are less accurate (Ioffe & Szegedy, 2015). This technicality hurts test-time training since each batch only contains (augmented) copies of a single image. Therefore our networks instead use Group Normalization (GN) (Wu & He, 2018), which achieves similar performance as BN on large batches without hurting on small ones. Results with BN are shown in Appendix E for completeness.
Optimization details. For Equation 2, optimization hyper-parameters are set to the default 3 in standard practice (Huang et al., 2016; He et al., 2016a). For Equation 3, we use stochastic gradient descent (SGD) with the learning rate set to that of the last epoch during training, which is 0.001 in all our experiments. Following standard practice (He et al., 2018; Liu et al., 2018) known to improve performance when finetuning, we do not use weight decay or momentum. For the standard version, we take ten gradient steps, using batches independently generated by the same image. For online we take only one step. The computational aspects of our method are discussed in Appendix C. Following standard practice, the transformations used for data augmentation are random crop with padding and random horizontal flip for CIFAR-10 (Guo et al., 2017a; Huang et al., 2016), and random resized crop and random horizontal flip for ImageNet (Ioffe & Szegedy, 2015; He et al., 2016a). Specifically, these transformations do not contain information about the distribution shifts.
In all the tables and figures, baseline refers to the plain ResNet model (using GN, unless otherwise specified); joint training refers to the model jointly trained on both the main task and the selfsupervised task, fixed at test-time as in Hendrycks et al. (2019b); test-time training refers to the standard version described section 2; and test-time training online refers to the online version that does not discard θ(xt) for xt arriving sequentially from the same distribution. Performance for test-time training online is calculated, just like the others, as the average over the entire test set; we always shuffle the test set before test-time training online to avoid ordering artifacts.
1CIFAR-10 (Krizhevsky & Hinton, 2009) is a standard object recognition dataset with 10 classes of objects in natural scenes. The standard train / test split has 50,000 / 10,000 images, each of size 32-by-32 pixels.
2The ImageNet 2012 classification dataset (Russakovsky et al., 2015) for object recognition has images from 1, 000 classes, 1.2 million for training and 50,000 for validation. Following standard practice (He et al., 2016a;b; Huang et al., 2016), the validation set is used as the test set.
3Namely, we use stochastic gradient descent (SGD) with weight decay and momentum; learning rate starts at 0.1 and is dropped by a factor of ten at two scheduled milestones, to 0.01 and 0.001.

heading: 3.1 COMMON CORRUPTIONS
text: Hendrycks & Dietterich (2019) propose to benchmark robustness of neural networks on 15 types of corruptions from four broad categories: noise, blur, weather and digital. Each corruption type comes in five levels of severity, with level 5 the most severe (details and sample images in Appendix D). The corruptions are algorithmically simulated to mimic real-world corruptions as much as possible on copies of the test set for both CIFAR-10 and ImageNet. According to the authors, training should be done on the original training set, and the diversity of corruption types should make it difficult for any method to work well across the board if it relies too much on corruption specific knowledge.
CIFAR-10-C. Our results on the level 5 corruptions (most severe) are shown in Figure 9. Due to space constraints, our results on levels 1-4 are shown in Appendix E. Across all five levels and 15 corruption types, both versions of test-time training always improve over the baseline by a large margin. The standard version of test-time training always improves over joint training, and the online version often improves very significantly (>10%) over joint training and never hurts by more than 0.2%. Specifically, test-time training online contributes >24% on the three noise types and 38% on pixelation. For the seemingly unstable setup of a learning problem that abuses a single image, this kind of consistency is rather surprising.
The baseline ResNet-26 has error 8.9% on the original test set of CIFAR-10. The joint training baseline actually improves performance on the original to 8.1%. Most surprisingly, unlike many other methods that tradeoff original performance with robustness, test-time training further improves on the original test set by 0.2% consistently over many independent trials. This indicates that our method does not choose between specificity and generality.
Separate from our method, it is interesting to note that joint training consistently improves over the baseline, as discovered by Hendrycks et al. (2019b). Hendrycks & Dietterich (2019) have also experimented with various other training methods on this benchmark, and point to Adversarial Logit Pairing (ALP) (Kannan et al., 2018) as the most effective. Results of this additional baseline on
all levels of CIFAR-10-C are shown in Appendix E, along with its implementation details. While surprisingly robust under some of the most severe corruptions (especially the three noise types), ALP incurs a much larger error (by a factor of two) on the original distribution and some corruptions (e.g. all levels of contrast and fog), and hurts performance significantly when the corruptions are not as severe (especially on levels 1-3); this kind of tradeoff is to be expected for methods based on adversarial training, but not test-time training.
ImageNet-C. Our results on the level 5 corruptions (most severe) are shown in Figure 2. We use accuracy instead of error for this dataset because the baseline severely underperforms with most corruptions. The general trend is roughly the same as on CIFAR-10-C. Test-time training (standard version) always improves over the baseline and joint training, while the online version only hurts on the original by 0.1% over the baseline, but dramatically improves (by a factor of more than three) on many of the corruption types.
In the lower panel of Figure 2, we visualize how the accuracy (averaged over a sliding window) of the online version changes as more images are tested on. Due to space constraints, we show this plot on the original test set, as well as every third corruption type, following the same order as in the original paper. On the original test set, there is no visible change in performance after updating on the 50,000 samples. With corruptions, accuracy has already risen significantly after 10,000 samples, but is still rising towards the end of the 50,000 samples, indicating room for additional improvements if more samples were available. Without looking at a single label, test-time training online behaves as if we were training on the test set from the appearance of these plots.
3.2 VIDEO CLASSIFICATION
The ImageNet Video Classification (VID) dataset was developed by Shankar et al. (2019) from the Video Detection dataset of ILSVRC2015 (Russakovsky et al., 2015), to demonstrate how deep learning models for object recognition trained on ImageNet (still images) fail to adapt well to video frames 4. Without any modification for videos, we apply our method to VID on top of the same ImageNet model as in the previous subsection. Our results are shown in Table 2. Again, we use accuracy instead of error because the baseline performance is poor.
In addition, we take the seven classes in VID that overlap with CIFAR-10, and rescale those video frames to the size of CIFAR-10 images, as a new test set for the model trained on CIFAR-10 in the previous subsection. Again, we apply our method to this dataset without any modification. Our results are shown in Table 1, with a breakdown for each class. Noticing that test-time training does not improve on the airplane class, we inspect some airplane samples, and observe that most of them have black margins on the sides, which provide a trivial hint for the rotation prediction task. In addition, for airplanes captued in the sky, it is often impossible even for humans to tell if an image is rotated. This shows that our method requires the self-supervised task to be both well defined and non-trivial on the new domain.
4 The VID dataset contains 1109 sets of video frames; each set forms a short video clip where all the frames are similar to an anchor frame. Our results are reported on the anchor frames. To map the 1000 ImageNet classes to the 30 VID classes, we use the max-conversion function in Shankar et al. (2019).

heading: 3.3 CIFAR-10.1: A NEW TEST SET WITH UNKNOWN DISTRIBUTION SHIFTS
text: CIFAR-10.1 (Recht et al., 2018) is a new test set of size 2000 modeled after CIFAR-10, with the exact same classes and image dimensionality, following the dataset creation process documented by the original CIFAR-10 paper as closely as possible. The purpose is to investigate the distribution shifts present between the two test sets, and the effect on object recognition. All models tested by the authors suffer a large performance drop on CIFAR-10.1 comparing to CIFAR-10, even though there is no human noticable difference, and both have the same human accuracy. This demonstrates how insidious and ubiquitous distribution shifts are, even when researchers strive to minimize them.
The distribution shifts from CIFAR-10 to CIFAR-10.1 pose an extremely difficult problem, and nobody has made a successful attempt to improve the performance of an existing model on this new test set, probably because 1) Researchers cannot even identify the distribution shifts, let alone describe them with mathematics. 2) The samples in CIFAR-10.1 are only revealed at test-time; and even if revealed during training, the distribution shifts are too subtle, and the sample size is too small, for domain adaptation algorithms (Recht et al., 2018).
On the original CIFAR-10 test set, our baseline has error 8.9%, and with joint training 8.1%; comparing to the first two rows of Table 3, both suffer the typical performance drop (by a factor of two). Test-time training yields an improvement of 0.8% (relative improvement of 4.8%) over joint training. We recognize that this improvement is still small comparing to the performance drop, but see it as an encouraging first step for this very difficult problem.

heading: 4 TOWARDS UNDERSTANDING TEST-TIME TRAINING
text: This section contains our preliminary study of when and why test-time training is expected to work. For convex models, we prove that positive gradient correlation between the loss functions leads to better performance on the main task after test-time training. Equipped with this insight, we then empirically demonstrate that gradient correlation governs the success of test-time training on the deep learning model discussed in Section 3.
Before stating our main theoretical result, we first illustrate the general intuition with a toy model. Consider a regression problem where x ∈ Rd denotes the input, y1 ∈ R denotes the label, and the objective is the square loss (ŷ − y1)2/2 for a prediction ŷ. Consider a two layer linear network parametrized byA ∈ Rh×d and v ∈ Rh (where h stands for the hidden dimension). The prediction according to this model is ŷ = v>Ax, and the main task loss is
lm(x, y1;A,v) = 1
2
( y1 − v>Ax )2 . (4)
In addition, consider a self-supervised regression task that also uses the square loss and automatically generates a label ys for x. Let the self-supervised head be parameterized byw ∈ Rh. Then the selfsupervised task loss is
ls(x, y2;A,w) = 1
2
( y2 −w>Ax )2 . (5)
Now we apply test-time training to update the shared feature extractor A by one step of gradient descent on ls, which we can compute with y2 known. This gives us
A′ ← A− η ( y2 −w>Ax ) ( −wx> ) , (6)
whereA′ is the updated matrix and η is the learning rate. If we set η = η∗ where
η∗ = y1 − v>Ax
(y2 −w>Ax)v>wx>x , (7)
then with some simple algebra, it is easy to see that the main task loss lm(x, y1;A′,v) = 0. Concretely, test-time training drives the main task loss down to zero with a single gradient step for a carefully chosen learning rate. In practice, this learning rate is unknown since it depends on the unknown y1. However, since our model is convex, as long as η∗ is positive, it suffices to set η to
be a small positive constant (see Lemma 1). If x 6= 0, one sufficient condition for η∗ to be positive (when neither loss is zero) is to have
sign ( y1 − v>Ax ) = sign ( y2 −w>Ax ) and v>w > 0 . (8)
For our toy model, both parts in Equation 8 have an intuition interpretation. The first part says that the mistakes should be correlated, in the sense that predictions from both tasks are mistaken in the same direction. The second part, v>w > 0, says that the decision boundaries on the feature space should be correlated. In fact, these two parts hold iff 〈∇lm(A),∇ls(A)〉 > 0 (see Lemma 2). To summarize, if the gradients have positive correlation, test-time training is guaranteed to reduce the main task loss. Our main theoretical result extends this to general smooth and convex loss functions.
Theorem 1. Let lm(x, y;θ) denote the main task loss on test instance x, y with parameters θ, and ls(x;θ) the self-supervised task loss that only depends on x 5. Assume that for all x, y, lm(x, y;θ) is differentiable, convex and β-smooth in θ, and both ‖∇lm(x, y;θ)‖ , ‖∇ls(x,θ)‖ ≤ G for all θ. With a fixed learning rate η = βG2 , for every x, y such that
〈∇lm(x, y;θ),∇ls(x;θ)〉 > , (9)
we have
lm(x, y;θ) > lm(x, y;θ(x)), (10)
where θ(x) = θ − η∇ls(x;θ) i.e. test-time training with one step of gradient descent. The proof is in Appendix B.2. Theorem 1 reveals gradient correlation as a determining factor of the success of test-time training in the smooth and convex case. In Figure 3, we empirically show that our insight also holds for non-convex loss functions, on the deep learning model and across the diverse set of corruptions considered in section 3; stronger gradient correlation clearly indicates higher performance improvements over the baseline.

heading: 5 RELATED WORK
text: Our work has been influenced by the successes and limitations of many related fields. Each of these fields contains maybe hundreds of interesting works, which we unfortunately do not have enough time and space to acknowledge in this draft. We apologize for the omissions and are happy to include additional citations upon request.
Learning on test instances. Concurrent work Bau et al. (2019) improves photo manipulation with a generative adversarial network, by adapting its image prior to the statistics of the input image. Shocher et al. (2018) performs super-resolution on an image, by learning to recover the original
5Because the main task branch and the self-supervised branch are kept fixed at test-time, we do not explicitly describe their parameters, and include them implicitly in the loss functions.
image itself from its downsampled version. An older work, Jain & Learned-Miller (2011) improves Viola-Jones (Viola et al., 2001) for face detection, by bootstrapping the more difficult faces in an image from the easier ones with high confidence in the same image. The online version of our algorithm is inspired by Mullapudi et al. (2018), which makes video segmentation more efficient by using a student model that learns online from a teacher model. The idea of online updates has also been used in Kalal et al. (2011) for tracking and detection. Zhu et al. (2019), a concurrent work in echocardiography, improves the deep learning model that tracks myocardial motion and cardiac blood flow with sequential updates. Lastly, we share the philosophy of transductive learning (Vapnik, 2013; Gammerman et al., 1998), but have little in common with their classical algorithms; concurrent work Tripuraneni & Mackey (2019) theoretically explores this for linear prediction.
Adversarial robustness studies the robust risk: RP,∆(θ) = Ex,y∼P maxδ∈∆ l(x+δ, y; θ) where l is some loss function, and ∆ is the set of perturbations; ∆ is often chosen as the Lp ball, for p ∈ {1, 2,∞}. Many popular algorithms formulate and solve this as a robust optimization problem (Goodfellow et al., 2014; Madry et al., 2017; Sinha et al., 2017; Raghunathan et al., 2018; Wong & Kolter, 2017; Croce et al., 2018), and the most well known technique is adversarial training. Another line of work is based on randomized smoothing (Cohen et al., 2019; Salman et al., 2019), while some other approaches such as input transformations (Guo et al., 2017b; Song et al., 2017) are shown to be less effective (Athalye et al., 2018). There are two main problems in this field. First, all the approaches mentioned above can be seen as smoothing the decision boundary. This establishes a theoretical tradeoff between accuracy and robustness (Tsipras et al., 2018; Zhang et al., 2019), which we also observe empirically with our adversarial training baseline in Section 3. Intuitively, the more diverse ∆ is, the less effective this one-boundary-fits-all approach can be for a particular element of ∆. Second, adversarial methods rely heavily on the mathematical structure of ∆, which might not accurately model perturbations in the real world. Therefore, generalization remains hard outside of the ∆ we know in advance or can mathematically model, especially for non-adversarial distribution shifts. Empirically, Kang et al. (2019) shows that robustness for one ∆ might not transfer to another, and training on the L∞ ball actually hurts robustness on the L1 ball.
Non-adversarial robustness studies the effect of corruptions, perturbations, out-of-distribution examples, and real-world distribution shifts (Hendrycks et al., 2019a;b; 2018; Hendrycks & Gimpel, 2016). Geirhos et al. (2018) show that training on images corrupted by Gaussian noise makes deep learning models recover super-human performance on this particular noise type, but cannot improve performance on another those corrupted by another noise type e.g. salt-and-pepper noise.
Unsupervised domain adaptation (a.k.a. transfer learning) studies the problem of distribution shift (from P to Q), when unlabled data from Q is available at training-time (Tzeng et al., 2017; Ganin et al., 2016; Gong et al., 2012; Long et al., 2016; Chen et al., 2018; 2011; Hoffman et al., 2017; Csurka, 2017; Long et al., 2015). We are inspired by this very active and successful community, especially (Sun et al., 2019), and believe that progress in this community can motivate new algorithms in the framework of test-time learning. Our update rule can be viewed as performing one-sample unsupervised domain adaptation on the fly 6. On the other hand, test-time learning comes from realizing the limitations of the unsupervised domain adaptation setting, that outside of the specific target distribution where data is available for training, generalization is still elusive. Previous works make the source and target distributions broader with multiple and evolving sources and targets without fundamentally address this problem (Hoffman et al., 2018; 2012; 2014).
Self-supervised learning studies how to create labels from the data, by designing ingenious tasks that contain semantic information without human annotations, such as context prediction (Doersch et al., 2015), solving jigsaw puzzles (Noroozi & Favaro, 2016), colorization (Larsson et al., 2017; Zhang et al., 2016), noise prediction (Bojanowski & Joulin, 2017), and feature clustering (Caron et al., 2018). Self-supervision has also been used on videos (Wang & Gupta, 2015; Wang et al., 2019). Particularly relevant to our work, Asano et al. (2019) shows that self-supervised learning on only a single image, surprisingly, can produce low-level features that generalize well. In addition,
6Note that typical unsupervised domain adaptation algorithms,such as those based on distributional discrepancy, adversarial learning, co-training and generative modeling, might not work in our framework because the concept of a target distribution, which has been so deeply rooted and heavily relied on, becomes ill-defined when there is only one sample from the target domain.
Hendrycks et al. (2019b) proposes that jointly training a main task and a self-supervised task (our joint training baseline in section 3) can improve robustness of the main task. The same idea is used in few-shot learning (Su et al., 2019), and domain generalization (Carlucci et al., 2019).
Domain generalization studies when a meta distribution generates multiple environment distributions, some of which are available during training (source), while others are used for testing (target) (Li et al., 2018; Shankar et al., 2018; Muandet et al., 2013; Balaji et al., 2018; Ghifary et al., 2015; Motiian et al., 2017; Li et al., 2017a; Gan et al., 2016). With only a few environments, information on the meta distribution is often too scarce to be helpful, and with many environments, we are back to the i.i.d. setting where each environment can be seen as a sample, and a strong baseline is to simply train on all the environments (Li et al., 2019). The setting of domain generalization is limited by the inherent tradeoff between specificity and generality of a fixed decision boundary, and the fact that generalization is again elusive outside of the meta distribution i.e. the actual P .
Continual learning (a.k.a. learning without forgetting) studies when a model is made to learn a sequence of tasks, and not forget about the task at the beginning (Li & Hoiem, 2017; Lopez-Paz & Ranzato, 2017; Kirkpatrick et al., 2017; Santoro et al., 2016). Test-time training does not care about forgetting the past test instances since they have already been evaluated on; and if a past instance comes up by any chance, it would go through test-time training again. In addition, the impact of forgetting the training set is minimal, because both tasks have been jointly trained. This is in contrast to continual learning, when the tasks are trained one-by-one from scratch.
Few (one)-shot learning studies extremely small training sets (maybe for some categories) (Snell et al., 2017; Vinyals et al., 2016; Fei-Fei et al., 2006; Ravi & Larochelle, 2016; Li et al., 2017b; Finn et al., 2017; Gidaris & Komodakis, 2018). Our update rule can be viewed as performing one-shot self-supervised learning and can potentially be improved by progress in few-shot learning.
Online learning (a.k.a. online optimization) is a well-studied area of learning theory (ShalevShwartz et al., 2012; Hazan et al., 2016). The basic setting repeats the following: receive xt, predict ŷt, receive yt from a worst-case oracle and learn. Final performance is evaluated using the regret, colloquially how much worse than the best fixed model in hindsight. It is easy to see how our setting differs, even for the online version. We learn before predicting ŷt, but never receive any yt that is evaluated on, thus do not need to consider the worst-case oracle or the regret.

heading: 6 CONCLUSION
text: The idea of test-time training also makes sense for other tasks such as segmentation and detection, and in other fields such as speech recognition and natural language processing. More generally, we hope this paper can encourage researchers to abandon the self-imposed constraint of a fixed decision boundary at test-time, or even altogether, the artificial divison between training and testing.

heading: B PROOFS
text: Here we prove the theoretical results covered in section 4.

heading: B.1 PROOFS FOR THE TOY PROBLEM
text: The following setting applies to the two lemmas; this is simply the setting of our toy problem, reproduced here for ease of reference. Consider a two layer linear network parametrized by A ∈ Rh×d (shared) and v,w ∈ Rh (fixed) for the two heads, respectively. Denote x ∈ Rd the input and y1, y2 ∈ R the labels for the two tasks, respectively. For the main task loss
lm(A;v) = 1
2
( y1 − v>Ax )2 , (11)
and the self-supervised task loss
ls(A;w) = 1
2
( y2 −w>Ax )2 , (12)
test-time learning yields an updated matrix A′ ← A− η ( y2 −w>Ax ) ( −wx> ) , (13)
where η is the learning rate. Lemma 1. Following the exposition of section 4, denote
η∗ = (y1 − v>Ax)
(y2 − w>Ax)v>wx>x . (14)
Assume η∗ ∈ [ ,∞) for some > 0. Then for any η ∈ (0, ], we are guaranteed an improvement on the main loss i.e. lm(A′) < lm(A).
Proof. From the exposition of section 4, we know that
lm(A− η∗∇lsA)) = 0,
which can also be derived from simple algebra. Then by convexity, we have lm (A+ η∇ls(A)) = lm ((
1− η η∗
) A+ η
η∗ (A− η∗∇ls(A))
) (15)
≤ (
1− η η∗
) lm(A) + 0 (16)
≤ ( 1− η ) lm(A) (17)
< lm(A), (18) where the last inequality uses the assumption that lm(A) > 0, which holds because η∗ > 0. Lemma 2. Define 〈U ,V 〉 = vec (U)> vec (V ) i.e. the Frobenious inner product, then sign (η∗) = sign (〈∇lm(A),∇ls(A)〉) . (19)
Proof. By simple algebra, 〈∇lm(A),∇ls(A)〉 = 〈 ( y1 − v>Ax ) ( −vx> ) , ( y2 −w>Ax ) ( −wx> ) 〉 (20)
= ( y1 − v>Ax ) ( y2 −w>Ax ) Tr ( xv>wx> ) (21)
= ( y1 − v>Ax ) ( y2 −w>Ax ) v>wx>x, (22)
which has the same sign as η∗.

heading: B.2 PROOF OF THEOREM 1
text: For any η, by smoothness and convexity, lm(x, y;θ(x)) = lm(x, y;θ − η∇ls(x;θ)) (23)
≤ lm(x, y;θ) + η〈∇lm(x, y;θ),∇ls(x,θ)〉+ η2β
2 ‖∇ls(x;θ)‖2 . (24)
Denote
η∗ = 〈∇lm(x, y;θ),∇ls(x,θ)〉
β ‖∇ls(x;θ)‖2 .
Then Equation 23 becomes
lm(x, y;θ − η∗∇ls(x;θ)) ≤ lm(x, y;θ)− 〈∇lm(x, y;θ),∇ls(x,θ)〉2
2β ‖∇ls(x;θ)‖2 . (25)
And by our assumptions on the gradient norm and gradient inner product,
lm(x, y;θ)− lm(x, y;θ − η∗∇ls(x;θ)) ≥ 2
2βG2 . (26)
Because we cannot observe η∗ in practice, we instead use a fixed learning rate η = βG2 , as stated in Theorem 1. Now we argue that this fixed learning rate still improves performance on the main task.
By our assumptions, η∗ ≥ βG2 , so η ∈ (0, η ∗]. Denote g = ∇ls(x;θ), then by convexity of lm,
lm(x, y;θ(x)) = lm(x, y;θ − ηg) (27)
= lm
( x, y; ( 1− η
η∗
) θ + η
η∗ (θ − η∗g)
) (28)
≤ (
1− η η∗
) lm(x, y;θ) + η
η∗ lm(x, y;θ − η∗g) (29)
Combining with Equation 26, we have lm(x, y;θ(x)) ≤ (
1− η η∗
) lm(x, y;θ) + η
η∗
( lm(x, y;θ)− 2
2βG2
) (30)
= lm(x, y;θ)− η η∗ 2 2βG2 (31)
Since η/η∗ > 0, we have shown that lm(x, y;θ)− lm(x, y;θ(x)) > 0. (32)

heading: C COMPUTATIONAL ASPECTS OF OUR METHOD
text: At test-time, our method is 2×batch size×number of iterations times slower than regular testing, which only performs a single forward pass for each sample. As the first work on test-time learning, this paper is not as concerned about computational efficiency as improving robustness, but here we provide two potential solutions that might be useful, but have not been thoroughly verified. The first is to use the thresholding trick on ls, introduced as a solution for the small batches problem in section 2. For the models considered in our experiments, roughly 80% of the test instances fall below the threshold, so test-time learning can only be performed on the other 20% without much effect on performance, because those 20% contain most of the samples with wrong predictions. The second is to reduce the number of iterations of test-time updates. For the online version, the number of iterations is already 1, so there is nothing to do. For the standard version, we have done some preliminary experiments setting number of iterations to 1 (instead of 10) and learning rate to 0.01 (instead of 0.001), and observing results almost as good as the standard hyperparameter setting. A more in depth discussion on efficiency is left for future works, which might, during training, explicitly make the model amenable to fast updates.

heading: D SAMPLE IMAGES FROM THE COMMON CORRUPTIONS BENCHMARK

heading: E ADDITIONAL RESULTS ON THE COMMON CORRUPTIONS DATASET
text: For table aethetics, we use the following abbreviations: B for baseline, JT for joint training, TTT for test-time training standard version, and TTTO for test-time training online version.
We have also abbreviated the names of the corruptions. The full names are, in order: original test set, Gaussian noise, shot noise, impulse noise, defocus blur, glass blue, motion blur, zoom blur, snow, frost, fog, brightness, contrast, elastic transformation, pixelation, and JPEG compression.

heading: E.1 RESULTS USING BATCH NORMALIZATION
text: As discussed in section 3, Batch Normalization (BN) is ineffective for small batches, which are the inputs for test-time training (both standard and online version) since there is only one sample available when forming each batch; therefore, our main results are based on a ResNet using Group Normalization (GN). Here we provide results of our method on CIFAR-10-C level 5, with a ResNet using Batch Normalization (BN). These results are meant to be merely a point of reference for the curious readers, instead of our technical contributions.
In the early stage of this project, we have experimented with two potential solutions to the small batches problem with BN. The naive solution is to fix the BN layers during test-time training. but this diminishes the performance gains since there are fewer shared parameters. The better solution, adopted for the results below, is hard example mining: instead of updating on all inputs, we only update on inputs that incur large self-supervised task loss ls, where the large improvements might counter the negative effects of inaccurate statistics.
Test-time training (standard version) is still very effective with BN. In fact, some of the improvements are quite dramatic, such as on contrast (34%), defocus blue (18%) and Gaussian noise (22% comparing to joint-training, and 16% comparing to the baseline). Performance on the original distribution is still almost the same, and the original error with BN is in fact slightly lower than with GN, and takes half as many epochs to converge.
We did not further experiment with BN because of two reasons: 1) The online version does not work with BN, because the problem with inaccurate batch statistics is exacerbated when training online for many (e.g. 10000) steps. 2) The baseline error for almost every corruption type is significantly higher with BN than with GN. Although unrelated to the main idea of our paper, we make the interesting note that GN significantly improves model robustness.

heading: E.2 ADDITIONAL BASELINE: ADVERSARIAL LOGIT PAIRING
text: As discussed in subsection 3.1, Hendrycks & Dietterich (2019) point to Adversarial Logit Pairing (ALP) (Kannan et al., 2018) as an effective method for improving model robustness to corruptions and perturbations, even though it was designed to defend against adversarial attacks. We take ALP as an additional baseline on all benchmarks based on CIFAR-10 (using GN), following the training procedure in Kannan et al. (2018) and their recommended hyper-parameters. The implementation of the adversarial attack comes from the codebase of Ding et al. (2019). We did not run ALP on ImageNet because the two papers we reference for this method, Kannan et al. (2018) and Hendrycks & Dietterich (2019), did not run on ImageNet or make any claim or recommendation.

heading: E.3 RESULTS ON CIFAR-10-C AND IMAGENET-C, LEVEL 5
text: The following two tables correspond to the bar plots in section 3.

heading: E.4 RESULTS ON CIFAR-10-C, LEVELS 1-4
text: The following bar plots and tables are on levels 1-4 of CIFAR-10-C. The original distribution is the same for all levels, so are our results on the original distribution.

Review summaries:
The motivation is to increase accuracy of CNNs with unseen (unknown) distribution shifts. To this end, instead of the recent approach of training-time self-supervision, they adopted it for test-time [limited novelty]. More precisely, for a classification task, they considered two headed neural network with one head for main classification task and another for an auxiliary task (e.g. predicting rotation degree of rotated images). The feature extractor (up to k layers) is shared between these tasks thus updated using the two tasks, while two heads are updated according to each task. In test-time, the samples (drawn from shifted data distributions) are being used for updating the shared feature extractor through the auxiliary task. They have investigated their test-time approach in a series of experiments in online and offline settings on synthetic shift in data distribution of image classification tasks. The distributional shifts are synthesized adding some non-adversarial perturbation to clean images. The authors proof that their test-time approach can lead to lower error rate on given test-time samples when the underlying learning model is a linear regression model.