D EJA V U : C ONTINUAL M ODEL G ENERALIZATION FOR U NSEEN D OMAINS
A BSTRACT
In real-world applications, deep learning models often run in non-stationary environments where the target data distribution continually shifts over time.
There have been numerous domain adaptation (DA) methods in both online and offline modes to improve cross-domain adaptation ability.
However, these DA methods typically only provide good performance after a long period of adaptation, and perform poorly on new domains before and during adaptation – in what we call the “Unfamiliar Period” , especially when domain shifts happen suddenly and significantly.
On the other hand, domain generalization (DG) methods have been proposed to improve the model generalization ability on unadapted domains.
However, existing DG works are ineffective for continually changing domains due to severe catastrophic forgetting of learned knowledge.
To overcome these limitations of DA and DG in handling the Unfamiliar Period during continual domain shift, we propose RaTP , a framework that focuses on improving models’ target domain generalization (TDG) capability, while also achieving effective target domain adaptation (TDA) capability right after training on certain domains and forgetting alleviation (FA) capability on past domains.
RaTP includes a trainingfree data augmentation module to prepare data for TDG, a novel pseudo-labeling mechanism to provide reliable supervision for TDA, and a prototype contrastive alignment algorithm to align different domains for achieving TDG, TDA and FA.
Extensive experiments on Digits, PACS, and DomainNet demonstrate that RaTP significantly outperforms state-of-the-art works from Continual DA, Source-Free
DA, Test-Time/Online DA, Single DG, Multiple DG and Unified DA&DG in TDG, and achieves comparable TDA and FA capabilities.
I NTRODUCTION
A major concern in applying deep learning models to real-world applications is whether they are able to deal with environmental changes over time, which present significant challenges with data distribution shifts.
When the shift is small, deep learning models may be able to handle it because their robustness is often evaluated and improved before deployment.
However, when the data distribution shifts significantly for a period of time, in what we call the “Unfamiliar Period” , model performance on new scenarios could deteriorate to a much lower level.
For example, surveillance cameras used for environmental monitoring can work normally with excellent performance on clear days, but have inferior performance or even become “blind” when the weather turns bad or the lighting conditions become poor (Bak et al., 2018).
As another example, consider conducting lung imaging analysis for corona-viruses, deep learning models may present excellent performance after being trained on a large number of samples for certain variant (e.g., the Alpha variant of COVID19), but are difficult to provide accurate and timely analysis for later variants (e.g., the Delta or Omicron variant) and future types of corona-viruses (Singh et al., 2020) when they just appear .
In the following, we will first discuss related works, highlight their limitations in addressing the poor model performance during the Unfamiliar Period , and then introduce our approach.
Domain adaptation (DA) methods have been proposed to tackle continual data drifts in dynamic environments in either online or offline mode.
For example, Continual DA (Liu et al., 2020; Rostami, 2021) starts from a labeled source domain and continually adapts the model to various target domains, while keeping the model performance from degrading significantly on seen domains.
However, existing Continual DA works often assume that the source domain can be accessed all the time, which may be difficult to guarantee in practical scenarios, especially considering the possible limitation on memory storage and regulations on privacy or intellectual property.
Source-Free
DA (Yang et al., 2021;
Qu et al., 2022) can overcome this issue and achieve target adaptation without the source domain data.
In addition, Test-Time or Online DA (Wang et al., 2022; Iwasawa &
Matsuo, 2021; Panagiotakopoulos et al., 2022) can improve the target model performance with a small training cost; however, the target domain data is only learned once by the model and the performance improvement is limited (higher improvement would require a large amount of data).
With these DA methods, although the model may perform better on the new target domain after sufficient adaptation, its performance on the target domain before and during the adaptation process, i.e., in the Unfamiliar Period , is often poor.
In cases where the domain shift is sudden and the duration of seeing a new target domain is short, this problem becomes even more severe.
In this work, we believe that for many applications, it is very important to ensure that the model can also perform reasonably well in the Unfamiliar Period , i.e., before seeing a lot of target domain data.
For instance in environmental surveillance, having poor performance under uncommon/unfamiliar weather or lighting conditions may cause significant security and safety risks.
In the example of lung imaging analysis for corona-viruses, being able to quickly provide good performance for detecting new variants is critical for the early containment and treatment of the disease.
Domain generalization (DG) methods also solve the learning problem on multiple data domains, especially for cases where the target domain is unavailable or unknown during training.
However, existing DG works are typically based on accurate supervision knowledge of the source domain data, whether it is drawn from a single domain (Wang et al., 2021c;
Li et al., 2021) or multiple domains (Yao et al., 2022; Zhang et al., 2022), which may not be achievable in continually changing scenarios.
Moreover, when DG is applied in scenarios with continual domain shifts, as it focuses more on the target domain, there could be severe catastrophic forgetting of domains that have been learned.
There are also some works unifying DA and DG (Ghifary et al., 2016; Motiian et al., 2017; Jin et al., 2021); however they can only be used in standard DA or DG individually, thus still suffering their limitations.
Bai et al.
(2022) and Nasery et al.
(2021) study the smooth temporal shifts of data distribution, but they cannot handle large domain shifts over time.
Our Approach and Contribution.
In this work, we focus on the study of Continual Domain Shift
Learning (CDSL) problem, in which the learning model is first trained on a labeled source domain and then faces a series of unlabeled target domains that appear continually.
Our goal, in particular, is to improve model performance before and during the training stage of each previously-unseen target domain (i.e., in the Unfamiliar Period ), while also maintaining good performance in the time periods after the training.
Thus, we propose a framework called RaTP that optimizes three objectives: (1) to improve the model generalization performance on a new target domain before and during its training, namely the target domain generalization (TDG) performance, (2) to provide good model performance on a target domain right after its training, namely the target domain adaptation (TDA) performance, and (3) to maintain good performance on a trained domain after the model is trained with other domains, namely the forgetting alleviation (FA) performance.
For improving TDG, RaTP includes a training-free data augmentation module that is based on Random Mixup, and this module can generate data outside of the current training domain.
For TDA, RaTP includes a Top 2 Pseudo Labeling mechanism that lays more emphasis on samples with a higher possibility of correct classification, which can produce more accurate pseudo labels.
Finally, for optimizing the model towards TDG, TDA, and FA at the same time, RaTP includes a Prototype Contrastive Alignment algorithm.
Comprehensive experiments and ablation studies on Digits, PACS, and DomainNet demonstrate that
RaTP can significantly outperform state-of-the-art works in TDG, including Continual DA, SourceFree DA, Test-Time/Online DA, Single DG, Multiple DG, and Unified DA&DG.
RaTP can also produce comparable performance in TDA and FA as these baselines.
In summary:
• We tackle an important problem in practical scenarios with continual domain shifts,
i
e., to improve model performance before and during training on a new target domain, in what we call the Unfamiliar Period .
And we also try to achieve good model performance after training, providing the model with capabilities of target domain adaptation and forgetting alleviation.
[Figure]
x i s t i n g
M e t h o d
P r o p o s e d R a T P
S o u r c e
D o m a i n 1 s t T a r g e t D o m a i n
• We propose a novel framework RaTP to achieve our goal.
The framework includes a trainingfree data augmentation module that generates more data for improving model’s generalization ability, a new pseudo-labeling mechanism to provide more accurate labels for domain adaptation, and a prototype contrastive alignment algorithm that effectively aligns domains to simultaneously improve the generalization ability and achieve target domain adaptation and forgetting alleviation.
• We conducted extensive experiments and comprehensive ablation studies that demonstrate the advantages of our RaTP framework over a number of state-of-the-art baseline methods.
M ETHODOLOGY
We first formulate the problem of Continual Domain Shift Learning (CDSL) in Section 2.1, and then introduce the three major modules of our framework RaTP .
Specifically, Section 2.2 presents a Random Mixup data augmentation module RandMix that generates data for improving the target domain generalization (TDG) on unadapted domains, which is a crucial technique for improving model generalization in the Unfamiliar Period .
Section 2.3 presents a Top 2 Pseudo Labeling approach T2PL that provides accurate labels to achieve target domain adaptation (TDA) for continually arriving target domains.
Finally, Section 2.4 presents a Prototype Contrastive Alignment algorithm PCA that optimizes the model to achieve TDG, TDA, and forgetting alleviation (FA) on seen domains.
Figure 1 shows the overall pipeline of RaTP .
2. P ROBLEM F ORMULATION OF C ONTINUAL D OMAIN S HIFT L EARNING
We assume that there is a labeled source domain dataset S
= { ( x i , y i )
∥
x i ∼ P S X ,
y i ∼ P S Y } N S i =1 at the beginning of CDSL.
Here P X and P Y are the input and label distributions, respectively, while
N S is the sample quantity.
This paper chooses visual recognition as the learning task, in which the number of data classes is K .
Then, we consider a sequence of continually arriving target domains
T =
{T t } Tt =1 , where T denotes the total number of domains.
The t -th domain contains N T t data samples x but no labels y , i.e., T t = { x i ∥
x
i ∼ P T t X } N T t i =1 , and all the target domains share the same label space with the source domain.
Note that the domain order is randomly determined (including the source domain), which means that the superscript t does not always indicate the same domain.
The generalization performance for the t -th domain T t depends on both the previously seen t − 1 target domains and the original source domain, i.e., S = {S , ∪ t − 1 j =1 T j } .
Considering the possible limitation on memory storage and regulations on privacy (Guo et al., 2021) or intellectual property (Wang et al., 2021b), like regular continual learning (Dong et al., 2022a), we also set an exemplar memory M to store |M| t exemplars that are closest to the class centroids for each domain in S , where |M| t ≪ N T , |M| t ≪ N S .
Moreover, the memory size is set to be fixed during CDSL.
We assume that the model is a deep neural network, and without loss of generality, the neural network consists of a feature extractor f θ at the bottom and a classifier g ω at the top.
For each target domain dataset T t , in addition to the current model f t θ ◦ g tω , its inherited version f t − 1 θ ◦ g t − 1 ω from the last domain is also stored for later usage.
We aim to improve the generalization performance on a new target domain (TDG) before and during its training, i.e., in its Unfamiliar Period of CDSL, while also achieving effective target domain adaptation (TDA) and forgetting alleviation (FA).
2. R ANDOM M IXUP A UGMENTATION
At the beginning of CDSL, only a labeled source domain is available.
Thus we face a pure singedomain generalization problem where the model is trained on a single domain S and tested on the other unseen domains T (each domain in T is possible as the domain order is random).
We apply data augmentation and design a Random Mixup ( RandMix ) method to solve this problem.
RandMix is not only helpful to improve cross-domain transferability from S to T 1 , but also beneficial for remaining model’s order agnostic generalization when it encounters low-quality domains.
RandMix relies on N aug simple autoencoders R
= { R i } N aug i =1 , where each autoencoder consists of an encoder e ξ and a decoder d ζ .
We want RandMix to be as simple as possible, preferably to work without training.
Inspired by (Wang et al., 2021c), the encoder e ξ and the decoder d ζ are implemented as a convolutional layer and a transposed convolutional layer.
With such implementation, even if the parameters ξ and ζ are randomly initialized from a normalized distribution, the autoencoder can still generate reasonable augmentation data.
In order to introduce more randomness, we apply AdaIN (Karras et al., 2019) to inject noise into the autoencoder.
Specifically, the used AdaIN contains two linear layers l ϕ 1 , l ϕ 2 , and when l ϕ 1 and l ϕ 2 are fed with a certain noisy input drawn from a normalized distribution ( n ∼ P N (0 , 1) ), they can produce two corresponding noisy outputs with smaller variances.
As observed in our experiments (Section 3.1), blindly pushing augmentation data away from the original (Li et al., 2021; Wang et al., 2021c) possibly hurts the model generalization ability, and injecting randomness with a smaller variance is a better solution.
The two noisy outputs are injected to the representations of the autoencoder as multiplicative and additive noises:
[Equation]
where l IN ( · ) represents an element-wise normalization layer.
RandMix works as feeding training data to all autoencoders and mixing the outputs with random weights drawn from a normalized distribution ( w = { w i ∥
w i ∼ P N (0 , 1) } N aug i =0 ).
Finally, the mixture is scaled by a sigmoid function σ ( x )
= 1 / (1 + e − x ) :
[Equation]
In mini-batch training, every time there is a new data batch, parameters of autoencoders ( ξ , ζ ),
AdaIN-s ( ϕ 1 , ϕ 2 ), AdaIN noisy inputs ( n ) and mixup weights ( w ) are all initialized again.
With
RandMix , we can generate augmentation data with the same labels corresponding to all labeled samples from the source domain.
Then, these labeled augmentation samples will work together with the original source data and be fed into the model for training.
However, for the following continually arriving target domains, conducting RandMix on all target data is unreasonable.
In CDSL, all target domains T =
{T t } T t =1 are unlabeled.
While we can apply approaches to produce pseudo labels, the supervision is likely unreliable and inaccurate.
Therefore, to avoid error propagation and accumulation, we augment a subset of the target data rather than the full set.
Specifically, we determine whether a target sample is supposed to be augmented based on its prediction confidence:
[Equation]
where max[ · ] K denotes the maximum of a vector with K dimensions, and r con is a confidence threshold that is set to 0 .
8 (sensitivity analysis of r con is provided in Appendix).
2. T OP 2 P SEUDO L ABELING
In CDSL, all target domains arrive with only the data but no label.
Thus we need a pseudo labeling mechanism to provide reasonably accurate supervision for subsequent optimizations.
However, existing pseudo labeling approaches have various limitations.
For example, softmax-based pseudo labeling (Lee et al., 2013) produces hard labels for unlabeled samples, but training with such hard labels sacrifices inter-class distinguishability within the softmax predictions.
To preserve inter-class distinguishability, SHOT (Liang et al., 2020) proposes a clustering-based approach to align unlabeled samples with cluster centroids.
However, when the model is applied in a new domain, it is difficult to distinguish different classes since they are nearly overlapped together and the class boundary among them is extremely vague.
Besides, such clustering-based methods usually use all training samples to construct centroids for each class.
During clustering, for a particular cluster, samples that exactly belong to the same class are often not used well and those misclassified pose a negative impact on centroid construction.
In this case, such negative impact hurts the pseudo labeling accuracy by resulting in low-quality centroids.
To address these issues, we propose a novel mechanism called Top 2 Pseudo Labeling ( T2PL ).
Specifically, we use the softmax confidence to measure the possibility of correct classification for data samples, and select the top 50% set to construct class centroids:
[Equation]
where g ω,k ( · ) denotes the k -th element of the classifier outputs.
r top controls the size of the selected top set, and if the data is class balanced, top 50% corresponds to r top =2 .
Then the top set F is used to construct class centroids by a prediction-weighted aggregation on representations:
[Equation]
Subsequently, we can compute the cosine similarity between these centroids and representations of all current unlabeled data, and also select the top half set of samples that have much higher similarity to the centroids than the rest for each class:
[Equation]
Then we use F ′ to fit a k-Nearest Neighbor (kNN) classifier and assign the pseudo label as below.
Note that kNN can decentralize the risk of misclassification in assigning pseudo labels by a single comparison between class centroids and data samples, and is more suitable for clustering samples that are highly overlapped than center-based approaches:
[Equation]
where the superscript N T t r ′ top · K and subscript Euclidean mean that the kNN works to find N T t r ′ top · K closest neighbors from F ′ with the measurement of Euclidean distance.
We select the top 5% for each class ( r ′ top = 20 ) in our implementation (sensitivity analyses of r top and r ′ top are provided in the Appendix).
With this kNN, T2PL makes better use of unlabeled samples with a relatively high possibility of correct classification than SHOT, and provides more accurate pseudo labels.
2. P ROTOTYPE C ONTRASTIVE A LIGNMENT
Prototype learning (PL) (Pan et al., 2019; Kang et al., 2019; Tanwisuth et al., 2021; Dubey et al., 2021) has been demonstrated to be effective for solving cross-domain sample variability and sample insufficiency (Wang et al., 2021a).
These two issues are reflected in our problem as the random uncertainty of augmentation data and limited data quantity of seen domains in the exemplar memory M .
As a result, in this work, we adopt the idea of PL and propose a new Prototype Contrastive Alignment ( PCA ) algorithm to align domains together for improving model generalization ability.
First, we need to point out that regular PL is unsuitable to our problem.
In regular PL, all samples are fed into the model to extract representations, and these representations are aggregated class-byclass for constructing prototypes p t
= { p tk } Kk =1 of a certain domain T t .
To achieve cross-domain alignment, prototypes of different domains for the same classes are aggregated and averaged.
Then data samples from different domains are optimized to approach these domain-average prototypes.
However, such domain alignment has a problem of adaptivity gap (Dubey et al., 2021).
As shown in
Figure 2, we assume that there is an optimal prototype location p ∗ k of class k for all domains ( S ∪ T ), and the objective is to move the source prototype p sk to the optimal by training on target domains ( T ) one-by-one.
Meanwhile, we also regard that there are optimal prototypes p tk for each domain itself, and suppose that the regular PL is applied to align prototypes of all these domains.
To illustrate the problem of adaptivity gap, we take the alignment between the source S and the first target domain
T 1 as an example, and assume that the distance between p 1 k and p ∗ k is larger than the distance between p s k and p ∗ k .
In this case, after the domain alignment, the location of the current prototype [Figure] [Figure] is worse than the source prototype, which means that the adaptivity gap is enlarged.
Although we can use RandMix to generate more data ( ˜ p sk , ˜ p 1 k ) that might be helpful for reducing the adaptivity gap, there is randomness for each use of RandMix and we cannot guarantee such reduction every time (e.g., when the augmentation data is as ˜ p s ′ k and ˜ p 1 ′ k in Figure 2).
Therefore, a better prototype construction strategy is needed to provide more representative prototypes.
Inspired by a semi-supervised learning work (Saito et al., 2019)
we view neuron weights of the classifier ω as the prototypes.
The classifier g ω consists of a single linear layer and is placed exactly behind the feature extractor f θ .
Thus the dimension of its neuron weights is the same as the hidden dimension of extracted representations.
Prototypes p tk -s are obtained with a CrossEntropy Loss:
[Equation]
where b k , b c are biases of the linear layer, and we set them as zeros during training, and I ( · ) is an indicator function that if the subscript condition is true, I True =1 , otherwise, I False =0 ..
Compared with regular prototypes, such linear layer prototypes are built on a lot more data because RandMix is initialized and used for every mini-batch during model training.
Moreover, RandMix has general effect on improving generalization ability, as shown in our experiments later in Section 3.2.
Thus we believe that linear layer prototypes have smaller adaptivity gaps than regular ones.
With linear layer prototypes, we can align domains in a better way.
Unlike the alignment on regular prototypes, we do not sum up and average prototypes of different domains.
Instead, we simultaneously maximize the similarities of data samples to prototypes of different domains, although in practice we may have prototypes of just two domains since there is only one old model being stored (Section 2.1).
We also introduce contrastive comparison into the domain alignment process that can enhance the distinguishability of different classes and be beneficial for our pseudo labeling.
The contrastive comparison includes negative pairs of a particular sample and samples from other classes.
In this case, our prototype contrastive alignment is formulated as follows:
[Equation]
∆ (cid:41) , where
[Equation]
Furthermore, we also adopt knowledge distillation from the stored old model to the current model for forgetting compensation.
In this case, our final optimization objective is shown as follows:
[Equation]
Note that this optimization objective is used in all target domains.
As for the source domain, there is no distillation L DIS and the nominator of L PCA only contains the first term, because there is no stored old model in the stage of source training.
We denote this simplified optimization loss as L ′ .
E XPERIMENTS
Our code is available at https://github.com/SonyAI/RaTP.
The datasets, experiment settings, and comparison baselines are introduced below, and more details are in the appendix.
Datasets.
Digits consists of 5 different domains with 10 classes, including MNIST (MT), SVHN (SN), MNIST-M (MM), SYN-D (SD) and USPS (US).
PACS contains 4 domains with 7 classes, including Photo (P),
Art painting (A), Cartoon (C), and Sketch (S).
DomainNet is the most challenging cross-domain dataset, including Quickdraw (Qu), Clipart (Cl), Painting (Pa), Infograph (In), Sketch (Sk) and Real (Re).
Considering label noise and class imbalance, we follow Xie et al.
(2022) to split a subset of DomainNet for our experiments.
Experiment Settings.
We apply ResNet-50 as the feature extractor for both PACS and DomainNet, and apply DTN as the feature extractor for Digits (Liang et al., 2020).
In the source domain, we randomly split 80% data as the training set and the rest 20% as the testing set.
In target domains, all data are used for training and testing.
The SGD optimizer with an initial learning rate of 0.01 is used for Digits, and 0.005 for PACS and DomainNet.
The exemplar memory size is set as 200 for all datasets, and the batch size is 64.
For all experiments, we conduct multiple runs with three seeds (2022, 2023, 2024), and report the average performance.
Comparison Baselines.
RaTP is compared with a comprehensive set of state-of-the-art works from Continual DA [CoTTA (Wang et al., 2022), AuCID (Rostami, 2021)], Source-Free DA [SHOT (Liang et al., 2020), GSFDA
(Yang et al., 2021), BMD (Qu et al., 2022)], Test-Time/Online
DA [Tent (Wang et al., 2020), T3A (Iwasawa & Matsuo, 2021)], Single DG [L2D (Wang et al., 2021c), PDEN (Li et al., 2021)], Unified DA&DG [SNR (Jin et al., 2021)], and Multiple DG [PCL (Yao et al., 2022), EFDM (Zhang et al., 2022)].
[Table]
3. E FFECTIVENESS OF THE R A TP F RAMEWORK
We assume that each domain corresponds to a single training stage.
After the training of every stage, we test the model performance on all domains.
In this case, we can obtain an accuracy matrix, as shown in Figure 3.
Target domain generalization (TDG) is measured by the mean model performance on a domain before its training stage (mean of the green elements in Figure 3), target domain adaptation (TDA) by the performance on a domain right after finishing its training stage (the red element), and forgetting alleviation (FA) by the mean performance on a domain after the model has been updated with other domains (mean of the blue elements).
All these metrics are the higher, the better.
Due to space limitation, we report experiment results for Digits (Tables 1) and PACS (Table 2) in two domain orders, and for DomainNet (Table 3) in one domain order.
Results for more domain orders can be found in the Appendix.
We can observe that RaTP achieves significantly higher performance in TDG than all baselines in all cases, and comparable (and in many cases higher) performance in TDA and FA.
Specifically, RaTP significantly outperforms the secondbest baseline on TDG in all cases and by 3.1 ∼ 10.3% in average, and the performance improvement is particularly large over DA methods.
For TDA and FA, RaTP is also the best in most cases (and clearly outperforms the second best in many cases); and if not, very close to the best.
These results demonstrate that our method can effectively improve the model performance during the Unfamiliar
Period , adapt the model to different domains, and alleviate catastrophic forgetting on seen domains.
[Table]
3. A BLATION S TUDIES
To demonstrate the effectiveness of each module in RaTP , we conduct comprehensive ablation studies for RandMix , T2PL , and PCA on Digits with the domain order US → SD → SN → MM → MT.
Effectiveness of RandMix .
We first remove RandMix from RaTP and see how the model performance will change.
We also try to apply RandMix on a few other baselines, including SHOT (Liang et al., 2020), GSFDA (Yang et al., 2021), and PCL (Yao et al., 2022).
The experiment results in Figure 4(a) demonstrate that, removing RandMix from RaTP hurts the performance significantly
[Table]
and attaching RandMix to other baseline methods clearly improves the model performance. Such observations prove the effectiveness of RandMix .
[Table]
[Figure]
[Table]
[Figure]
Effectiveness of T2PL .
We replace T2PL in RaTP with other pseudo labeling approaches to investigate the gain from T2PL , including Softmax (Lee et al., 2013), SHOT (Liang et al., 2020), and BMD (Qu et al., 2022).
Figure 4(b) shows that RaTP performs the best when it has T2PL .
Effectiveness of PCA .
We first remove L PCA from the optimization objective, leaving only CrossEntropy Loss and Logits Distillation.
We then try to replace PCA with regular forwarding prototype learning (PL), supervised contrastive learning (SCL), and PCL (Yao et al., 2022).
Figure 4(c) shows that the performance of RaTP degrades significantly without L PCA , and when we use other methods instead, the performance is still worse.
This validates the effectiveness of PCA .
C ONCLUSION
This paper focuses on improving the model performance before and during the training of continually arriving domains, in what we call the Unfamiliar Period .
To solve this practical and important problem, we propose a novel framework RaTP that includes a training-free data augmentation module RandMix , a pseudo labeling mechanism T2PL , and a prototype contrastive alignment training algorithm PCA .
Extensive experiments demonstrate that RaTP can significantly improve the model performance in the Unfamiliar Period , while also achieving good performance in target domain adaptation and forgetting alleviation, in comparison with state-of-the-art methods from Continual DA, Source-Free DA, Test-Time/Online DA, Single DG, Multiple DG, and Unified DA&DG. A CKNOWLEDGEMENT
We gratefully acknowledge the support by Sony AI, National Science Foundation awards #2016240, #1834701, #1724341, #2038853, Office of Naval Research grant N00014-19-1-2496, and research awards from Meta and Google.
E THICS S TATEMENT
In this paper our studies are not related to human subjects, practices to data set releases, discrimination/bias/fairness concerns and also do not have legal compliance or research integrity issues.
Our work is proposed to address continual domain shifts when applying deep learning models in real-world applications.
In this case, if the trained models are used responsibly for good purposes, we believe that our proposed methods will not cause ethical issues or pose negative societal impacts
R EPRODUCIBILITY S TATEMENT
The source code is provided at https://github.com/SonyAI/RaTP.
All datasets we use are public.
In addition, we also provide detailed experiment parameters and random seeds in the Appendix.
S UMMARY OF THE A PPENDIX
This Appendix includes additional details for the ICLR 2023 paper “Deja Vu: Continual Model Generalization for Unseen Domains” , including related work comparison, more implementation details of main experiments, additional experiment results, and sensitivity analysis on parameters used in the framework.
The Appendix is organized as follows:
• Section A discusses the difference between RaTP and related works.
• Section B provides more implementation details, including detailed experiment settings, data splitting strategy, implementation details of the baseline methods, and network structures.
• Section C presents experiment results of additional domain orders on three datasets.
• Section D provides detailed sensitivity analysis of three parameters used in RaTP .
• Section E shows additional evaluations of RaTP in stationary domain adaptation.
A R ELATED W ORK C OMPARISON
Our work is relevant to a number of different topics as we focus on addressing important and practical problems.
We show a detailed comparison among these relevant topics in Table 4.
Specifically,
Fine-Tuning (Tajbakhsh et al., 2016) is usually conducted on a trained model with labeled target domain data.
It can achieve certain domain adaptation capabilities after sufficient training, but the forgetting of previously learned knowledge is often severe.
Continual Learning (Lopez-Paz & Ranzato, 2017; Rebuffi et al., 2017), which shares the same settings as Fine-Tuning, can effectively achieve alleviation of catastrophic forgetting.
To relax the demand for target labels, a series of domain adaptation (DA) methods are proposed.
Unsupervised DA (Ganin & Lempitsky, 2015; Dong et al., 2021; Zhu et al., 2021; Xu et al., 2021) can work effectively when the target data is unlabeled, but suffers from poor forgetting alleviation capability in continually changing cases. Continual
DA (Wang et al., 2022; Rostami, 2021; Tang et al., 2021) is able to compensate for the forgetting of learned knowledge, while achieving good domain adaptation, but it requires access to source data.
Source-Free DA (Yang et al., 2021;
Liang et al., 2020; 2021; Qu et al., 2022) is proposed to adapt the model to unlabeled target domains without the need for source data, but the model forgets a lot of learned knowledge during adaptation.
Test-Time DA (Wang et al., 2020; Iwasawa & Matsuo, 2021; Chen et al., 2022; Niu et al., 2022; Hong et al., 2023) does not need source data and target labels, and can achieve effective domain adaptation without heavy catastrophic forgetting on old knowledge.
However, all these DA methods cannot achieve effective target domain generalization on new domains before and during the training on them, which is the main focus of our work here.
Different from DA, Domain Generalization (DG), as another cross-domain learning paradigm, can improve model out-of-distribution generalization (Dong et al., 2022b; Hong et al., 2021) performance even without seeing target domains.
According to the composition of the given source domain, DG can be divided into two types, Single Source (Wang et al., 2021c; Li et al., 2021; Zhu & Li, 2022) and Multi-Source (Yao et al., 2022; Zhang et al., 2022).
Both these two DG-s require labeled source domain data, and can address target domain generalization before any adaptation on target domains.
However, they cannot achieve effective target domain adaptation and forgetting alleviation, which are important in continually changing scenarios.
Recently, there are some works (Jin et al., 2021) that try to unify DA and DG, but they require significant resources such as sourcelabeled data and target-labeled data.
Moreover, such Unified DA & DG also suffers from forgetting when being applied in continual learning settings.
Compared with these studies, our work focuses on improving model performance on new target domains before and during the training on them, in what we call the Unfamiliar Period in the main text, while also achieving effective target domain adaptation and forgetting alleviation.
To ensure the application practicability, we assume that there is only unlabeled data from target domains.
As shown in the main text, the proposed RaTP framework can effectively solve the problem we target under such assumptions.
B I MPLEMENTATION D ETAILS
Experiment Settings.
To classify the datasets, we apply ResNet-50 as the feature extractor for both
PACS and DomainNet
Liang et al.
(2020) use DTN as the feature extractor.
In source domain, we follow Wang & Lu to split 80% data as the training set and the rest 20% as the set. In all target domains, all data are used for training and testing. For each dataset, [Table]
we keep the training steps per epoch the same for all domains in all different domain orders.
We use 800 steps for Digits, 50 steps for PACS and 70 steps for DomainNet.
Training epoch is 30 for all datasets and domains.
The SGD optimizer with initial learning rate 0.01 is used for Digits and 0.005 for PACS and DomainNet.
Moreover, we use momentum of 0.9 and weight decay of 0. to schedule the SGD.
The exemplar memory is set as 200 for all datasets, and we set the batch size of mini-batch training as 64.
Only ResNet-50 is initialized as the pre-trained version of ImageNet.
Subset of DomainNet.
The original DomainNet is class imbalanced, with certain classes in some domains containing very few images ( ∼ 10).
This makes it hard to assign pseudo labels for these classes.
Thus, we refer to Xie et al.
(2022) to select the top 10 classes with most images in all domains, which contain 26,013 samples in total.
This dataset is still class imbalanced, with the smallest sample number for a class is 32, while the largest is 901.
Therefore, this subset is still quite challenging.
Baseline Implementations.
For fair comparison, we try our best to extend all baseline methods in our problem settings.
AuCID (Rostami, 2021) shares the most similar setting with us.
But their exemplar memory size is not limited and can be enlarged as more domains appear.
And they transform Digits to gray scale images while we treat them as RGB images.
For Test-Time/Online DA [CoTTA (Wang et al., 2022), Tent (Wang et al., 2020), T3A Iwasawa & Matsuo (2021), AdaCon (Chen et al., 2022), EATA (Niu et al., 2022)], we keep the setting that adapts the model on each target domain only once.
For Single DG [L2D (Wang et al., 2021c), PDEN (Li et al., 2021)] and Multiple DG [PCL (Yao et al., 2022), EFDM (Zhang et al., 2022)], we use SHOT (Liang et al., 2020) to assign pseudo labels for the optimization on target domains.
In EFDM, we use samples from current domain as the content images and randomly select images in the replay memory as the style images.
SNR (Jin et al., 2021) directly modifies the model structures to match statistics of different domains, thus it can be viewed as a unified approach for both DA and DG.
In our implementation, we use SNR to modify the convolution filters of the feature extractor and optimize the model with SHOT.
We also consider a more advanced version of SHOT for further comparison, i.e., SHOT++ (Liang et al., 2021), which equips an additional semi-supervised training step using MixMatch (Berthelot et al., 2019).
This may not be fair for other methods because all methods can in principle equip with this additional training step.
Thus, we also run SHOT++ without the MixMatch and denote it as SHOT+.
All baseline methods are equipped with the same exemplar memory and the same feature extractor.
Network Structures.
Our RandMix augmentation network includes four autoencoders that consist of a convolutional layer and a transposed convolutional layer.
All these layers have 3 channels and kernel sizes of 5, 9, 13, 17, respectively.
The classification model contains a feature extractor, a bottleneck module and a classifier.
Specifically, pre-trained ResNet-50 is used as the feature extractor for both PACS and DomainNet.
Following Liang et al.
(2020), DTN, a variant of LeNet is used as the feature extractor for Digits.
We also introduce a bottleneck module between the feature extractor and the classifier.
The bottleneck consists of a fully-connected layer (256 units for Digits and 512 units for both PACS and DomainNet), a Batch Normalization layer, a ReLU layer and another fully-connected layer (128 units for Digits, 256 units for PACS, and 512 units for DomainNet).
The classifier is a fully-connected layer without the parameters of bias.
Both contrastive loss and distillation loss are applied to the representations after the bottleneck.
C A DDITIONAL E XPERIMENT R ESULTS
Following existing studies of continual domain shifts (Rostami, 2021; Wang et al., 2022; Tang et al., 2021), we have presented experiment results under the most popular domain orders in the main text.
To further explore the impact of domain order, which is rarely studied by existing works, we conduct more experiments with additional domain orders for the three datasets.
Specifically, for each dataset, we carry out experiments under 10 different domain orders that are randomly shuffled, shown in Table 5.
We present the average performance for all orders in Table 6 (Digits), Table(PACS), Table 8 (DomainNet).
Note that for the average performance in Tables 6, 7 and 8, we select a subset of the baseline methods that perform relatively better than the rest, including a few additional baselines (i.e., SHOT+ (Liang et al., 2021), SHOT++ (Liang et al., 2021), AdaCon (Chen et al., 2022), EATA (Niu et al., 2022), L2D (Wang et al., 2021c), and PDEN (Li et al., 2021)), to carry out experiments for saving time and space.
Under these additional domain orders, RaTP still achieves the best average TDG on all three datasets, and comparable (and in many cases better) performance in TDA and FA.
Combining these results with the ones shown in the main text, we can clearly see that RaTP provides significant improvement on TDG over previous state-of-the-art methods, while achieving comparable performance in TDA and FA.
The results are reported in Tables 6, 7, and 8 for the average performance of all orders.
[Table]
D S ENSITIVITY A NALYSIS
We conduct sensitive analysis of the confidence threshold r con in splitting RandMix
[Table]
and r top and r ′ top in T2PL .
All sensitive analysis experiments are conducted on Digits with the domain order of US → SD → SN → MM → MT.
For splitting RandMix , r con controls the proportion of unlabeled data that needs to be augmented.
As shown in Figure 5(a)
[Table]
different r con -s correspond to different model performance
[Table]
and we can obtain the best performance when r con = 0 .
8 , which is adopted for Digits and DomainNet.
And r con is set as 0.5 for PACS.
As for the sensitivity analysis of the other two parameters, according to the results shown in Figures 5(b) and 5(c), we can observe that a larger r top that corresponds to a smaller amount of fitting samples is detrimental to the model performance, while a larger r ′ top that corresponds to fewer nearest samples for the kNN classification leads to slightly better performance.
We choose r top = 2 and r ′ top = 20 for Digits and PACS, r top = 1 and r ′ top = 10 for DomainNet.
E E VALUATIONS ON S TATIONARY D OMAIN A DAPTATION
While our work primarily focuses on continual domain shift, here we provide results of stationary domain adaptation for further comparison. In this setting, we consider the combination of one single source domain and one single target domain, and consider the generalization performance on the target domain accuracy after adaptation.
In such situation, we remove the replay memory, the distillation loss term (Eq. 10) and the second term in the nominator of L PCA (Eq. 9), as they force the model to achieve forgetting alleviation for previous domains and may impede the adaptation to the target domain. We conduct our stationary domain adaptation in PACS, and the results after adaptation are shown in Tables 9 Compared with other baselines, RaTP performs the best in most cases and achieves 4.4% higher average accuracy than the second best.
[Table]
Order91.
Order
[Table]
[Table]
[Table]
Order73. Order79.
[Table]
[Table]
[Table] [Table] Order [Table]
[Table] [Table] [Table] [Table]
[Table]
[Table]
[Table] Order [Table] [Table]
[Table] [Table] [Table] [Table]
[Table]
[Table]
[Table] Order [Table] [Table]
[Table]
[Table]
[Table]
[Table]
[Table]
[Table] Order [Table] [Table]
[Table] [Table] [Table] [Table]
[Table] Order [Table] [Table]
[Table] [Table] [Table] [Table]
Avg
[Table]
[Table]
[Table]
[Table]
[Table]
[Table]
[Table]
FA
Order [Table] [Table] [Table]
[Table]
[Table]
[Table]
[Table]
Order
[Table]
[Table]
[Table]
[Table]
[Table]
[Table]
[Table]
[Table]
Order
[Table]
[Table]
[Table]
[Table]
[Table]
[Table]
[Table]
Order
[Table]
[Table]
[Table]
[Table]
[Table] [Table] [Table] [Table]
Order [Table] [Table]
Order59. Order62.
Order57.
Order25.
Order39.
Avg.
[Figure]
[Table]
Order87. Order88.
Order89.
Order85. Order83.
Order66. Order64.
Order91.
Order75.
Avg.
FA
Order73. Order72.
Order81.
Order76.
Order82. Order79.
Order65.
Order58.
Order86.
Order72.
Avg.
[Table]
Order69.
Order72.
Order51.
Order68. Order63.
Order47.
Order72.
Order74. Order71.
Avg.
FA
Order61.
Order64.
Order62.
Order42.
Order60.
[Table]
[Table]
EATA
[Table]