A ﬁne-grained analysis of distribution shifts
Abstract
Robustness to distribution shifts is critical for deploying machine learning models in the real world.
Despite this necessity, there has been little work in deﬁning the underlying mechanisms that cause these shifts and evaluating the robustness of algorithms across multiple, different distribution shifts.
To this end, we introduce a framework that enables ﬁne-grained analysis of various distribution shifts.
We provide a holistic analysis of current state-of-the-art methods by evaluatingdistinct methods grouped into ﬁve categories across both synthetic and real-world datasets.
Overall, we train more than 85K models.
Our experimental framework can be easily extended to include new methods, shifts, and datasets.
We ﬁnd, unlike previous work [Gulrajani and Lopez-Paz, 2021], that progress has been made over a standard ERM baseline; in particular, pretraining and augmentations (learned or heuristic) offer large gains in many cases.
However, the best methods are not consistent over different datasets and shifts.
A longer version of this paper is at https://arxiv.org/abs/2110.11328 .
Introduction
If machine learning models are to be ubiquitous in critical applications such as driverless cars [Janai et al., 2020], medical imaging [Erickson et al., 2017] and science [Jumper et al., 2021], it is pivotal to build models that are robust to distribution shifts.
Otherwise, models may fail surprisingly in ways that derail trust in the system.
For example, Koh et al.
[2020], Perone et al.
[2019], AlBadawy et al.
[2018], Heaven [2020], Castro et al.
ﬁnd that a model trained on one set of hospitals may not generalise to the imaging conditions of another; Alcorn et al.
[2019], Dai and Van Gool [2018] ﬁnd that a model for driverless cars may not generalise to new lighting conditions or object poses; and Buolamwini and Gebru [2018] ﬁnd that a model may perform worse on subsets of the distribution, such as different ethnicities, if the training set has an imbalanced distribution.
Thus, it is important to understand when we expect a model to generalise and when we do not.
This would allow a practitioner to have conﬁdence in the system (e.g. if a model is demonstrated to be robust to the imaging conditions of different hospitals, then it can be deployed in new hospitals with conﬁdence).
While domain generalization is a well studied area, Gulrajani and Lopez-Paz [2021], Schott et al. [2021] have cast doubt on the efﬁcacy of existing methods, raising the question: has any progress been made in domain generalization over a standard expectation risk minimization (ERM) algorithm?
Despite these discouraging results, there are many examples that machine learning models do generalise across datasets with different distributions [Radford et al., 2021, Taori et al., 2020].
However, there is little understanding on when and why models generalise, especially in realistic settings inspired by real-world applications.
To this end we introduce an evaluation framework to systematically evaluate the robustness of different methods under different distribution shifts.
Using this framework, we evaluate models across three distribution shifts: spurious correlation , low data drift , and unseen data shift (illustrated in ﬁgure 1).
We choose these settings as they arise in the real world and harm generalization performance.
The unique ability of our framework to evaluate
[Figure]
ﬁne-grained performance of models across different distribution shifts and under different conditions is of critical importance to analyze methods under a variety of real-world settings.
Models evaluated
We evaluate 19 algorithms to cover a broad range of approaches that can be used to improve model robustness to distribution shifts.
These algorithms cover the following areas: architecture choice, data augmentation, domain adaptation, adaptive approaches and representation learning.
Further discussion and how these models relate to our robustness framework is in appendix C.
Architecture choice.
We evaluate the following standard vision models: ResNet18, ResNet50,
ResNet
[He et al., 2016], ViT [Dosovitskiy et al., 2021], and an MLP [Vapnik, 1992].
Heuristic data augmentation.
We analyze the following augmentation methods: standard ImageNet augmentation [He et al., 2016], AugMix without JSD [Hendrycks et al., 2020], RandAugment [Cubuk et al., 2020], and AutoAugment [Cubuk et al., 2019].
Learned data augmentation.
These approaches learn how to augment an image according to auxiliary information (e.g. given a blue shape and the color red, the learned augmentation will turn the shape red).
We follow Goel et al.
[2020], who use C YCLE GAN [Zhu et al., 2017], but we do not use their SGDRO objective in order to evaluate the performance of learned data augmentation alone.
Domain generalization.
We evaluate IRM [Arjovsky et al., 2019], DeepCORAL [Sun and Saenko, 2016], domain MixUp [Gulrajani and Lopez-Paz, 2021], DANN [Ganin et al., 2016], and SagNet [Nam et al., 2021].
Adaptive approaches.
We evaluate JTT [Liu et al., 2021] and BN-Adapt [Schneider et al., 2020].
Representation learning.
We evaluate using a β -VAE [Higgins et al., 2017a] and pretraining on
ImageNet [Deng et al., 2009].
Experiments
We evaluate the 19 different methods across six datasets and three distribution shifts.
We plot aggregate results in ﬁgures 2-4 and complete results in the appendix in ﬁgures 7-9.
We discuss the results by distilling them into six concrete takeaways in section 3.1 and four practical tips in section 3.2.
Implementation details are given in appendix H.
Datasets.
We use six vision, classiﬁcation datasets – D S PRITES [Matthey et al., 2017], MPI3D [Gondal et al., 2019], S MALL N ORB [LeCun et al., 2004], S HAPES 3D [Burgess and Kim, 2018],
C AMELYON
[Koh et al., 2020, Bandi et al., 2018], and I W ILD C AM [Koh et al., 2020, Beery et al., 2018].
We discuss precisely how we set up the shifts for these datasets in appendix G.2.
3.1 Takeaways
Takeaway 1: While we can improve over ERM, no one method always performs best.
The relative performance between methods varies across datasets and shifts.
Under spurious correlation (ﬁgure 2), C YCLE GAN consistently performs best but in ﬁgure 3, under low-data drift , pretraining consistently performs best.
Under unseen data shift (ﬁgure 4), pretraining is again one of the best performing models.
However, if we drill down on the results in ﬁgure 7, we can see pretraining performs best on the synthetic datasets but not on C AMELYON 17 (where using augmentation or
DANN is best) or I W ILD C AM (where using ViT or an MLP is best).
Takeaway 2: Pretraining is a powerful tool across different shifts and datasets.
While pretraining is not always helpful (e.g. on C AMELYON 17 in ﬁgures 7-9, I W ILD C AM in ﬁgures 7-8), it often provides a strong boost in performance.
This is presumably because the representation z learned during pretraining is helpful for the downstream task.
For example, the representation may have been trained to be invariant to certain useful properties (e.g. scale, shift, and color).
If these properties are useful on the downstream tasks, then the learned representation should improve generalization.
Takeaway 3:
Heuristic augmentation improves generalization if the augmentation describes an attribute.
In all settings (ﬁgures 2-4), ImageNet augmentation generally improves performance.
However, RandAugment, AugMix, and AutoAugment have more variable performance (as further shown in ﬁgures 7-9).
These methods are compositions of different augmentations.
We investigate each augmentation of RandAugment in appendix D.3 and ﬁnd variable performance.
Augmentations that approximate an existing property in the dataset (an attribute) lead to the best results; otherwise, the model may waste capacity.
For example, on C AMELYON 17 (which consists of cell images), color jitter harms performance but on S HAPES 3D and MPI3D it is essential.
Takeaway 4: Learned data augmentation is effective across different conditions and distribution shifts.
This approach is highly effective in the spurious correlation setting (ﬁgure 2).
It can also help in the low data and unseen data shift settings (ﬁgure 3,4) (though the gains for these two shifts are not as large as for pretraining).
This effectiveness can be explained by the fact that if the augmentations are learned perfectly, then augmented samples by design are from the true data distribution.
Takeaway 5: Domain generalization algorithms offer limited performance improvement.
In some cases these methods (in particular DANN) do improve performance, most notably in the low data drift and unseen data shift settings (ﬁgures 3-4).
However, this depends on the dataset (see ﬁgures 7-9) and performance is rarely much better than using heuristic augmentation.
Takeaway 6: The precise attributes we consider directly impacts the results.
On D S PRITES , if we make color the label, we ﬁnd that all methods generalise perfectly in the unseen data shift setting to unseen shapes (ﬁgure 6) unlike when shape is the label and color values unseen (ﬁgure 7).
DANN perform consistently well.
3.2 Practical tips
Tip 1: If heuristic augmentations approximate attributes in the dataset, use them.
Under this constraint, heuristic augmentations can signiﬁcantly improve performance; this should be a ﬁrst point of call.
How to heuristically choose these augmentations without exhaustively trying all possible combinations is an open research question.
Tip 2: If heuristic augmentations do not help, learn the augmentation.
If the attributes in the dataset cannot be readily approximated with heuristic techniques, but some subset of the attributes can be modelled by using a conditional generative model, this is a promising way to further improve performance.
How to learn the true underlying generative model of the data directly and use this for augmentation is a promising area to explore more thoroughly.
Tip 3:
Use pretraining.
In general, pretraining was found to be a useful way to learn a robust representation.
While this was not true for all datasets (e.g. C AMELYON 17, I W ILD C AM ), performance could be dramatically improved by pretraining ( D S PRITES , MPI3D, S MALL N ORB , S HAPES 3D).
An area to be investigated is the utility of self-supervised pre-training.
Tip 4: More complex approaches lead to limited improvements.
Domain generalization, adaptive approaches and disentangling lead to limited improvements, if any, across the different datasets and shifts.
Of these approaches, DANN performs generally best.
How to make these approaches generically useful for robustness is still an open research question.
Discussion
Our experiments demonstrate that no one method performs best over all shifts and that performance is dependent on the precise attribute being considered.
This leads to the following considerations.
There is no way to decide a-priori on the best method given only the dataset.
It would be helpful for practitioners to be able to select the best approaches without requiring comprehensive evaluations and comparisons.
Moreover, it is unclear how to pinpoint the precise distribution shift (and thereby methods to explore) in a given application.
This should be an important future area of investigation.
We should focus on the cases where we have knowledge about the distribution shift.
We found that the ability of a given algorithm to generalize depends heavily on the attribute and dataset being considered.
Instead of trying to make one algorithm for any possible shift, it makes sense to have adaptable algorithms which can use auxiliary information if given.
Moreover, algorithms should be evaluated in the context for which we will use them.
It is pivotal to evaluate methods in a variety of conditions.
Performance varies due to the number of examples from each part of the distribution.
Thus it is important to perform comprehensive evaluations when comparing different methods, as in our framework.
This gives others a more realistic view of different models’ relative performance in practice.
Conclusion
This work has put forward a general, comprehensive framework to reason about distribution shifts.
We analyzed 19 different methods, spanning a range of techniques, over three distribution shifts – spurious correlation , low data drift , and unseen data shift .
We hope that our framework and comprehensive benchmark spurs research on in this area and provides a useful tool for practitioners to evaluate which methods work best under which shifts. Acknowledgments
The authors thank Irina Higgins and Timothy Mann for feedback and discussions while developing their work.
They also thank Irina, Rosemary Ke and Dilan Gorur for reviewing earlier drafts.
A Overview
In the appendix we ﬁrst motivate the types of distributions we considered by connecting them to ideas from disentanglement literature in appendix
B.
We then relate the 19 approaches we considered to this framework in appendix C. We then give the full results as well as additional results in appendix D; code samples from our framework showing how it can be extended in appendix E; a thorough literature review in appendix F; a description of the datasets and how we set up the distribution shifts on these datasets in appendix G; and ﬁnally implementation details in appendix H.
B Robustness Framework
In this section we introduce our robustness framework for characterizing distribution shifts in a principled manner.
We then relate three common, real world inspired distribution shifts.
B.1 Latent Factorisation
We assume a joint distribution p of inputs x and corresponding attributes y 1 , y 2 , . . .
, y K (denoted as y 1: K ) with y k ∈
A k where A k is a ﬁnite set.
One of these K attributes is a label of interest, denoted as y l (in a mammogram, the label could be cancer/benign and a nuisance attribute
y i with i (cid:54) =
l could be the identity of the hospital where the mammogram was taken).
Our aim is to build a classiﬁer f that minimizes the risk R .
However, in real-world applications, we only have access to a ﬁnite set of inputs and attributes of size n .
Hence, we minimize the empirical risk ˆ R instead:
[Equation]
where L is a suitable loss function.
Here, all nuisance attributes y k with k (cid:54) =
l are ignored and we work with samples obtained from the marginal p ( y l , x ) .
In practice, however, due to selection bias or other confounding factors in data collection, we are only able to train and test our models on data collected from two related but distinct distributions: p train , p test .
For example, p train and p test may be concentrated on different subsets of hospitals and this discrepancy may result in a distribution shift; for example, hospitals may use different equipment, leading to different staining on their cell images.
While we train f on data from p train by minimizing ˆ R ( f ; p train ) , we aim to learn a model that generalises well to data from p test ; that is, it should achieve a small ˆ R ( f ; p test ) .
While generalization in the above sense is desirable for machine learning models, it is not clear why a model f trained on data from p train should generalise to p test .
It is worth noting that while p train and p test can be different, they are both related to the true distribution p .
As such, we take inspiration from disentanglement literature to express this relationship.
In particular, that we can view data as being decomposed into an underlying set of factors of variations.
We formalise various distribution shifts using a latent variable model for the true data generation process:
[Equation]
where z denotes latent factors.
By a simple refactorization, we can write
[Equation]
Thus, the true distribution can be expressed as the product of the marginal distribution of the attributes with a conditional generative model.
We assume that distribution shifts arise when a new marginal distribution for the attributes is chosen, such as p ( y 1: K ) (cid:54) =
p train ( y 1: K ) (cid:54) =
p test ( y 1: K ) , but otherwise the conditional generative model is shared across all distributions, i.e., we have p test ( y 1: K , x ) =
p test ( y 1: K ) (cid:82) p ( x | z ) p ( z | y 1: K ) dz , and similarly for p train .
We focus on common cases of distribution shifts visualized in ﬁgure 1; we discuss these in more detail in section B.2.
To provide more context, as a running example, we use the color D S PRITES dataset [Matthey et al., 2017]; where in our notation y 1 deﬁnes the color with A 1 = { red , green , blue } , and y 2 deﬁnes the shape with A 2 = { ellipse , heart , square } .
We can imagine that a data collector (intentionally or implicitly) selects some marginal distribution over attributes p train ( y 1: K ) when training; for example they select mostly blue ellipses and red hearts.
This induces a new joint distribution over latent factors and attributes: p train ( z, y 1: K ) =
p ( z | y 1: K ) p train ( y 1: K ) .
Consequently, during training, we get images with a different joint distribution p train ( x , y 1: K ) =
(cid:82) p ( x | z ) p train (
z, y 1: K ) .
This similarly applies when collecting data for the test distribution.
The goal of enforcing robustness to distribution shifts is to maintain performance when the data generating distribution p train changes.
In other words, we would like to minimize risk on p, p test given only access to p train .
We can achieve robustness in the following ways:
• Weighted resampling.
We can resample the training set using importance weights W ( y 1: K ) =
p ( y 1: K ) /p train ( y 1: K ) .
This means that given the attributes, the i -th data point ( y 1: K i , x i ) in the training set is used with probability W ( y 1: K i ) / (cid:80) ni (cid:48)
=1 W ( y 1: K i (cid:48) ) rather than 1 /n .
We refer to this empirical distribution as p reweight .
This procedure requires access to the true distribution of attributes p ( y 1: K ) , so to avoid bias and improve fairness, it is often assumed that all combinations of attributes happen uniformly at random.
• Data Augmentation : Alternatively, we can learn a generative model ˆ p ( x | y 1: K ) from the training data that aims to approximate (cid:82) p ( x | z ) p ( z | y 1: K ) dz , as the true conditional generator is by our assumption the same over all (e
g. train and test) distributions.
If such a conditional generative model can be learned, we can sample new synthetic data at training time (e
g. according to the true distribution p ( y 1: K ) ) to correct for the distribution shift.
More precisely, we can generate data from the augmented distribution p aug =
(1 − α ) p reweight + α ˆ p ( x | y 1: K ) p ( y 1: K ) and train a supervised classiﬁer on this augmented dataset.
Here, α ∈ [0 , 1] is the percentage of synthetic data used for training.
• Representation Learning : An alternative factorization of a data generating distribution (e.g. train) is p train ( y 1: K , x ) =
(cid:82) p ( z | x ) p train ( y 1: K | z ) dz .
We can learn an unsupervised representation that approximates p ( z | x ) using the training data only, and attach a classiﬁer to learn a task speciﬁc head that approximates p train ( y l | z ) .
Again, by our assumption p ( z | x ) ∝ p ( x | z ) p ( z ) .
Given a good guess of the true prior, the learned representation would not be impacted by the speciﬁc attribute distribution and so generalise to p test , p .
B.2 Distribution Shifts
While distribution shifts can happen in a continuum, we consider three types of shifts, inspired by real-world challenges.
Test distribution p test .
We assume that the attributes are distributed uniformly: p test ( y 1: K ) = 1 / (cid:81) i | A i | .
This is desirable, as all attributes are represented and a-priori independent.
Shift 1: Spurious correlation – Attributes are correlated under p train but not p test .
Spurious correlation arises in the wild for a number of reasons including capture bias, environmental factors, and geographical bias [Beery et al., 2018, Torralba and Efros, 2011].
These spurious correlations lead to surprising results and poor generalization.
Therefore, it is important to be able to build models that are robust to such challenges.
In our framework, spurious correlation arises when two attributes y a , y b are correlated at training time, but this is not true of p test , for which attributes are independent: p train ( y a | y 1 . . .
y b . . .
y K ) > p train ( y a | y 1 . . .
y b − 1 , y b +1 . . .
y K ) .
This is especially problematic when one attribute y b is y l , the label.
Using the running D S PRITES example, shape and color may be correlated and the model may ﬁnd it easier to predict color.
If color is the label, the model will generalise well.
However, if the aim is to predict shape, the model’s reliance on color will lead to poor generalization.
Shift 2: Low-data drift – Attribute values are unevenly distributed under p train but not under p test .
Low-data drift arises in the wild (e.g. in [Buolamwini and Gebru, 2018] for different ethnicities) when data has not been collected uniformly across different attributes.
When deploying models in the wild, it is important to be able to reason and have conﬁdence that the ﬁnal predictions will be consistent and fair across different attributes.
In the framework above, low-data shifts arise when certain values in the set
A a of an attribute y a are sampled with a much smaller probability than in p test : p train ( y a = v ) (cid:28) p test ( y a = v ) .
Using the D S PRITES example, only a handful of red shapes may be seen at training time, yet in p test all colors are sampled with equal probability.
Shift 3:
Unseen data shift – Some attribute values are unseen under p train but are under p test .
This is a special case of shift 2: low-data drift.
which we make explicit due to its important real world applications.
Unseen data shift arises when a model, trained in one setting is expected to work in another, disjoint setting.
For example: a model trained to classify animals on images at certain times of day should generalise to other times of day.
In our framework, unseen data shift arises when some values in the set
A a of an attribute y
a
are unseen in p train but are in p test : p train ( y a = [Equation] =
[Equation]
This is a stronger constraint than in standard out-of-distribution generalization (see appendix F), as multiple values for A a must be seen under p train , which allows the model to learn invariance to y a .
In the D S PRITES example, the color red may be unseen at train time but all colors are in p test .
Discussion.
We choose these sets of shifts as they are the building blocks of more complex distribution shifts.
Consider the simplest case of two attributes: the label and a nuisance attribute.
If we consider the marginal distribution of the label, it decomposes into two terms: the conditional probability and the probability of a given attribute value: p ( y l ) =
(cid:80)
y a p ( y l | y a ) p ( y a ) .
The three shifts we consider control these terms independently: unseen data shift and low-data drift control p ( y a ) whereas spurious correlation controls p ( y l | y a ) .
The composition of these terms describes any distribution shift for these two variables.
C Method
Here we give further description of the methods we implement and how they relate to our robustness framework.
This allows us to obtain an intuition of what guarantees each method gives in this context and thereby under what circumstances they should promote generalization.
Backbone architecture.
We investigate the performance of different standard vision models on the robustness task.
The model is trained on p train to predict the true label, making no use of the additional attribute information.
We use weighted resampling p reweight
[Vapnik, 1992] to oversample from the parts of the distribution that have a lower probability.
This is what we refer to as the standard setup.
Heuristic data augmentation.
In this case, we use standard heuristic augmentation methods in order to augment the training samples in p train .
Instead of attempting to learn the conditional generative model, in this approach, we ‘fake’ the generative model by augmenting the images using a set of heuristic functions to create p aug , α = 1 .
However, we have to heuristically choose these functions, so the generative model they approximate may not correspond to the true underlying generative model p ( x | y 1: K ) .
In practice, these methods make no use of the additional attribute information and are trained to predict the label, as in the standard setup.
Learned data augmentation.
Again, we approximate the underlying generative model p ( x | y 1: K ) by a set of augmentations.
However, instead of heuristically choosing these augmentation functions, we learn them from data.
We learn a function that, given an image x and attribute y a = v i , transforms x to have another attribute value y a = v j , while keeping all other attributes ﬁxed.
We can then use this function to generate new samples p aug , α = 1 with any distribution over y a .
In particular, we generate samples under the uniform distribution.
In this case, the additional attribute information is used to generate new samples from a given image.
However, the performance of this approach is highly dependent on the quality of the learned generative model.
We follow Goel et al.
[2020], who use C YCLE GAN [Zhu et al., 2017] to learn how to transform an image with one attribute value to have that of another.
(We do not use their additional SGDRO objective as we want to study the impact of the data augmentation process alone.)
In our case, there are more than two attribute values, so we use S TAR GAN [Choi et al., 2018] to learn a single model that, conditioned on an input image and desired attribute, transforms that image to have the new attribute.
Domain generalization.
These works were devised to improve domain generalization.
They can also be seen as a form of representation learning.
The aim is to recover p ( z | x ) such that the representation z is independent of the domain (in our framework, the attribute y a ): p ( y a , z )
=
p ( y a ) p
( z ) .
If this is achieved, then the task speciﬁc classiﬁer p ( y l | z ) will be independent of y a by deﬁnition.
However, these approaches rely on the ability of the underlying method to learn invariance.
Adaptive approaches.
These works modify the reweighting distribution in p reweight using multi stage training.
The models are trained ﬁrst as for the standard setup, giving a classiﬁer f o .
JTT [Liu et al., 2021] then uses f o to approximate the difﬁculty of the sample.
The more difﬁcult samples are weighted higher in the second stage according to a factor λ .
This is equivalent to sampling the more difﬁcult sample λ times in a batch (thereby learning a more complex function W ).
BN-Adapt [Schneider et al., 2020] learns K models in the second stage by modifying the batch normalization parameters.
For the j -th model, W ( y j ) = 1 , W ( y i ) = 0 for i (cid:54) =
j .
However, neither of these methods give strong guarantees on the properties of the ﬁnal model.
Representation learning.
Finally, in representation learning, the aim is to learn an initial representation that has preferable properties to standard ERM training; the motivation for this approach is discussed in appendix B.
To learn the prior, we can pretrain f on large amounts of auxiliary data, such as on ImageNet [Russakovsky et al., 2015].
This has been demonstrated to improve model robustness and uncertainty between datasets [Hendrycks et al., 2019], but here we investigate its utility under different distribution shifts.
Another approach is to attempt to learn a disentangled representation with a VAE, as in β -VAE [Higgins et al., 2017a], where z would then describe the underlying factors of variation for the generative model.
However, the robustness of these methods is dependent on the quality of the learned representation for the speciﬁc robustness task.
D Results
We give the complete breakdown of results for all methods and shifts in appendix D.1.
We give a detailed analysis on the impact of each augmentation type in RandAugment in appendix D.3.
Finally, we evaluate the performance using a different attribute as the label in appendix D.3 and using the ID (as opposed to OOD) validation set on I W ILD C AM and C AMELYON 17 in appendix D.4.
D.1 Complete results
Here, we give the complete results over each dataset for each shift ( spurious correlation , low-data drift , and unseen data shift ) in ﬁgures 7-9.
In these plots, we plot the mean and standard deviation of each method on each dataset and sort them according to their performance.
D.2 A detailed analysis on the impact of augmentation
We found that different methods of performing heuristic augmentation perform differently: some outperform the ERM baseline, some do not.
Each of these methods are composed of individual augmentation techniques.
Here, we investigate how each technique contributes to the end performance and thereby how the choice of augmentation function impacts the robustness of the models.
We take the augmentations used in RandAugment.
Instead of sampling all augmentations randomly, for each augmentation, we randomly sample the given augmentation or the identity function.
We plot the deviation from the mean in ﬁgure 5 for each dataset under unseen data shift .
The results are surprising.
No augmentation always leads to a strong boost in performance.
For example, using invert improves performance on D S PRITES , S HAPES 3D but harms performance on MPI3D,
S MALL N ORB , and I W ILD C AM .
Similarly, using color improves performance on most datasets but harms performance on C AMELYON 17.
D.3 Results with different attributes
Here we investigate if the results are dependent on the attributes being investigated.
We investigate unseen data shift on D S PRITES , but instead of predicting shape, we predict color.
We then leave out some shapes and test whether models can correctly predict color given the unseen shape.
We ﬁnd that all methods generalise to the OOD case with approximately perfect score, as shown in ﬁgure 6.
D.4 Results using different, OOD validation sets
When evaluating on I W ILD C AM and C AMELYON 17, we explore whether using the out-of-distribution (OOD) or in-distribution (ID) validation sets are preferable for obtaining best performance.
We ﬁnd that neither the out-of-distribution (OOD) nor in-distribution (ID) validation sets perform best, but the
As can be seen, no one augmentation always improves performance.
An augmentation that may improve performance on one dataset (e.g. invert on S HAPES 3D) hurts performance on another (e.g. invert on S MALL N ORB ).
relative performance remains similar The relative performance of different models in ﬁgure 7 when using the ID or OOD validation set is comparable on C AMELYON [-
-]17 and I W ILD C AM .
However, the maximum performance is not consistently better using either the ID or OOD set (for C AMELYON 17,
OOD performs best but for I W ILD C AM , ID performs best).
[Figure]
E Extending the evaluation framework
Our evaluation framework is easily extendable.
Different methods, datasets, and distribution shifts can be easily added and evaluated.
We include code in appendix E.1-E.3, demonstrating how this is done.
E.1 Adding a new distribution shift
Changing the distribution shift simply amounts to updating four values.
These values deﬁne (1) how to construct the distribution as a combination of other distributions; (2) the total number of samples from each distribution; (3) the probability of sampling from a given distribution; and (4) the probability that the label is corrupted at training time.
Assume a dataset that has the key center which takes values in the range [0, 4] and the key label which takes values in the set {0, 1}.
The code in algorithm 1 deﬁnes the following dataset: with probability 0.1, we sample an example that is either from center 0 or center 1 from the complete dataset; with probability 0.4 we sample from a total of 100 samples that are from center 3 or 4 with label 0; and with probability 0.5, we sample from a total of 10K samples from centers 0, 1, 2.
None of the labels are corrupted.
[Table]
[Table]
Listing 1: Setting up a new distribution shift.
E.2 Adding a new dataset
Adding a new data loader requires implementing three methods: (1) a preprocessing function for how to preprocess a batch; (2) a function to load the data in a tensorﬂow datasets format; (3) a function to batch and shufﬂe this tensorﬂow dataset.
In algorithm 2, we demonstrate how this is done for the
S HAPES 3D dataset and in algorithm 3 how the conﬁg is updated to include a new dataset
[Figure]
:ds = tfds
[Figure]
load(name=’shapes3d’, split=tfds
[Figure]
Split
[Figure]
TRAIN)
[Figure]
skip(test
[Figure]
size)
[Figure]
take(valid_size)elif subset == ’train_and_valid’:ds = tfds
[Figure]
load(name=’shapes3d’
[Figure]
split=tfds
[Figure]
Split
[Figure]
TRAIN)
[Figure]
skip(test_size)elif subset == ’test’:ds = tfds
[Figure]
load(name=’shapes3d’, split=tfds. Split. TRAIN).take(test_size)else:raise ValueError(’Unknown subset: "{}"’.format(subset))return ds
[Table] [Table]
[Table] [Table]
[-return ds 
-]
[Table] [Table]
[Table]
if preprocess_fn is None [Figure]
[Figure]
Listing 3: Updating the conﬁg to use the new dataset.
E.3 Adding a new method
Adding a new loss function.
Adding a new loss function simply amounts to extending the abstract class in algorithm 4 and updating the conﬁg (see algorithm 5) to point to this loss function.
[Table]
[Figure]
[Table]
[Figure]
[Table]
[Figure]
[Table]
[Figure]
[Table]
def adversary(self, logits, attributes, reduction = ’mean’, targets =
None):"""The adversarial loss function.
If la = LearningAlgorithm(), this function is applied in a min-max game with la().
The model is trained to minimize the loss arising from la(), while maximizing the loss from the adversary (la. adversary()).
[-Returns: 
 has no-]The adversarial part of the model tries to minimize this loss.
[-734""" 735# Do nothing. [Table] return {} 737 
-]Args:logits: The predicted value input to the training algorithm.attributes: A set of attributes of the input data.reduction: How to combine the loss for different samples (’mean’ or ’sum’).targets: The ground truth value to estimate (optional).
Returns:scalars: A dictionary of key and scalar estimates.
The key ’adv_loss’ is the value that should be minimized (for the adversary) and maximized (for the model). If empty, this learning algorithm has no adversary."
""# Do nothing.return {} 383940 class ERM(base.LearningAlgorithm):"""An example, demonstrating how to compute the empirical risk within our framework.""" def __init__(self, loss_fn, name = ’empirical_risk’):super().__init__(loss_fn= loss_fn, name=name) def __call__(self, logits, targets, reduction = ’mean’, **unused_kwargs):loss = self.loss_fn(logits, targets, reduction=
reduction)return {’loss’: loss}, logits
Listing 4: Setting up a new loss function.
[Figure]
Listing 5:
Updating the conﬁg
for the new loss function
Extending other parts of the framework.
We similarly deﬁne abstract classes, initialized in the conﬁg, for model selection, preprocessing and postprocessing a batch, and adapting model parameters at train and test time.
These can all be extended in order to include new models, algorithms, preprocessing and postprocessing steps or adaptive approaches.
[Figure] [Figure]
F Literature review
Here we discuss in depth related literature.
We ﬁrst discuss datasets and benchmarks used to evaluate different distribution shifts.
We then discuss methods related to the ﬁve common approaches we consider in the paper: architecture choice, data augmentation, domain generalization methods, adaptive approaches, and representation learning.
We additionally discuss the hypotheses present in the current literature and whether our results corroborate or dispute those hypotheses.
Benchmarking robustness to out of distribution (OOD) generalization.
While a multitude of methods exist that report improved OOD generalization, Gulrajani and Lopez-Paz [2021] found that in actuality no evaluated method performed signiﬁcantly better than a strong ERM baseline on a variety of datasets.
However, Hendrycks et al.
[2021] found that, when we focus on better augmentation, larger models and pretraining, we can get a sizeable boost in performance.
This can be seen on the Koh et al.
[2020] benchmark (the largest boosts come from larger models and better augmentation).
Our work is complementary to these methods, as we look at a range of approaches (pretraining, heuristic augmentation, learned augmentation, domain generalisation, adaptive, disentangled representations) on a range of both synthetic and real-world datasets.
Moreover, we allow for a ﬁne-grained analysis of methods over different distribution shifts.
Benchmarking spurious correlation and low-data drift.
Studies on fairness and bias (surveyed by Mehrabi et al.
[2021]) have demonstrated the pernicious impact of low-data in gender recognition [Buolamwini and Gebru, 2018], medical imaging [Castro et al., 2020], and conservation [Beery et al., 2018] and spurious correlation in classiﬁcation [Geirhos et al., 2019] and conservation [Beery et al., 2020].
Arjovsky et al.
[2019] hypothesized that spurious correlation may be the underlying reason for poor generalization of models to unseen data.
To our knowledge, there has been no large scale work focused on understanding the beneﬁts of different methods across these distribution shifts systematically across multiple datasets and with ﬁne-grained control on the amount of shift.
Here we introduce a framework for creating these shifts we seek to understand in a controllable way to allow such challenges to be investigated robustly.
Benchmarking disentangled representations.
A related area, disentangled representation learning aims to learn a representation where the factors of variation in the data are separated.
If this could be achieved, then models should be able to generalise effortlessly to unseen data as investigated in multiple settings such as reinforcement learning [Higgins et al., 2017b].
Despite many years of work in disentangled representations [Higgins et al., 2017a, Burgess et al., 2017, Kim and Mnih, 2018,
Chen et al., 2018], a benchmark study by Locatello et al.
[2019] found that, without supervision or implicit model or data assumptions, one can not reliably perform disentanglement; however, weak supervision appears sufﬁcient to do so [Locatello et al., 2020].
Dittadi et al.
[2021], Schott et al.
[2021], Montero et al.
[2020] further investigated whether representations (disentangled or not) can interpolate, extrapolate, or compose properties; they found that when considering complex combinations of properties and multiple datasets, representations do not do so reliably.
Datasets to evaluate distribution shifts.
Obtaining datasets of real world distribution shifts is challenging and expensive.
As a result, many works have focussed on using synthetic or existing datasets to build their benchmarks.
One approach is to create synthetic shifts over ImageNet to study how models generalise in speciﬁc, synthetic conditions: ImageNet-C [Hendrycks and Dietterich, 2019] studies the impact of standard corruptions; Stylized ImageNet [Geirhos et al., 2019] studies the impact of texture; Waterbirds and the Backgrounds challenge [Sagawa et al., 2020, Xiao et al., 2020] study the impact of a fake background; and colored MNIST [Gulrajani and Lopez-Paz, 2021] studies impact of color on classiﬁcation.
Another approach is to consider how models trained on a given dataset generalise to other datasets of the same set of objects (e.g. cartoons to paintings in PACS or ImageNet to ImageNetV2)
[Torralba and Efros, 2011, Li et al., 2017, Recht et al., 2019, Peng et al., 2019, Venkateswara et al., 2017] or over time [Shankar et al., 2019].
While these datasets give insight into the biases of a trained model, models that do well on them may not necessarily do well on real world tasks.
As a result, the WILDS dataset [Koh et al., 2020] was created as a collection of real world distribution shifts where the OOD task is well deﬁned (e.g. the model should generalise to unseen countries for satellite imagery or hospitals for tumour identiﬁcation) in order to evaluate progress.
Controllable shifts?
Many methods?
Real world motivated?
Ours (cid:51) (cid:51) (cid:51)
WILDS [Koh et al., 2020] (cid:55) (cid:55) (cid:51)
Gulrajani and Lopez-Paz [2021] (cid:55) (cid:51) (cid:55)
Hendrycks et al.
[2021] (cid:55) (cid:51) (cid:55)
Our framework is complementary to these datasets and benchmarks (table 1).
Given a dataset, our framework can be used to set up a desired distribution shift to be investigated with ﬁne-grained control over the type of distribution shift and amount of shift.
Moreover, our framework provides extendable classes for a wide range of approaches and datasets.
Finally, we present a robustness framework inspired by disentangling literature hypothesizing when we expect models to be able to generalise across these shifts.
Architecture choice.
Previous work has investigated the impact of model size on robustness to various distribution shifts, ﬁnding that larger models generally are more robust when considering common corruptions [Hendrycks et al., 2019] and adversarial training [Xie and Yuille, 2020].
However, [Schott et al., 2021] ﬁnds that larger models do not give representations that generalise better within the same domain.
We ﬁnd that there is no strict rule correlating model size or model capacity with performance.
Sometimes deeper ResNets perform best, sometimes not.
The ViT model (with the highest capacity) often performs worse, but on I W ILD C AM it performs best.
Data augmentation.
Data augmentation is often pivotal to achieve state of the art performance on machine learning benchmarks, leading to a wide range of methods to perform heuristic data augmentation [He et al., 2016, Hendrycks et al., 2020, Cubuk et al., 2019, 2020, Zhang et al., 2018].
When considering domain generalization, more speciﬁc techniques for augmentation have been devised to improve a model’s ability to generalise using MixUp [Gulrajani and Lopez-Paz, 2021, Xu et al., 2020, Yan et al., 2020, Wang et al., 2020] or knowledge of the domains [Zhang et al., 2019].
Instead of using heuristic data augmentations which cannot be used to learn more complex transformations, the desired augmentation can be learnt.
The training data can be augmented by transforming samples using a generative model to either come from another part of the domain conditioned on an attribute [Goel et al., 2020], another domain [Zhou et al., 2020], be domain agnostic
[Carlucci et al., 2019], or to have a different style [Gowal et al., 2020, Geirhos et al., 2019].
These methods often build on work in image generation, such as C YCLE GAN [Zhu et al., 2017] and S TYLE GAN [Karras et al., 2019].
We ﬁnd that these approaches can be effective to learn invariance to the heuristic or learned transformation.
However, performance depends on whether the augmentation is a useful property to learn invariance against, else the model may waste capacity.
Domain generalization.
While many works can be viewed as aiming to improve robustness of models in new domains, here we focus on those methods that aim to learn domain invariant features in stochastic trained machine learning models.
One impactful approach to learning features invariant to the domain is DANN [Ganin et al., 2016]
(domain adversarial neural networks).
This work uses an adversarial network [Goodfellow et al., 2014] to enforce that the features cannot be predictive of the domain.
Later work considered a number of ways to enforce invariance, such as the following: minimizing the maximum mean discrepancy [Long et al., 2015, 2017], invariance of the conditional distribution [Li et al., 2018], and invariance of the covariance matrix of the feature distribution [Sun and Saenko, 2016].
However, enforcing invariance is challenging to learn and often too strict a constraint
[Johansson et al., 2019, Zhao et al., 2019].
As a result, IRM [Arjovsky et al., 2019] instead enforces that the optimal classiﬁer for different domains is the same.
We ﬁnd that DANN performs consistently best but that performance varies over different datasets and distribution shifts.
Adaptive approaches.
Instead of learning a single model and treating samples similarly, adaptive approaches can be used to either modify model parameters or dynamically modify training if there are multiple domains (or groups with different attributes) within the training set.
Ways to adapt the model parameters to a new domain include meta learning (as in MAML [Finn et al., 2017]) and adapting the batch normalisation statistics based on the different domains [Schneider et al., 2020].
Instead of adapting the parameters, other approaches reweigh the importance of samples on which the model struggles.
This, intuitively, should force the model to spend more capacity on more challenging parts of the domain (or groups with fewer samples).
In GroupDRO [Sagawa et al., 2020], this amounts to putting more mass on samples from the more challenging domains at train time using the loss to determine the challenging domains.
In JTT [Liu et al., 2021], this is done by two stage training.
First, a classiﬁer is trained in a standard manner.
Then, a second classiﬁer is trained by upweighting the samples with a high loss according to the ﬁrst classiﬁer.
The authors posit that the most challenging samples will be those coming from groups with few samples (the low-data regions).
We ﬁnd that neither of these methods consistently performs better than the baselines.
Representation learning.
Finally, instead of focusing on the downstream task, another approach is to learn a representation p ( z | I ) that approximates the true prior over the latent factors.
This can be done by pretraining on large amounts of data such as ImageNet [Russakovsky et al., 2015, Deng et al., 2009] as explored by [Hendrycks et al., 2021] for domain generalization, such that the learned representation is potentially more robust and general.
Our results corroborate their ﬁndings: in many cases pretraining is helpful.
However, this is not universally true.
On C AMELYON 17 and I W ILD C AM , pretraining did not improve performance across all shifts.
For example, pretraining was unhelpful under spurious correlation on C AMELYON 17.
Another approach is to learn a representation subject to constraints.
This is what the disentanglement literature aims to do: ﬁnd a representation that is sparse and low dimensional, which hopefully will correspond to a higher level, disentangled representation.
Disentanglement is a large research area, so we brieﬂy mention some formative works, such as the β -VAE [Higgins et al., 2017a, Burgess et al., 2017] and FactorVAE
[Kim and Mnih, 2018], which build on the original VAE [Kingma and Welling, 2013, Rezende et al., 2014] formulation.
Other approaches build on GANs [Goodfellow et al., 2014], such as InfoGAN [Chen et al., 2016].
A recent study of these methods [Locatello et al., 2019] found that they did not reliably disentangle the representation into a semantically meaningful set of latent variables.
Therefore, it is unclear how robust these methods are when used for distribution shifts, but our results imply that more research is needed to make these approaches practically useful.
G Dataset
Here we give further details about the datasets in appendix G.1, how we set up the shifts and conditions for these datasets in appendix G.2 and ﬁnally we give samples from the different datasets and shifts in appendix G.3.
G.1 Details
Here we give further detail about each of the datasets and how we set the two attributes: y l , y a .
D S PRITES .
D S PRITES [Matthey et al., 2017] consists of shapes (heart, ellipse, and square), which we augment with three colors (red, green, and blue).
The shapes vary in location, scale, and orientation.
We make the shape the label, and the attribute the color (we consider other choices in the appendix).
MPI3D.
MPI3D [Gondal et al., 2019] consists of real images of shapes on a robotic arm.
There are six shapes and the images vary in terms of the object color, object size, camera height, background color and the rotation about the horizontal and vertical axis.
We make the shape the label and color the other attribute.
S HAPES 3D.
S HAPES 3D [Burgess and Kim, 2018] consists of images of shapes centered in a synthetic room.
There are three shapes and the images vary in terms of the ﬂoor hue, object hue, orientation, scale, shape, and wall hue.
We make the shape the label and object color the other attribute.
S MALL N ORB .
S MALL N ORB [LeCun et al., 2004] consists of images of toys of ﬁve categories with varying lighting, elevation and azimuths.
The aim is to create methods that generalize to unseen samples of the ﬁve categories.
We make the object category the label and azimuth the other attribute for unseen data shift, low-data drift .
We make the lighting the other attribute for spurious correlation .
C AMELYON 17.
C AMELYON
[Koh et al., 2020, Bandi et al., 2018] contains tumour cell images coming from different hospitals.
We follow Koh et al.
[2020] and make the label the presence of tumor cells and the other attribute the hospital from which the image came from.
In spurious correlation, low-data drift , we resplit the dataset randomly (there are no held out hospitals).
In spurious correlation , we correlate the presence of tumor cells with the hospital (all images from a given hospital either do or do not have tumors).
In low-data drift , we select the hospitals that are out of distribution for Koh et al.
[2020] as the hospitals for which we only have N samples.
In unseen data shift , we use the split given by Koh et al.
[2020] and optionally use either the in-distribution or out-of-distribution validation set for model selection.
[Equation]
, 2020, Beery et [Equation] , 2018] contains camera trap imagery.
There are a set of locations.
The camera is kept in the same ﬁxed spot in each location, and takes photos at different times.
The task is to determine if there is an animal in the image and which animal is present.
In spurious correlation, low-data drift , we resplit the dataset randomly (there are no held out locations).
In spurious correlation , we correlate the presence of a given animal with a location (all images from a given location only show a given animal).
In low-data , we select the locations that are out of distribution for Koh et al.
[2020] as the locations for which we only have N samples.
In unseen data shift , we use the split given by Koh et al.
[2020] and optionally use either the in-distribution or out-of-distribution validation set for model selection.
G.2 Evaluated shifts
Shift 1: Spurious correlation.
Under spurious correlation, we correlate y l , y a .
At test time, these attributes are uncorrelated.
We vary the amount of correlation by creating a new dataset with all samples from the correlated distribution in the dataset and N samples from the uncorrelated distribution; this forms the training set.
We set N > = 1 (as if N = 0 , then the problem is ill deﬁned as to what is the correct label).
The test set is composed of sampling from the uncorrelated distribution and is disjoint from the training samples.
Results are given in ﬁgure 2.
Shift 2: Low-data drift.
Under low-data drift, we consider the set A a .
For some subset A ac ⊂
A a , we only see N samples of those attributes.
For all other values of y a ( A a / A ac ), the model has access to all samples.
Results are given in ﬁgure 3.
Shift 3:
Unseen data shift This is a special case of low-data drift , where we set N = 0 .
Results are given in ﬁgure 4.
G.3 Samples from the different distributions
We include samples for each distribution for each dataset in ﬁgure 10-15.
We describe each of the shifts in table 2.
Note that the amount of correlation, samples from the low-data region, and the probability of sampling from the low-data or correlated distributions is controllable in our framework.
Additionally, we can control the amount of label noise and total dataset size.
[Figure]
[Table]
MPI3D [Figure] IID
[Figure]
S HAPES 3D (IID test).
S HAPES 3D ( Shift 1: Spurious correlation. )
S HAPES 3D ( Shift 2: Low-data drift. )
S HAPES 3D ( Shift 3: Unseen data shift. )
[Figure]
C AMELYON 17 (OOD test).
C AMELYON 17 ( Shift 1: Spurious correlation. )
C AMELYON 17 ( Shift 2: Low-data drift. )
C AMELYON 17 ( Shift 3:
Unseen data shift. )
[Figure]
[Table]
H Implementation
We ﬁrst describe the experimental setup in appendix H.1 architectures and precise implementation of each approach in appendix H.2-H.7 and give training details in appendix H.8.
We then give the sweeps over the hyperparameters considered in appendix H.9.
H.1 Experimental setup
Here we describe the precise implementation choices.
We do not claim that these are the best possible results obtainable with these methods (as performing sweeps over all possible settings would be computationally impractical) but that they are indicative of performance.
Model selection.
When investigating heuristic data augmentation, domain generalization, learned augmentation, adaptive approaches, and representation learning, we use a ResNet18 for the simpler, synthetic datasets ( D S PRITES , MPI3D, S HAPES 3D, and S MALL N ORB ) but a ResNet50 for the more complex, real world ones (C AMELYON [-
-]17 and I W ILD C AM ).
To perform model selection, we choose the best model according to the in-distribution validation set ( D valid ⊂ D train ).
In the unseen data shift setting for the C AMELYON 17 and I W ILD C AM , we use the given out-of-distribution validation set, which is a different, distinct set in D that is independent of D train , D test .
(We consider using the in-distribution validation set in appendix D.4.)
Hyperparameter choices.
We perform a sweep over the hyperparameters (the precise sweeps are given in appendix H.9).
We run each set of hyperparameters for ﬁve seeds for each setting.
To choose the best model, we perform model selection for each seed over all runs using the top-1 accuracy.
In the low-data and correlated case, we choose a different set of samples from the low-data region with each seed.
We report the mean and standard deviation over the ﬁve seeds.
H.2 Base architectures
We train three types of models.
These all have different capacities, which we report in table 3.
ResNets.
We use the standard ResNet18, ResNet50, and ResNet101 setups [He et al., 2016].
MLP.
For the MLP, we use a 4 layer MLP with 256 hidden units.
ViT. For the ViT [Dosovitskiy et al., 2021], we set the parameters as follows.
For the smaller 64x images ( D S PRITES , MPI3D, S HAPES 3D), we use a patch size of 4 with a hidden size of 256.
For the transformer, we use 512 for the width of the MLP, 8 heads and 8 layers.
We use a dropout rate of 0.1.
For the medium 96x96 images (C AMELYON 17, S MALL N ORB ), we use a patch size of 12 and for the 256x256 images ( I W ILD C AM ), a patch size of 16.
H.3 Heuristic Augmentation
ImageNet Augmentation.
ImageNet augmentation is composed of random crops and color jitter.
We use the standard ratios as used in ImageNet training He et al.
We only apply the augmentation to the ﬁrst three channels of a dataset (replicating across three channels if the data is grayscale).
AugMix [Hendrycks et al., 2020].
AugMix composes multiple k sequences of augmentations, randomly sampled from thirteen base augmentations.
We use their default: k = 3 .
RandAugment [Cubuk et al., 2020].
RandAugment randomly samples N augmentations from a set sixteen base augmentations with a severity M .
For the augmentation parameters (cutout and translate) based on image size, we interpolate between the values used for ImageNet on 224 images and Cifar10 on 32 images.
We set N = 3 , M = 5 .
AutoAugment [Cubuk et al., 2019].
If the image size is less than 128 (e.g. all datasets but I W ILDC AM ), we use the cifar10 policy, else we use the ImageNet policy.
Again, for the augmentation parameters (cutout and translate) based on image size, we interpolate between the values used for
ImageNet on 224 images and Cifar10 on 32 images.
H.4 Learned Augmentation
CycleGAN [Goel et al., 2020, Choi et al., 2018, Zhu et al., 2017].
This approach proceeds in two stages.
The ﬁrst stage learns how to transform images of one attribute to have another attribute.
In this stage, these models are trained to minimize three losses: a reconstruction loss L r , classiﬁer loss
L c , and adversarial loss L a .
The ﬁnal loss is a combination of these: L = λ r L r + λ c
L c − λ a L a .
We set λ c = 1 , λ r = 1 and we sweep over λ a .
We train this model with a learning rate lr S TAR GAN (using the same learning rate for the generator and discriminator).
We use the same ResNet style architecture as C YCLE GAN, except we append to the image a one hot encoding designating the original attribute, as described in S TAR GAN Choi et al.
We use ﬁve ResNet blocks for images of size 64 ( D S PRITES , MPI3D, S HAPES 3D), six ResNet blocks for images of size 96 (C AMELYON 17, S MALL N ORB ) and nine ResNet blocks for images of size 256 ( I W ILD C AM ).
H.5 Domain Generalization
IRM [Arjovsky et al., 2019].
IRM enforces that the optimal classiﬁer for all domains is the same.
This is done using two terms in the risk: a term to minimize the overall risk and a term to enforce the constraint, with a tradeoff λ .
DeepCORAL [Sun and Saenko, 2016].
DeepCORAL enforces that the mean and covariance of the learned features in different domains is the same.
This is achieved by two terms in the loss: a term to minimize the overall risk and a term to penalize differences in the mean and covariance across each pair of domains.
These are weighted according to a tradeoff λ .
Domain MixUp [Gulrajani and Lopez-Paz, 2021].
Domain MixUp enforces smoothness in the label prediction by interpolating between images from different domains and enforcing the prediction similarly interpolates between the labels.
We set the interpolation parameter λ = 0 .
2 (as in MixUp
Zhang et al.
DANN [Ganin et al., 2016].
DANN trains an adversary g that attempts to predict the attribute from the learned representation and the model seeks to fool this adversary while also minimizing downstream accuracy:
L = L c ( l ( z )) − λ a L a ( g ( z )) .
For the adversary, we use a two layer MLP with
ReLU [Nair and Hinton, 2010] with hidden sizes of size 64 .
SagNet [Nam et al., 2021].
SagNet aims to learn a representation z that is invariant to style by using an adversary.
The classiﬁcation loss L c aims to use the content predictor c to classify z .
The adversary L a aims to use the style predictor
s predict the class.
This give a ﬁnal loss:
L = L c ( c ( z )) − λ a L a ( s ( z )) .
We use the feature extractor of a ResNet18 [He et al., 2016]
(before the average pool) as the representation z .
For the content c and style predictor s , we use MLPs with three hidden dimensions of size 64 and ReLUs.
We set λ a = 1 .
H.6 Adaptive Approaches
JTT [Liu et al., 2021].
JTT uses a pretrained classiﬁer to ﬁnd the most challenging samples.
It then reweights these samples by λ .
We set λ
= 20 and train the ﬁrst model for half the training time.
BN-Adapt [Schneider et al., 2020].
BN-Adapt adapts the parameters of the original model according to the attribute label using a hyperparameter r ( N/n in their paper).
Intuitively, this controls the the strength of the original model r and the new model 1 .
We set r = 10 .
H.7 Representation Learning
β -VAE [Higgins et al., 2017a].
β -VAE poses the original VAE objective using constrained optimisation to obtain a new objective which have a trade-off β between the log-likelihood objective and the KL objective.
We resize images to 64x64 and use a convolutional architecture as in Higgins et al. [2017a].
The encoder consists of the following layers (with ReLUs) to obtain the ﬁnal representation z of size L : Conv 16x5x5 (stride 1, image size: 60), Conv 32x4x4 (stride 2, image size 29), Conv 64x3x3 (stride 1, image size 27), Conv 128x3x3 (stride 2, image size 13), Conv 256x4x4 (stride 1, image size 10), Conv 512x4x4 (stride 2, image size 4), Conv 512x4x4 (stride 1, image size 1), Linear
L .
The decoder has the reverse setup to the encoder with convolutional transpose layers.
There are two terms to trade-off: the strength of β and the size of the latent representation L .
However, a larger latent will need a stronger β .
We use the β norm = βLI which normalises these values by the data size I .
We then sweep over L and β norm .
Finally, to train the downstream classiﬁer, we ﬁx the encoder of the β -VAE.
We then train an MLP (the same as used in appendix H.2) from the representation of size L to the labels.
Pretrained on ImageNet.
We resize images to 224x224 and pass them to a model pretrained on
ImageNet.
We ﬁnetune the full network.
H.8 Training.
We train the ResNets and MLP with the Adam optimizer for 100K steps on the synthetic datasets 200K steps on C AMELYON 17 and W ILD C AM with a batch size of 128. The
ViT is trained with a batch size of 1024 (it did not converge for
smaller batch sizes).
H.9 Sweeps.
The sweeps are given in table 4.
[Table]