---
title: "Dynamic Domain Generalization"
authors:
  - "Zhishu Sun"
  - "Zhifeng Shen"
  - "Luojun Lin"
  - "Yuanlong Yu"
  - "Zhifeng Yang"
  - "Shicai Yang"
  - "Weijie Chen"
doi: "10.24963/ijcai.2022/187"
url: "https://ijcai.org/proceedings/2022/187"
pdf: "https://ijcai.org/proceedings/2022/0187.pdf"
venue: "Proceedings of the Thirty-First International Joint Conference on Artificial Intelligence"
year: 2022
pages: "1342-1348"
track: "Main Track"
keywords:
  - "Computer Vision: Transfer, low-shot, semi- and un- supervised learning"
---

# Dynamic Domain Generalization

Zhishu Sun, Zhifeng Shen, Luojun Lin, Yuanlong Yu, Zhifeng Yang, Shicai Yang, Weijie Chen

*Proceedings of the Thirty-First International Joint Conference on Artificial Intelligence*, pages 1342-1348. DOI: [10.24963/ijcai.2022/187](https://doi.org/10.24963/ijcai.2022/187)

## Abstract

Domain generalization (DG) is a fundamental yet very challenging research topic in machine learning. The existing arts mainly focus on learning domain-invariant features with limited source domains in a static model. Unfortunately, there is a lack of training-free mechanism to adjust the model when generalized to the agnostic target domains. To tackle this problem, we develop a brand-new DG variant, namely Dynamic Domain Generalization (DDG), in which the model learns to twist the network parameters to adapt to the data from different domains. Specifically, we leverage a meta-adjuster to twist the network parameters based on the static model with respect to different data from different domains. In this way, the static model is optimized to learn domain-shared features, while the meta-adjuster is designed to learn domain-specific features. To enable this process, DomainMix is exploited to simulate data from diverse domains during teaching the meta-adjuster to adapt to the agnostic target domains. This learning mechanism urges the model to generalize to different agnostic target domains via adjusting the model without training. Extensive experiments demonstrate the effectiveness of our proposed method. Code is available: https://github.com/MetaVisionLab/DDG

## Full text

## 1 Introduction

Deep neural networks have achieved great success on various vision tasks, such as image recognition and object detection [He et al., 2016]. Most of deep models are learnt in a closed perception environment where training and testing data are supposed under i.i.d (independent and identical distribution) assumption. However, the reality is open, compound, uncontrolled and incompatible with i.i.d assumption. Such complex scenarios can make conventional models suffer tremendous performance degradation, due to the absence of generalization ability to handle domain shift, which undoubtedly will discount the reliability and security of intelligent systems, e.g., autonomous driving system.

† Corresponding authors: Luojun Lin and Yuanlong Yu

Figure 1: Comparison among DA, DG, Test-time DG and DDG methods. DA and test-time DG are able to adjust the model when encountering novel target domains via fine-tuning, while DG freezes a static model to adapt to any agnostic target domain. Different from the existing methods, DDG is able to adjust the model without any training effort for better domain generalization.

![Image](https://ijcai.org/proceedings/2022/fulltext/187/image_000000_700e58d3807f64066e62f3003dff9c5dba0cb336461af4edcbb59ba6523b60e2.png)

Extensive studies aim to tackle this problem through domain generalization (DG), whose objective is to obtain a robust static model by learning domain-invariant representations via exploiting multiple source domains [Ganin and Lempitsky, 2015; Zhou et al., 2021]. Nevertheless, a severe bottleneck from the static model constrains its freedom to generalize to agnostic target domains with different distribution. In contrast, domain adaptation (DA) [Ganin et al., 2016] and test-time DG [Iwasawa and Matsuo, 2021] are explored to leverage the unlabeled data sampled from the target domain for further unsupervised fine-tuning so as to enhance the target-oriented generalization ability. However, extra training effort and latency are required during testing, while the manufactured chips and edge devices mostly do not possess training resources. Considering these two perspectives, there is a lack of training-free mechanism to adjust the model when encountering the testing data from novel target domains.

To complement this blank, we propose a new DG variant, Dynamic Domain Generalization (DDG). As shown in Figure 1, different from DA, DG, as well as test-time DG methods, the proposed DDG is attached with a meta-adjuster, which learns to adapt to novel domains during pre-training and twists the model during testing without any fine-tuning. To drive the process of learning to adapt, we need to collect training data from numerous novel domains, while the reality is that we are usually hindered by limited source domains. A simple yet friendly solution is that we simulate novel samples from the limited source domains via a random convex interpolation among different source domains, which is termed as DomainMix in this paper. In this way, each simulated sample is restricted to a unique domain. As a consequence, the domain-aware meta-adjuster can be relaxed into an instanceaware meta-adjuster, which modulates the network parameters per instance. Besides, it makes the model easier adapt from source domains to agnostic target domains with undefinable domain distinction, by discarding the utilization of domain label during optimizing meta-adjuster.

Beyond the optimization pipeline of DDG, it is also a critical factor on how to design the meta-adjuster. In order to disentangle the domain-shared features and domain-specific features, the network parameters are decoupled into a static part and a dynamic part where the latter one is generated by the meta-adjuster per instance. To ease the optimization of meta-adjuster, the dynamic parameters are decomposed into a linear combination of several elaborately-designed kernel templates with low-dimensional dynamic coefficients, in which the coefficients are generated dynamically by the metaadjuster via taking the instance embedding as input. As shown in Figure 3, the kernel templates are designed as four asymmetric kernels for the sake of strengthening the kernel skeletons in spatial as well as channel dimensions, which explicitly regularize the meta-adjuster to generate diverse dynamic parameters to adapt to a large variety of novel samples.

Extensive experiments are conducted on three popular DG benchmarks, including PACS [Li et al., 2017], Office-Home [Venkateswara et al., 2017] and DomainNet [Peng et al., 2019]. These datasets contain various situations varying from small to large scales, from simple to complex scenarios, from small to large domain shifts, which are sufficient to demonstrate the effectiveness of our proposed method. To summarize, DDG opens up a new paradigm to study DG problem.

## 2 RelatedWork

DomainAdaptation. Conventional DA aims to transfer the knowledge learnt from labeled source domains to target domains which may contain a few labeled samples or none at all. The discrepancy-based methods are early developed, which mitigate the distribution discrepancy between two domains by minimizing the well-defined distance loss [Haeusser et al., 2017]. Another line of DA methods is based on adversarial learning, where a domain discriminator is frequently-used to train with the feature extractor adversarially, in order to enforce the feature extractor to learn domain-invariant features by confusing the domain discriminator [Ganin et al., 2016]. Compared with DA methods that adjust models to adapt to target domains explicitly, our method can be viewed as a kind of training-free DA via pre-training merely in source domains.

Domain Generalization. Early DG-related research focus on learning domain-invariant representation, which is believed to be robust if it can suppress domain shift among multiple source domains [Motiian et al., 2017]. Another line of DG methods is based on data augmentation that enhances the diversity of image styles for optimizing the generalization capability of models [Zhou et al., 2020a; Zhou et al., 2021]. Self-supervised learning is also applied to DG that learns task-independent representation with less probability of over-fitting [Carlucci et al., 2019; Kim et al., 2021]. Metalearning is also involved with solving DG [Balaji et al., 2018], where deep model is trained by simulating the meta-train and meta-test tasks in source domains to enhance its generalization ability. Our method can be regarded as a very simple meta-learning-like paradigm, in which meta-adjuster learns to learn parameter generalization for each individual "domain". Besides, a few emerging works show a new insight for DG that deep model can be adapted to target domain at test time [Iwasawa and Matsuo, 2021]. However, the computational cost is inescapable in such methods. In contrast, our method can directly update parameters to adapt to agnostic target domain without any backward propagation.

## 3 Methods

## 3.1 Overview

DG aims to train a general model that can be well generalized to any agnostic target domain. In particular, we only consider K-way classification task in this paper. For a vanilla DG task, we are given ns labeled samples {xis , yis , dis }ns i=1 drawn from multi-source domains XS = {XS1 ,XS2 , ...,XSM }, where xis ∈ XS, yis ∈ YS and domain label dis ∈ [1,M]. The objective of DG is to learn a mapping fΘ : {XS1 , ..., XSM } → YS that can also predict precisely on any agnostic target domain.

Vanilla Domain Generalization. For vanilla DG, the learnt mapping fΘ obtained in training stage will be kept static in inference. It usually causes the performance degradation on agnostic target domains due to the inevitable data distribution distinction between the source and target domains.

DynamicDomainGeneralization. To overcome theweakness of vanilla DG, we propose a new variant of DG, namely Dynamic Domain Generalization (DDG). DDG mainly focuses on learning to twist the network parameters to adapt to the instances from diverse novel domains. In this paper, each instance is assumed to be an independent latent domain. Under this assumption, the model parameters Θ can be modeled as a function of input instance x: Θ = Θ(x). To this end, a meta-adjuster is designed to generate network parameters to achieve diverse networks so as to adapt to diverse novel samples. In this case, the mapping fΘ(x) is more likely Train Time to align different instances into the same feature space under the reflection of instance-aware parameters Θ(x). Compared with the static mapping that is difficult to align instances from different data distributions, DDG is easier to achieve feature alignment among diverse novel domains.

Figure 2: Pipeline of the proposed DDG method. In the training phase, two stages are required, namely novel samples simulation and learning to adjust, which aims to teach the meta-adjuster to adapt to novel samples. In the testing phase, the network can be adjusted without training when encountering agnostic target domain.

![Image](https://ijcai.org/proceedings/2022/fulltext/187/image_000001_ac75391b1b28df2d491ee380f56f86e18975f8d66ba3885d4c639627eb1be866.png)

The pipeline of our method is illustrated in Figure 2, where DDG framework is composed of a static component and a dynamic component updated by the meta-adjuster based on each input instance. The former one is responsible to learn domain-shared features while the latter one is designed to learn domain-specific features. In order to teach the metaadjuster to adapt to diverse novel domains, we simulate numerous novel training samples via a random convex interpolation among the limited source domains.

## 3.2 Novel Samples Simulation

Numerous novel samples are required to drive the optimization of learning to adjust. By exploiting the limited source domains, we develop a DomainMix method from MixUp [Zhang et al., 2018] to synthesize novel domains with diverse styles. Given two instances (xis , yis ) and (xjs , yjs ) randomly sampled from two different source domains, the process of novel samples simulation is formulated as:

<!-- formula-not-decoded -->

Figure 3: Structure illustration of the basic block for DDG, which contains a static and a dynamic component. The latter one is a learnable linear combination of four asymmetric kernel templates and corresponding dynamic coefficients which are generated by the meta-adjuster. For simplicity, Cout is omitted.

![Image](https://ijcai.org/proceedings/2022/fulltext/187/image_000002_1f6bfc4ec59c7e0251eee957a20a80c448b6ae77b2ef06870d64ec5ac09c83f5.png)

where α is randomly sampled from Beta distribution in each feed-forward. Each DomainMix sample (¯xis , ¯ yis ) can be viewed as an unique domain and be harnessed to drive the following process of learning to adjust.

## 3.3 Learn to Adjust

In this section, we decouple the network parameters into a static part and a dynamic part which implicitly disentangles the domain-shared and domain-specific features. Here the dynamic parameters are generated by a shallow generator, termed as meta-adjuster, by taking the instance embedding as input. For a better illustration, we take one of the most popular convolutional neural networks, namely ResNet [He et al., 2016], as the backbone of our dynamic network. As shown in Figure 3, the meta-adjuster is embedded in each middle convolution layer in the residual block (note that each residual block is composed by a sequential of 1 × 1, 3 × 3 and 1 × 1 convolution layers). In the following, we will introduce how to design meta-adjuster effectively.

Meta-Adjuster. Meta-adjuster takes the instance embedding Fin(x) (i.e., the output of last block) as input, so that the meta-adjuster practically can be considered as the function of input instance ∆Θ(x). Therefore, the network parameters adjusting process can be formulated as:

<!-- formula-not-decoded -->

where Θs and Θ(x) represent the static parameters and its corresponding up-to-date parameters, and ∆Θ(x) denotes their dynamic term. Theoretically, the dynamic term∆Θ(x) should be the same dimension with the static parameters Θs. However, it makes the amount of network parameters grow quadratically and then apparently increases the risk of overfitting. Thus, according to matrix factorization, we propose to decompose the dynamic term into a learnable linear combination of several kernel templates {V n}Nn=1 which can be formulated as:

<!-- formula-not-decoded -->

where N is a hyper-parameter that represents the number of kernel templates. {λn(x)}Nn=1 denotes the set of dynamic coefficients, which is a group of instance-aware scalars generated by a learnable shallow meta-adjuster λ(·) via taking instance x (practically the instance embedding Fin(x)) as input. In this way, the dynamic component are restricted into a limited space, which benefits the optimization of whole model.

Asymmetric Kernel Templates. An apparent side effect to decompose meta-adjuster into a linear combination of kernel templates and a few dynamic coefficients is that the modulation brought by dynamic parameters are prone to be tiny and rigid. To avoid this tendency, we design four asymmetric kernel templates to explore the relationship between dynamic parameters from different dimensions, as well as to enforce the meta-adjuster to generate more diverse dynamic parameters for a large variety of novel samples. Another discovery is that the learned knowledge of convolutional kernels is not distributed uniformly, since the skeleton of kernels (i.e. the central criss-cross positions) usually has larger weight values [Ding et al., 2019]. For this reason, we propose to enhance the skeleton of kernels by generating skeleton-based dynamic parameters that is derived from a linear combination of these asymmetric skeleton-based kernel templates.

Suppose that the dimension of static kernels Θs is denoted as cin × cout × k × k, where k, cin and cout represent the kernel size, the input channel number as well as the output channel number. As shown in Figure 3, the asymmetric skeleton-based kernel templates are designed as four matrices with different shapes as cin × 1 × k × k, cin × cout × 1 × 1, cin × cout × k × 1 and cin × cout × 1 × k, respectively. Note that the kernel template with size of cin×1×k×k are implemented as depth-wise convolution, because it merely focuses on spatial relationship. In this way, the dynamic parameters are encouraged to be varied for different input samples. In addition, the skeleton of network parameters can be amplified in spatial as well as channel dimensions.

## 4 Experiments

## 4.1 Datasets and Experimental Setup

Datasets. 1) PACS [Li et al., 2017] contains more than 9k images with seven categories collected from four domains, which includes: Photo, Sketch, Cartoon and Art Painting. 2) Office-Home [Venkateswara et al., 2017] contains 15, 500 images with 65 categories with a few images per category. All images are sampled from four domains, including: Art, Clipart, Product and Real-World. 3) DomainNet [Peng et al., 2019] is a large-scale benchmark containing 600k images with 345 categories. The images are collected from six different domains which are Clipart, Inforgraph, Painting, Quickdraw, Real and Sketch.

Experimental Setup. For each dataset, we conduct leaveone-out strategy that randomly selects one domain for evaluation and leaves the remaining ones as source domains for training. Each experiment is repeated three times with different random seeds, and the mean and variance of these results are reported in this paper.

## 4.2 Implementation Details

All the experiments are conducted on RTX 3090 GPU with PyTorch 1.10.0. We use ResNet-50 as the backbone of our dynamic network, by attaching the meta-adjusters to the original residual blocks (as shown in Figure 3), where the spatial size of kernel templates is set as k = 3. Note that in each block, the meta-adjuster is implemented by a sequential of a global average pooling layer, a ReLU layer sandwiched between two fully-connected layers, and a SoftMax layer to output instance-aware coefficients.

Before training DG tasks, we pre-train our network on ImageNet so as to compare with the existing works fairly. Then, we train DG tasks by fine-tuning the pre-trained model with SGD. The training objective is a cross-entropy loss function, exactly the same with vanilla DG. The asymmetric kernel templates and meta-adjuster are optimized with the main backbone simultaneously during training. For PACS and Office-Home, the network optimization is set with batch size of 64, training epochs of 50, and the initial learning rate of 1e-3 decayed by cosine scheduler. While training on DomainNet, most of the hyper-parameters keep the same with that of PACS, except that the initial learning rate and max epoch are 2e-3 and 15, and the mini-batches are fetched with random domain sampler strategy [Zhou et al., 2021], in order to ensure that each domain is uniformly sampled.

## 4.3 Comparisons with the State-of-the-Art

We compare our method with the state-of-the-art methods on PACS, Office-Home and DomainNet datasets, where the results are reported in Table 1, Table 2 and Table 3, respectively. From these tables, we can observe that:

- 1) Our method achieves an average accuracy of 86.21, 72.13 and 46.89 percent on PACS, Office-Home and DomainNet benchmark datasets, respectively. Compared to other DG methods, our method achieves the state-of-the-art results on most of DG benchmarks, which shows the superiority of our DDG.
- 2) Our method is flexible to combine with other methods to further improve the performance. Taking Mixstyle [Zhou et al., 2021] as an example, the performance of our model can be further improved if we insert MixStyle layers into our model. The results can reach 87.87, 72.31 and 46.93 percent on PACS, Office-Home and DomainNet benchmarks, respectively. It shows that our method is rather robust even on the very strong baselines, i.e. MixStyle.

## 4.4 Ablation Studies

We conduct ablation studies on PACS dataset to evaluate the effectiveness of asymmetric kernel templates and DomainMix respectively, where the results are shown in Table 4.

Effectiveness of Asymmetric Kernel Templates. We study the effectiveness of asymmetric design of kernel templates, by employing common kernel templates that consists of four identical kernels with spatial dimensions of 1 × 1 or 3 × 3. Besides, we also compare with a channel-wise attention method, namely SENet [Hu et al., 2018], which is also a popular and powerful architecture in CNN community. As shown in Table 4, we can see that:

Table 1: Results on PACS dataset. The best and second-best results are bold and underlined, respectively.

| Method                                                                                                                                                                                                                                                                                       | Art Painting                                                                                   | Cartoon                                                                                        | Photo                                                                                          | Sketch                                                                                         | Avg.                                                        |
|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------|-------------------------------------------------------------|
| D-SAM [D'Innocente and Caputo, 2018] CSD [Piratla et al., 2020] Epi-FCR [Li et al., 2019] MASF [Dou et al., 2019] DDAIG [Zhou et al., 2020a] MetaReg [Balaji et al., 2018] MixStyle [Zhou et al., 2021] ERM [Gulrajani and Lopez-Paz, 2021] RSC [Huang et al., 2020] SWAD [Cha et al., 2021] | 77.33 78.90±1.10 82.10 82.89±0.16 84.20±0.30 87.20±0.13 84.10±0.40 88.10±0.10 87.89 89.30±0.20 | 72.43 75.80±1.00 77.00 80.49±0.21 78.10±0.60 79.20±0.27 78.80±0.40 77.90±1.30 82.16 83.40±0.60 | 95.30 94.10±0.20 93.90 95.01±0.10 95.30±0.40 97.60±0.31 96.10±0.30 97.80±0.00 83.35 97.30±0.30 | 77.83 76.70±1.20 73.00 72.29±0.15 74.70±0.80 70.30±0.18 75.90±0.90 79.10±0.90 97.92 82.50±0.50 | 80.72 81.40 81.50 82.67 83.10 83.60 83.70 85.70 87.83 88.10 |
| Ours Ours w/ MixStyle                                                                                                                                                                                                                                                                        | 85.92±0.17 87.14±0.21                                                                          | 79.68±0.42 82.66±0.33                                                                          | 96.65±0.15 97.77±0.06                                                                          | 82.62±0.27 83.89±0.14                                                                          | 86.21 87.87                                                 |

Table 2: Results on Office-Home dataset. The best and second-best results are bold and underlined, respectively.

| Method                               | Art        | Clipart    | Product    | Real-World   |   Avg. |
|--------------------------------------|------------|------------|------------|--------------|--------|
| D-SAM [D'Innocente and Caputo, 2018] | 58.03      | 44.37      | 69.22      | 71.45        |  60.77 |
| JiGen [Carlucci et al., 2019]        | 53.04      | 47.51      | 71.47      | 72.79        |  61.20 |
| L2A-OT [Zhou et al., 2020b]          | 60.60      | 50.10      | 74.80      | 77.00        |  62.60 |
| RSC [Huang et al., 2020]             | 58.42      | 47.90      | 71.63      | 74.54        |  63.12 |
| DDAIG [Zhou et al., 2020a]           | 59.20±0.10 | 52.30±0.30 | 74.60±0.30 | 76.00±0.10   |  65.50 |
| MixStyle [Zhou et al., 2021]         | 58.70±0.30 | 53.40±0.20 | 74.20±0.10 | 75.90±0.10   |  65.50 |
| ERM [Gulrajani and Lopez-Paz, 2021]  | 62.70±1.10 | 53.40±0.60 | 76.50±0.40 | 77.30±0.30   |  67.50 |
| SWAD [Cha et al., 2021]              | 66.10±0.40 | 57.70±0.40 | 78.40±0.10 | 80.20±0.20   |  70.60 |
| Ours                                 | 69.39±0.07 | 57.15±0.17 | 80.20±0.19 | 81.79±0.07   |  72.13 |
| Ours w/ MixStyle                     | 69.43±0.19 | 59.40±0.36 | 78.56±0.16 | 81.85±0.11   |  72.31 |

Table 3: Results on DomainNet dataset. The best and second-best results are bold and underlined, respectively. +: The results are reimplemented and reported by ERM [Gulrajani and Lopez-Paz, 2021]

| Method                               | Clipart    | Infograph   | Painting   | Quickdraw   | Real       | Sketch     |   Avg. |
|--------------------------------------|------------|-------------|------------|-------------|------------|------------|--------|
| C-DANN [Li et al., 2018b]+           | 54.60±0.40 | 17.30±0.10  | 43.70±0.90 | 12.10±0.70  | 56.20±0.40 | 45.90±0.50 |  38.30 |
| RSC [Huang et al., 2020]+            | 55.00±1.20 | 18.30±0.50  | 44.40±0.60 | 12.20±0.20  | 55.70±0.70 | 47.80±0.90 |  38.90 |
| Mixup [Zhang et al., 2018]+          | 55.70±0.30 | 18.50±0.50  | 44.30±0.50 | 12.50±0.40  | 55.80±0.30 | 48.20±0.50 |  39.20 |
| SagNet [Nam et al., 2021]+           | 57.70±0.30 | 19.00±0.20  | 45.30±0.30 | 12.70±0.50  | 58.10±0.50 | 48.80±0.20 |  40.30 |
| MLDG [Li et al., 2018a]+             | 59.10±0.20 | 19.10±0.30  | 45.80±0.70 | 13.40±0.30  | 59.60±0.20 | 50.20±0.40 |  41.20 |
| ERM [Gulrajani and Lopez-Paz, 2021]+ | 58.10±0.30 | 18.80±0.30  | 46.70±0.30 | 12.20±0.40  | 59.60±0.10 | 49.8±0.40  |  40.90 |
| MetaReg [Balaji et al., 2018]        | 59.77      | 25.58       | 50.19      | 11.52       | 64.56      | 50.09      |  43.62 |
| DMG [Chattopadhyay et al., 2020]     | 65.24      | 22.15       | 50.03      | 15.68       | 59.63      | 49.02      |  43.63 |
| SelfReg [Kim et al., 2021]           | 62.40±0.10 | 22.60±0.10  | 51.80±0.10 | 14.30±0.10  | 62.50±0.20 | 53.80±0.30 |  44.60 |
| SWAD [Cha et al., 2021]              | 66.00±0.10 | 22.40±0.30  | 53.50±0:10 | 16.10±0.20  | 65.80±0.40 | 55.50±0.30 |  46.50 |
| Ours                                 | 68.07±0.08 | 25.02±0.18  | 53.54±0.37 | 13.74±0.10  | 67.39±0.02 | 53.59±0.06 |  46.89 |
| Ours w/ MixStyle                     | 67.39±0.05 | 24.21±0.08  | 53.59±0.32 | 16.21±0.05  | 65.85±0.12 | 54.34±0.27 |  46.93 |

- 1) Our method achieves superior performance to the vanilla ResNet and SENet by a large margin, which suggests the effectiveness of meta-adjusters on DG tasks.
- 2) The result of asymmetric kernel templates is obviously better than that of four identical 1×1 kernel templates and 3×3 kernel templates, which confirms the effectiveness of the asymmetric design of kernel templates. In-depth analysis of asymmetric kernel templates will be introduced in the visualization section.

Effectiveness of Novel Sample Simulation. In order to verify the effectiveness of the novel sample simulation method, we also conduct ablation studies on DomainMix. Instead of using DomainMix, we train the networks with limited source domains. Table 4 shows the comparison results, from which we can observe that our method suffers obvious performance degradation when training without DomainMix strategy. This result demonstrates the importance of novel sample simulation in teaching the meta-adjuster to adapt novel samples from agnostic target domains.

## 4.5 Visualization

For a better understanding of our method, we visualize the kernel templates and dynamic coefficients in different ways. Note that we use the model trained on the multi-source domains (i.e., Art Painting, Cartoon and Sketch) of PACS.

Visualization of Asymmetric Kernel Templates. In order to further explore the mechanism of asymmetric kernel templates, we have a comparison between static kernels in vanilla ResNet and dynamic kernels in our dynamic network, by the means of visualizing kernel magnitude matrix following the literature [Ding et al., 2019]. For ResNet, we sum up the

Table 4: Results of ablation studies in terms of asymmetric kernel templates and DomainMix on PACS dataset.

| Method                        | Art Painting   | Cartoon    | Photo      | Sketch     |   Avg. | #Params   |
|-------------------------------|----------------|------------|------------|------------|--------|-----------|
| ResNet [He et al., 2016]      | 84.99±0.25     | 77.64±0.42 | 97.54±0.19 | 71.63±0.41 |  82.95 | 22.43M    |
| SENet [Hu et al., 2018]       | 82.08±0.36     | 80.70±0.50 | 96.89±0.21 | 75.97±1.84 |  83.91 | 24.83M    |
| Ours w/ 1× 1 kernel templates | 81.95±0.96     | 78.20±1.86 | 97.50±0.31 | 78.45±0.34 |  84.03 | 28.17M    |
| Ours w/ 3× 3 kernel templates | 81.10±0.66     | 78.32±0.71 | 97.64±0.27 | 77.70±1.90 |  83.69 | 66.56M    |
| Ours                          | 85.92±0.17     | 79.68±0.42 | 96.65±0.15 | 82.62±0.27 |  86.21 | 31.81M    |
| Ours w/o DominMix             | 81.18±0.33     | 80.18±0.73 | 97.35±0.10 | 78.78±1.11 |  84.37 | 31.81M    |

Figure 4: Comparison among static kernel of vanilla ResNet, and dynamic kernel of our network in terms of parameter magnitude. The kernels in sub-figures are acquired by averaging all the kernels, and being normalized in layer dimension.

![Image](https://ijcai.org/proceedings/2022/fulltext/187/image_000003_8a0f0e097879c5bcf727f534b398f093fd0c86e19ae3d089a587216086918582.png)

3 × 3 kernels along the channel and layer dimensions to obtain a 3 × 3 kernel magnitude matrix. For dynamic network, we randomly select an image from validation set to feed into the model and aggregate all the kernel templates with corresponding dynamic coefficients, summing up along the channel and layer dimensions. The comparison result is shown in Figure 4, from which we can see that:

- 1) The central criss-cross positions have larger values than the corners of kernel, no matter whether static network or dynamic network. It confirms the kernel skeletons are more crucial than the corners when learning knowledge.
- 2) The kernel skeletons are further strengthened in dynamic network (as shown in Figure 4(b)). The reason is that the design of dynamic combination among kernel templates can adjust or enlarge the weights of kernel skeletons in instance-aware manner. Consequently, it can promote the model for learning advanced knowledge, which further improves training-free adaptation ability in inference.

t-SNE Visualization of Dynamic Coefficients and Features. In order to investigate the effect of dynamic network on different distribution data, we select a few blocks to visualize corresponding dynamic coefficients and the features. Figure 5(a)-(e) show the distributions of dynamic coefficients from different blocks of our model, by taking the whole dataset as input, including source (i.e., Art Painting, Cartoon, and Sketch) and target domains (i.e., Photo). We can observe that the dynamic coefficients tend to separate based on domains, and this phenomenon is decelerated from shallow to deep layers. It proves that the instance-aware coefficients are domain-aware practically, even without the explicit supervision of domain labels. Thus, the domain-aware coefficients can realize domain alignment in feature space, as shown in Figure 5(f). It stresses the superiority of dynamic coefficients on learning domain-invariant features for DG tasks.

Figure 5: (a)-(e): t-SNE visualization of dynamic coefficients for samples from different domains, where we use colors to distinguish domains. Coefficients of Block #a denotes the dynamic coefficients from the ath block. (f): t-SNE visualization of features (from the last block) for samples from different domains. Best viewed in colors.

![Image](https://ijcai.org/proceedings/2022/fulltext/187/image_000004_809bc8d66120d05067b58d1060c983360897b199eea3e55522198ee95024f8d7.png)

## 5 Conclusion

In this paper, we develop a brand-new DG variant termed as dynamic domain generalization, which aims to explore a training-free mechanism to adjust the model to adapt to agnostic target domains. To this end, we decouple network parameters into static and dynamic parts to disentangle domainshared and domain-specific features, where the latter ones are dynamically modulated by meta-adjusters with respect to varied novel samples from different domains. To enable this process, DomainMix and Asymmetric Kernel Templates are utilized to simulate novel samples and impose the meta-adjuster to modulate the models diversely for the samples from a large variety of novel domains. Extensive experiments demonstrate the superiority of our proposed DDG to vanilla DG approaches. Our work provides a strong baseline for DDG, and it shows possible to further improve DDG from an optimization perspective in the future.

## Acknowledgments

This work was supported by the National Natural Science Foundation of China (No.: 83321016, 83418022, U21A20471); the Fujian Provincial Youth Education and Scientific Research Project (No. 650722).

## References

1. [Balaji et al., 2018] Yogesh Balaji, Swami Sankara- narayanan, and Rama Chellappa. Metareg: Towards do- main generalization using meta-regularization. NeurIPS, 2018.
2. [Carlucci et al., 2019] Fabio M Carlucci, Antonio D'Innocente, Silvia Bucci, Barbara Caputo, and Ta- tiana Tommasi. Domain generalization by solving jigsaw puzzles. In CVPR, 2019.
3. [Cha et al., 2021] Junbum Cha, Sanghyuk Chun, Kyungjae Lee, Han-Cheol Cho, Seunghyun Park, Yunsung Lee, and Sungrae Park. Swad: Domain generalization by seeking flat minima. NeurIPS, 2021.
4. [Chattopadhyay et al., 2020] Prithvijit Chattopadhyay, Yo- gesh Balaji, and Judy Hoffman. Learning to balance speci- ficity and invariance for in and out of domain generaliza- tion. In ECCV, 2020.
5. [Ding et al., 2019] Xiaohan Ding, Yuchen Guo, Guiguang Ding, and Jungong Han. Acnet: Strengthening the ker- nel skeletons for powerful cnn via asymmetric convolution blocks. In ICCV, 2019.
6. [Dou et al., 2019] Qi Dou, Daniel Coelho de Castro, Kon- stantinos Kamnitsas, and Ben Glocker. Domain general- ization via model-agnostic learning of semantic features. NeurIPS, 2019.
7. [D'Innocente and Caputo, 2018] Antonio D'Innocente and Barbara Caputo. Domain generalization with domain- specific aggregation modules. In GCPR, 2018.
8. [Ganin and Lempitsky, 2015] Yaroslav Ganin and Victor Lempitsky. Unsupervised domain adaptation by backprop- agation. In ICML, 2015.
9. [Ganin et al., 2016] Yaroslav Ganin, Evgeniya Ustinova, Hana Ajakan, Pascal Germain, Hugo Larochelle, Franc ¸ois Laviolette, Mario Marchand, and Victor Lempitsky. Domain-adversarial training of neural networks. JMLR, 2016.
10. [Gulrajani and Lopez-Paz, 2021] Ishaan Gulrajani and David Lopez-Paz. In search of lost domain generalization. In ICLR, 2021.
11. [Haeusser et al., 2017] Philip Haeusser, Thomas Frerix, Alexander Mordvintsev, and Daniel Cremers. Associative domain adaptation. In ICCV, 2017.
12. [He et al., 2016] Kaiming He, Xiangyu Zhang, Shaoqing Ren, and Jian Sun. Deep residual learning for image recog- nition. In CVPR, 2016.
13. [Hu et al., 2018] Jie Hu, Li Shen, and Gang Sun. Squeeze- and-excitation networks. In CVPR, 2018.
14. [Huang et al., 2020] Zeyi Huang, Haohan Wang, Eric P Xing, and Dong Huang. Self-challenging improves cross- domain generalization. In ECCV, 2020.
15. [Iwasawa and Matsuo, 2021] Yusuke Iwasawa and Yutaka Matsuo. Test-time classifier adjustment module for model- agnostic domain generalization. NeurIPS, 2021.
16. [Kim et al., 2021] Daehee Kim, Youngjun Yoo, Seunghyun Park, Jinkyu Kim, and Jaekoo Lee. Selfreg: Self- supervised contrastive regularization for domain general- ization. In ICCV, 2021.
17. [Li et al., 2017] Da Li, Yongxin Yang, Yi-Zhe Song, and Timothy M Hospedales. Deeper, broader and artier do- main generalization. In ICCV, 2017.
18. [Li et al., 2018a] Da Li, Yongxin Yang, Yi-Zhe Song, and Timothy M Hospedales. Learning to generalize: Meta- learning for domain generalization. In AAAI, 2018.
19. [Li et al., 2018b] Ya Li, Xinmei Tian, Mingming Gong, Ya- jing Liu, Tongliang Liu, Kun Zhang, and Dacheng Tao. Deep domain generalization via conditional invariant ad- versarial networks. In ECCV, 2018.
20. [Li et al., 2019] Da Li, Jianshu Zhang, Yongxin Yang, Cong Liu, Yi-Zhe Song, and Timothy M Hospedales. Episodic training for domain generalization. In ICCV, 2019.
21. [Motiian et al., 2017] Saeid Motiian, Marco Piccirilli, Don- ald A Adjeroh, and Gianfranco Doretto. Unified deep su- pervised domain adaptation and generalization. In ICCV, 2017.
22. [Nam et al., 2021] Hyeonseob Nam, HyunJae Lee, Jongchan Park, Wonjun Yoon, and Donggeun Yoo. Reducing do- main gap by reducing style bias. In CVPR, 2021.
23. [Peng et al., 2019] Xingchao Peng, Qinxun Bai, Xide Xia, Zijun Huang, Kate Saenko, and Bo Wang. Moment match- ing for multi-source domain adaptation. In ICCV, 2019.
24. [Piratla et al., 2020] Vihari Piratla, Praneeth Netrapalli, and Sunita Sarawagi. Efficient domain generalization via common-specific low-rank decomposition. In ICML, 2020.
25. [Venkateswara et al., 2017] Hemanth Venkateswara, Jose Eusebio, Shayok Chakraborty, and Sethuraman Pan- chanathan. Deep hashing network for unsupervised do- main adaptation. In CVPR, 2017.
26. [Zhang et al., 2018] Hongyi Zhang, Moustapha Cisse, Yann N Dauphin, and David Lopez-Paz. mixup: Beyond empirical risk minimization. In ICLR, 2018.
27. [Zhou et al., 2020a] Kaiyang Zhou, Yongxin Yang, Timothy Hospedales, and Tao Xiang. Deep domain-adversarial im- age generation for domain generalisation. In AAAI, 2020.
28. [Zhou et al., 2020b] Kaiyang Zhou, Yongxin Yang, Timothy Hospedales, and Tao Xiang. Learning to generate novel domains for domain generalization. In ECCV, 2020.
29. [Zhou et al., 2021] Kaiyang Zhou, Yongxin Yang, Yu Qiao, and Tao Xiang. Domain generalization with mixstyle. In ICLR, 2021.
