Title: DIVA: DOMAIN INVARIANT VARIATIONAL AUTOEN-CODERS

Abstract: We consider the problem of domain generalization, namely, how to learn representations given data from a set of domains that generalize to data from a previously unseen domain. We propose the Domain Invariant Variational Autoencoder (DIVA), a generative model that tackles this problem by learning three independent latent subspaces, one for the domain, one for the class, and one for any residual variations. We highlight that due to the generative nature of our model we can also incorporate unlabeled data from known or previously unseen domains. To the best of our knowledge this has not been done before in a domain generalization setting. This property is highly desirable in fields like medical imaging where labeled data is scarce. We experimentally evaluate our model on the rotated MNIST benchmark and a malaria cell images dataset where we show that (i) the learned subspaces are indeed complementary to each other, (ii) we improve upon recent works on this task and (iii) incorporating unlabelled data can boost the performance even further.

1. INTRODUCTION:

Deep neural networks (DNNs) led to major breakthroughs in a variety of areas like computer vision and natural language processing. Despite their big success, recent research shows that DNNs learn the bias present in the training data. As a result they are not invariant to cues that are irrelevant to the actual task (Azulay & Weiss, 2018) . This leads to a dramatic performance decrease when tested on data from a different distribution with a different bias.

In domain generalization the goal is to learn representations from a set of similar distributions, here called domains, that can be transferred to a previously unseen domain during test time. A common motivating application, where domain generalization is crucial, is medical imaging (Blanchard et al., 2011; Muandet et al., 2013) . For instance, in digital histopathology a typical task is the classification of benign and malignant tissue. However, the preparation of a histopathology image includes the staining and scanning of tissue which can greatly vary between hospitals. Moreover, a sample from a patient could be preserved in different conditions (Ciompi et al., 2017) . As a result, each patient's data could be treated as a separate domain (Lafarge et al., 2017) . Another problem commonly encountered in medical imaging is class label scarcity. Annotating medical images is an extremely time consuming task that requires expert knowledge. However, obtaining domain labels is surprisingly cheap, since hospitals generally store information about the patient (e.g., age and sex) and the medical equipment (e.g., manufacturer and settings). Therefore, we are interested in extending the domain generalization framework to be able to deal with additional unlabeled data, as we hypothesize that it can help to improve performance.

In this paper, we propose to tackle domain generalization via a new deep generative model that we refer to as the Domain Invariant Variational Autoencoder (DIVA). We extend the variational autoencoder (VAE) framework (Kingma & Welling, 2013; Rezende et al., 2014) by introducing independent latent representations for a domain label, a class label and any residual variations in the input x. Such partitioning of the latent space will encourage and guide the model to disentangle these sources of variation. Finally, by virtue of having a generative model we can naturally handle the semi-supervised scenario, similarly to Kingma et al. (2014) . We evaluate our model on a version of the MNIST dataset where each domain corresponds to a specific rotation angle of the digits, as well as on a Malaria Cell Images dataset where each domain corresponds to a different patient. An implementation of DIVA can be found under (URL was removed to preserve anonymity). . Right: Inference model. We propose to factorize the variational posterior as q φ d (z d |x)q φx (z x |x)q φy (z y |x). Dashed arrows represent the two auxiliary classifiers q ω d (d|z d ) and q ωy (y|z y ).

2. TOWARDS DOMAIN GENERALIZATION WITH GENERATIVE MODELS:

We follow the domain generalization definitions used in Muandet et al. (2013) . A domain is defined as a joint distribution p(x, y) on X × Y, where X denotes the input space and Y denotes the output space. Let P X ×Y be the set of all domains. The training set consists of samples S taken from N domains, S = {S (d=i) } N i=1 . Here, the ith domain p (d=i) (x, y) is represented by n i samples,

S (d=i) = {(x (d=i) k , y (d=i) k )} ni k=1

. Each of the N distributions p (d=1) (x, y), . . . , p (d=i) (x, y), . . . , p (d=N ) (x, y) are sampled from P X ×Y . We further assume that p (d=i) (x, y) = p (d=j) (x, y), therefore, the samples in S are non-i.i.d. During test time we are presented with samples S (d=N +1) from a previously unseen domain p (d=N +1) (x, y). We are interested in learning representations that generalize from p (d=1) (x, y), . . . , p (d=N ) (x, y) to this new domain. Training data are given as tuples (d, x, y) in the case of supervised data or as (d, x) in the case of unsupervised data.

2.1. DIVA: DOMAIN INVARIANT VAE:

Assuming a perfectly disentangled latent space (Higgins et al., 2018) , we hypothesize that there exists a latent subspace that is invariant to changes in d, i.e., it is domain invariant. We propose a generative model with three independent sources of variation; z d , which is domain specific, z y , which is class specific and finally z x , which captures any residual variations left in x. While z x keeps an independent Gaussian prior p(z x ), z d and z y have conditional priors p θ d (z d |d), p θy (z y |y) with learnable parameters θ d , θ y . This will encourage information about the domain d and label y to be encoded into z d and z y , respectively. Furthermore, as z d and z y are marginally independent by construction, we argue that the model will learn representations z y that are invariant with respect to the domain d. All three of these latent variables are then used by a single decoder p θ (x|z d , z x , z y ) for the reconstruction of x.

Since we are interested in using neural networks to parameterize p θ (x|z d , z x , z y ), exact inference will be intractable. For this reason, we perform amortized variational inference with an inference network (Kingma & Welling, 2013; Rezende et al., 2014) , i.e., we employ a VAE-type framework. We introduce three separate encoders q φ d (z d |x), q φx (z x |x) and q φy (z y |x) that serve as variational posteriors over the latent variables. Notice that we do not share their parameters as we empirically found that sharing parameters leads to a decreased generalization performance. For the prior and variational posterior distributions over the latent variables z x , z d , z y we assume fully factorized Gaussians with parameters given as a function of their input. We coin the term Domain Invariant VAE (DIVA) for our overall model, which is depicted in Figure 1 .

Given a specific dataset, all of the aforementioned parameters can be optimized by maximizing the following variational lower bound per input x:

L s (d, x, y) = E q φ d (z d |x)q φx (zx|x),q φy (zy|x) [log p θ (x|z d , z x , z y )] -βKL (q φ d (z d |x)||p θ d (z d |d)) -βKL (q φx (z x |x)||p(z x ))

-βKL q φy (z y |x)||p θy (z y |y) .

(1) Notice that we have introduced a weigting term, β. This is motivated by the β-VAE (Higgins et al., 2017) and serves as a constraint that controls the capacity of the latent spaces of DIVA. Larger values of β limit the capacity of each z and in the ideal case each dimension of z captures one of the conditionally independent factors in x.

To further encourage separation of z d and z y into domain and class specific information respectively, we add two auxiliary objectives. During training z d is used to predict the domain d and z y is used to predict the class y for a given input x:

EQUATION

where α d , α y are weighting terms for each of these auxiliary objectives. Since our main goal is a domain invariant classifier, during inference we only use the encoder q φy (z y |x) and the auxiliary classifier q ωy (y|z y ). For the prediction of the class y for a new input x we use the mean of z y . Consequently, we regard the the variational lower bound L s (d, x, y) as a regularizer. Therefore, evaluating the marginal likelihood p(x) of DIVA is outside the scope of this paper. Locatello et al. (2018) and Dai & Wipf (2019) claim that learning a disentangled representation, i.e., q φ (z) = i q φ (z i ), in an unsupervised fashion is impossible for arbitrary generative models. Inductive biases, e.g., some form of supervision or constraints on the latent space, are necessary to find a specific set of solutions that matches the true generative model. Consequently, DIVA is using domain labels d and class labels y in addition to input data x during training. Recent work by Khemakhem et al. (2019) shows that conditional priors, like p θ d (z d |d) and p θy (z y |y) in DIVA, lead to identifiability guarantees in VAEs. Furthermore, we enforce the factorization of the marginal distribution of z in the following form: q φ (z) = q φ d (z d )q φx (z x )q φy (z y ), which prevents the impossibility described in Locatello et al. (2018) . We argue that the strong inductive biases in DIVA make it possible to learn disentangled representations that match the ground truth factors of interest, namely, the domain factors z d and class factors z y . To highlight the importance of a partitioned latent space we compare DIVA to a VAE with a single latent space, the results of this comparison can be found in the Appendix.

2.2. SEMI-SUPERVISED DIVA:

In Kingma et al. (2014) an extension to the VAE framework was introduced that allows to use labeled as well as unlabeled data during training. While Kingma et al. ( 2014) introduced a two step procedure, Louizos et al. (2015) presented a way of optimizing the decoder of the VAE and the auxiliary classifier jointly. We use the latter approach to learn from supervised data {(d n , x n , y n )} as well as from unsupervised data {(d m , x m )}. Analogically to Louizos et al. (2015) , we use q ωy (y|z y ) to impute y:

L u (d, x) = E q φ d (z d |x)q φx (zx|x)q φy (zy|x) [log p θ (x|z d , z x , z y )] -βKL(q φ d (z d |x)||p θ d (z d |d)) -βKL(q φx (z x |x)||p(z x ))

+ βE q φy (zy|x)qω y (y|zy) [log p θy (z y |y) -log q φy (z y |x)]

EQUATION

where we use Monte Carlo sampling with the reparametrization trick (Kingma & Welling, 2013) for the continuous latents z d , z x , z y and explicitly marginalize over the discrete variable y. The final objective combines the supervised and unsupervised variational lower bound as well as the two auxiliary losses. Assuming N labeled and M unlabeled examples, we obtain the following objective:

F SS-DIVA = N n=1 F DIVA (x n , y n , d n ) + M m=1 L u (x m , d m ) + α d E q φ d (z d |xm) [log q ω d (d m |z d )]. (4)

3. RELATED WORK:

The majority of proposed deep learning methods for domain generalization fall into one of two categories: 1) Learning a single domain invariant representation, e.g., using adversarial methods (Carlucci et al., 2018; Ghifary et al., 2015; Li et al., 2018; 2017; Motiian et al., 2017; Shankar et al., 2018; Wang et al., 2019) . While DIVA falls under this category there is a key difference: we do not explicitly regularize z y using d. Instead we learn complementary representations z d , z x and z y utilizing a generative architecture. 2) Ensembling models, each trained on an individual domain from the training set (Ding & Fu, 2018; Mancini et al., 2018) . The size of models in this category scales linearly with the amount of training domains. This leads to slow inference if the number of training domains is large. However, the size of DIVA is independent of the number of training domains. In addition, during inference time we only use the mean of the encoder q φy (z y |x) and the auxiliary classifier q ωy (y|z y ).

Concurrently to DIVA Cai et al. (2019) developed a framework to learn latent disentangled semantic representations (DSR) for domain adaptation. DSR assumes that the data generation process is exclusively controlled by the domain d and class y. As a result, DSR is lacking a third latent space z x . We designed DIVA assuming that not all variations in x can be explained by the domain d and the class y. Therefore we introduce z x in order to capture these residual variations. Furthermore, while DSR uses gradient reversal layers, we directly parameterize the ground truth generative model. As a result, the priors in DIVA are conditional which is necessary for guaranteed disentanglement as recent research has shown (Khemakhem et al., 2019) . More related work is published under the name of multiple source domain adaptation (Zhao et al., 2018) .

An area that is closely related to domain generalization is that of the statistical parity in fairness.

The goal of fair classification is to learn a meaningful representation that at the same time cannot be used to associate a data sample to a certain group (Zemel et al., 2013) . The major difference to domain generalization is the intention behind that goal, e.g., to protect groups of individuals vs. being robust to variations in the input. Consequently, DIVA is closely related to the fair VAE (Louizos et al., 2015) . In contrast to the fair VAE, which is using a hierarchical latent space, DIVA is using a partitioned latent space. Moreover, the fair VAE requires the domain label during inference while DIVA alleviates this issue by learning the classifier without d. Similar to DIVA, there is an increasing number of methods showing the benefits of using latent subspaces in generative models (Siddharth et al., 2017; Klys et al., 2018; Jacobsen et al., 2018; Bouchacourt et al., 2018; Atanov et al., 2019) .

We derived DIVA by following the VAE framework (Kingma & Welling, 2013) , where the generative process is the starting point. A conditional version of the variational information bottleneck (CVIB) was proposed by Moyer et al. (2018) that likewise leads to an objective consisting of a reconstruction loss. However, CVIB suffers from the same limitation as the fair VAE: that the domain must be known during inference, hence, we excluded it from our experiments.

4. EXPERIMENTS:

We evaluate the performance of DIVA on two datasets: Rotated MNIST (Ghifary et al., 2015) and Malaria Cell Images (Rajaraman et al., 2018) . In both cases we first investigate if DIVA is able to successfully learn disentangled representations. Furthermore, we compare DIVA to other methods in a supervised and semi-supervised setting. While for the rotated MNIST dataset DIVA's graphical model is matching the ground truth generative model, the Malaria Cell Images dataset poses a more challenging and realistic scenario, where the ground truth generative model is unknown.

4.1. ROTATED MNIST:

The construction of the Rotated MNIST dataset follows (Ghifary et al., 2015) . We sample 100 images from each of the 10 classes from the original MNIST training dataset. This set of images is denoted M 0 • . To create five additional domains the images in M 0 • are rotated by 15, 30, 45, 60 and 75 degrees. In order to evaluate their domain generalization abilities, models are trained on five domains and tested on the remaining 6th domain, e.g., train on M 0 First of all, we visualize the three latent spaces z d , z x and z y , to see if DIVA is able to successfully disentangle them. In addition, we want to verify whether DIVA utilizes z x in a meaningful way, since it is not directly connected to any downstream task. For the following visualizations we restrict the size of each latent space z d , z x and z y to 2 dimensions. Therefore, we can plot the latent subspaces directly without applying dimensionality reduction, see Figure 2 . Here, we trained DIVA on 5000 images from five domains: From these initial qualitative results we conclude that DIVA is disentangling the information contained in x as intended, as z d is only containing information about d and z y only information about y. In the case of the Rotated MNIST dataset z x captures any residual variation that is not explained by the domain d or the class y. In addition, we are able to generate conditional reconstructions as well as entirely new samples with DIVA. We provide these in the Appendix.

M 0 • , M 15 • , M 30 • , M 45 • and M 60 • .

4.1.2. COMPARISON TO OTHER METHODS:

We compare DIVA against the well known domain adversarial neural networks (DA) (Ganin et al., 2015) as well as three recently proposed methods: LG (Shankar et al., 2018) , HEX (Wang et al., 2019) and ADV (Wang et al., 2019) . For the first half of Table 1 (until the vertical line) we only use labeled data. The first column indicates the rotation angle of the test domain. We report test accuracy on y for all methods. For DIVA we report the mean and standard error for 10 repetitions. DIVA achieves the highest accuracy across all test domains and the highest average test accuracy among all proposed methods.

The second half of Table 1 showcases the ability of DIVA to use unlabeled data. For this experiment we add: The same amount (+1) of unlabeled data as well as three (+3), five (+5) and nine (+9) times the amount of unlabeled data to our training set. We first add the unlabeled data to M 0 • and create the data for the other domains as described in Section 4.1. In Table 1 we can clearly see a performance increase when unlabeled data is added to the training set. When the amount of unlabeled data is The majority of medical imaging datasets consist of images from a multitude of patients. In a domain generalization setting each patient is viewed as an individual domain. While we focus on patients as domains in this paper, this type of reasoning can be extended to, e.g., hospitals as domains. We, among others (Rajaraman et al., 2018; Lafarge et al., 2017) , argue that machine learning algorithms trained with medical imaging datasets should be evaluated on a subset of hold-out patients. This presents a more realistic scenario since the algorithm is tested on images from a previously unseen domain. In the following, we use a Malaria Cell Images dataset (Rajaraman et al., 2018) as an example of a dataset consisting of samples from multiple patients. The images in this dataset were collected and photographed at Chittagong Medical College Hospital, Bangladesh. It consists of 27558 single red blood cell images taken from 150 infected and 50 healthy patients. The images were manually annotated by a human expert. A cell has the label y = 1 if it shows the parasite and the label y = 0 if not. To facilitate the counting of parasitized and uninfected cells, the cells were stained using Giemsa stain which turns the parasites inside the cell pink. In addition, the staining process leads to a variety of colors of the cell itself. While the color of the cell is relatively constant for a single patient, it can vary greatly between patients, see the first row in Figure 3 . This variability in appearance of the cells can be easily ignored by a human observer, however, machine learning models can fail to generalize across patients. In our experiments we will use the patient ID as the domain label d. We argue that for this specific dataset the patient ID is a good proxy of appearance variability. In addition, there is no extra cost for obtaining the patient ID for each cell.

Subsequently, we use a subset of the Malaria Cell Images dataset that consists of the 10 patients with the highest amount of cells. The amount of cells per patient varies between 400 and 700 and there are 5922 cell images in total. The choice of this subset is motivated by the similiar amount of cells as well as the similar marginal label distributions per patient, the latter being a necessary condition for successful domain generalization (Zhao et al., 2019) . Furthermore we rescale all images to 64 × 64 pixels. To artificially expand the size of the training dataset we use data augmentation in the form of vertical flips, horizontal flips and random rotations.

4.2.1. QUALITATIVE DISENTANGLEMENT:

We investigate the three latent subspaces z d , z x and z y to see if DIVA is able to successfully disentangle them. In addition, we want to see if DIVA utilizes z x in a meaningful way, since it is not directly connected to any downstream task. Figure 3 shows the reconstructions of x using all three latent subspaces as well as reconstructions of x using only a single latent subspace at a time. First, we find that DIVA is able to reconstruct the original cell images using all three subspaces (Figure 3 , second row). Second, we find that the three latent subspaces are indeed disentangled: z d is containing the color of the cell (Figure 3 , third row), z x the shape of the cell (Figure 3 , fourth row) and z y the location of the parasite (Figure 3 , fifth row). The holes in the reconstructions using only z x indicate that there is no probability mass in z d and z y at 0, similar to Figure 2 . From the reconstructions in Figure 3 we conclude that DIVA is able to learn disentangled representations that match the ground truth factors of interest, here, the appearance of the cell and the presence of the parasite. In addition to these qualitative results, we show that a classifier for y trained on z d or z x performs worse than a classifier that would always predict the majority class, the results can be found in the Appendix.

0 1 0 1 0 1 1 0 1 1 1 1 1 0 x x ∼ p θ (x|z d , z x , z y ) x ∼ p θ (x|z d , 0, 0) x ∼ p θ (x|0, z x , 0)

x ∼ p θ (x|0, 0, z y ) y Figure 3 : Reconstructions of x using all three latent subspaces as well as reconstructions of x using only a single latent subspace at a time.

4.2.2. SUPERVISED CASE:

To further evaluate domain generalization abilities, models are trained on nine domains (patient IDs) and tested on the remaining 10th domain. We choose ROC AUC on the hold out test domain as the evaluation metric, since the two classes are highly imbalanced. All experiments are repeated five times.

Table 3 : Results of the supervised experiments for the first part of domains. We report the average and standard error of ROC AUC.

Model C116P77 C132P93 C137P98 C180P141 C182P143 C184P145 Baseline 90.6 ± 0.7 97.8 ± 0.5 98.9 ± 0.2 98.5 ± 0.2 96.7 ± 0.4 98.1 ± 0.2 DA 90.6 ± 1.7 98.3 ± 0.4 99.0 ± 0.1 98.8 ± 0.1 96.9 ± 0.4 97.1 ± 0.8 DIVA 93.3 ± 0.4 98.4 ± 0.3 99.0 ± 0.1 99.0 ± 0.1 96.5 ± 0.3 98.5 ± 0.3 We compare DIVA with a ResNet-like (He et al., 2015) baseline and DA. During inference all three models have the same architecture, seven ResNet blocks followed by two linear layers. Detailed information about hyperparameters, architecture and training schedule can be found in the Appendix.

In Table 3 and 4 we find that the results are not equally distributed across all test domains. In five cases DIVA is able to significantly improve upon the baseline model and DA. Upon visual inspection we find that cells from domain C116P77 and domain C59P20 are stained pink, similar to the stain of the parasite, see Appendix. In case of C116P77 DIVA achieves the highest ROC AUC of all three models. In case of domain C59P20, all three methods have difficulties to detect the parasite which leads to the lowest ROC AUC among all domains. We believe that the difficulties arise the poor contrast between cell and parasite. Last, DIVA is able to improve on average when compared to the baseline model and DA, although the improvements are within the standard error.

4.2.3. SEMI-SUPERVISED CASE:

As described in Section 4.1.3 we are interested in learning from domains with no class labels, since such an approach can drastically lower the amount of labeled data needed to learn a domain invariant representation, i.e., a model that generalizes well across patients. For the semi-supervised experiments we choose domain C116P77 to be the test domain since its cells show a unique dark pink stain. Furthermore, unlabeled data from domain C59P20 is used since it is visually the closest to domain C116P77, see Appendix. The evaluation metric on the hold out test domain is ROC AUC again.

In Table 5 we compare the baseline model, DA and DIVA trained with labeled data from domain C59P20, unlabeled data from domain C59P20 and no data from domain C59P20.

We argue that the improvement of DIVA over DA arises from the way the additional unlabeled data is utilized. In case of DA the unlabeled data (d, x) is only used to train the domain classifier and the feature extractor in an adversarial manner. In Section 2.2 we show that due to DIVA's generative nature q φy (z y |x), p θy (z y |y) can be updated using q ωy (y|z y ) to marginalize over y for an unlabeled sample x. In addition, the unlabeled data (d, x) is used to update q φ d (z d |x), p θ d (z d |d), q ω d (d|z d ), q φx (z x |x) and p θ (x|z d , z x , z y ) in the same way as in the supervised case. In all of our experiments it appears that there is a key difference between interpolation and extrapolation, a distinction currently not made by the domain generalization community: If we assume that the domains lie in intervals like [0 • ,15 • , 30 • ] or ['red', 'orange', 'yellow'] then the performance for the domains in the center of the interval, e.g., 15 • and 'orange', seems to be better than for the domains on the ends of the interval. We argue that DIVA can make use of unlabeled data from a domain that is close to the test domain to improve its extrapolation performance, as seen in Section 4.1.3 and 4.2.3. ReLU, Linear(5 for q ω d (d|z d )/10 for q ωy (y|z y )), Softmax 

Change of class:

The first row of Figure 5 (left) shows the input images x for DIVA. First, we generate embeddings z d , z x and z y for each x using q φ d (z d |x), q φx (z x |x) and q φy (z y |x). Second, we replace z y with a sample z y from the conditional prior p θy (z y |y). Last, we generate new images from z d , z x and z y using the trained encoder p θ (x|z d , z x , z y ). In Figure 5 (left) rows 2 to 11 Right: Inference model. We propose q φ (z|x) as the variational posterior. Dashed arrows represent the two auxiliary classifiers q ω d (d|z) and q ωy (y|z).

The objective is given by, 

EQUATION

2.. DIVA without z:

x : There exist no latent space z x , no encoder q φx (z x |x) and no prior p(z x ).

The decoder becomes p θ (x|z d , z y ).

In Table 11 , we compare DIVA and the two ablated versions on the Rotated MNIST dataset. Surprisingly, for Rotated MNIST we could not find a significant difference in performance between DIVA and DIVA without z d , as seen in the third column. However, not having z d drastically reduces the interpretability of our model, since without z d we cannot find the variations in x that are explained by the domain d. E.g. in Appendix 5.1.4, we show that we can generate samples conditioned on the domain label that give us a clear idea of the meaning of d. Furthermore, as seen in Figure 3 , we see that the patient ID is highly correlated with the color of the stain. While the cell shape in not correlated with d or y and therefore is captured by z x . Without z d we are unable to gain such (especially from a medical perspective) important insights. In the fourth column, we see that for M 0 • and M 75 • DIVA with z x performs significantly better than without. We argue that if z x does not exist, z d and z y will capture the residual variations in x that are not explained by d or y. We believe this makes it harder to predict y using z y and d using z d . 

5.2.3. TRAINING PROCEDURE: BASELINE AND DA:

In case of the supervised experiments in Section 5.2.5 all models are trained for 500 epochs. The training is terminated if the validation accuracy for y has not improved for 100 epochs. In case of the semi-supervised experiments in Section 2.2 the amount of epochs is adjusted to match the number of parameter updates of DIVA. For DA we follow the same training procedure as described in Ganin et al. (2015) . In the supervised case, first, a labeled batch randomly sampled from the training distributions is used to update the class classifier, domain classifier and the feature extractor in an adversarial fashion. Second, a second batch randomly sampled from the training distributions is used to update only the domain classifier and the feature extractor in an adversarial fashion. In the semi-supervised case samples from the unsupervised domains form the second batch together

:



Figures and Tables:

Figure 1: Left: Generative model. According to the graphical model we obtain p(d, x, y, z d , z x , z y ) = p θ (x|z d , z x , z y )p θ d (z d |d)p(z x )p θy (z y |y)p(d)p(y). Right: Inference model. We propose to factorize the variational posterior as q φ d (z d |x)q φx (z x |x)q φy (z y |x). Dashed arrows represent the two auxiliary classifiers q ω d (d|z d ) and q ωy (y|z y ).

Figure 2: 2D embeddings of all three latent subspaces. In the top row embeddings are colored according to their domain, in the bottom row they are colored according to their class. First column: z d encoded by q φ d (z d |x). The top plot shows five distinct clusters, where each cluster corresponds to a single domain. In the bottom plot no clustering is visible. Second column: z x encoded by q φx (z x |x). We observe a correlation between the rotation angle of each MNIST digit and z x [0] in the top plot. Upon visual inspection of the original inputs x, we find a correlation between the line thickness digit and z x [0] as well as a correlation between the digit width and z x [1] in the bottom plot. As a result, we observe a clustering of embeddings with class '1' at the lower left part of the plot. Third column: z y encoded by q φy (z y |x). In the top plot no clustering is visible. The bottom plot shows ten distinct clusters, where each cluster corresponds to a class. A plot of the 2D embeddings for the test domain M 75 • can be found in the Appendix.

5.1.3 SAMPLESWe present samples from DIVA by sampling z d , z x and z y from their priors and then decoding them. Generated examples on the Rotated MNIST data are given in the Figure4. DIVA allows to generate images that are almost indistinguishable from real datapoints.

Figure 4: Samples from DIVA trained on Rotated MNIST.

Figure 6: 1000 two-dimensional embeddings z d encoded by q φ d (z d |x) for x from the test domain M 75 • . The color of each point indicates the associated domain.

Figure 7: 1000 two-dimensional embeddings z y encoded by q φy (z y |x) for x from the test domain M 75 • . The color of each point indicates the associated class.

Test DIVA DIVA without z d DIVA without z x M 0 • 93.5 ± 02 TRAINING PROCEDURE: DIVA All DIVA models are trained for 500 epochs. The training is terminated if the validation accuracy for y has not improved for 100 epochs. As proposed in Burgess et al. (2018), we linearly increase β from 0.0 to 1.0 during the first 100 epochs of training. We set α d = 100000 and α y = 75000. Last, z d , z x and z y each have 64 latent dimensions. We searched over the following parameters: α d , α d ∈ {25000, 50000, 75000, 100000}; dim(z d ) = dim(z x ) = dim(z y ), dim(z x ) ∈ {32, 64}; β max ∈ {1, 5, 10}. All hyperparameters were determined using a validation set that consists of 20 % of the training set. All models were trained using ADAM (Kingma & Ba, 2014) (with default settings), a mixture of discretized logistics (Salimans et al., 2017) loss and a batch size of 100. In case of the semi-supervised experiment in Section 4.2.3 we adapt α d and α y according to Equation 5.

• , M 15 • , M 30 • , M 45 • and M 60 • , test on M 75 • . The evaluation metric is the classification accuracy on the test domain. All experiments are repeated 10 times. Detailed information about hyperparameters, architecture and training schedule can be found in the Appendix.

Table content: <table/>

Comparison with other state-of-the-art domain generalization methods. Methods in the first half of the table (until the vertical line) use only labeled data. The second half of the table shows results of DIVA when trained semi-supervised (+ X times the amount of unlabeled data). We report the average and standard error of the classification accuracy. For the first experiment we choose the domains M 0 • , M 15 • , M 45 • and M 60 • to be part of the labeled training set. In addition, unlabeled data from M 30 • is used. In Table2we can see that even in the case where the additional domain is dissimilar to the test domain DIVA is able to slightly improve. For the second experiment we choose the domains M 0 • , M 15 • , M 30 • and M 45 • to be part of the labeled training set. In addition, unlabeled data from M 60 • is used. When comparing the results in Table2to the results in Table1we notice a drop in accuracy of about 20% for DIVA trained with only labeled data. However, when trained with unlabeled data from M 60 • we see an improvement of about 7%. The comparison shows that DIVA can successfully learn from samples of a domain without any labels.

Table content: <table><tr><td>Test</td><td>DA</td><td colspan="2">LG HEX ADV</td><td>DIVA</td><td>DIVA(+1) DIVA(+3) DIVA(+5) DIVA(+9)</td></tr><tr><td>M 0 •</td><td colspan="2">86.7 89.7 90.1</td><td colspan="3">89.9 93.5 ± 0.3 93.8 ± 0.4 93.9 ± 0.5 93.2 ± 0.5 93.0 ± 0.4</td></tr><tr><td colspan="3">M 15 • 98.0 97.8 98.9</td><td colspan="3">98.6 99.3 ± 0.1 99.4 ± 0.1 99.5 ± 0.1 99.5 ± 0.1 99.6 ± 0.1</td></tr><tr><td colspan="3">M 30 • 97.8 98.0 98.9</td><td colspan="3">98.8 99.1 ± 0.1 99.3 ± 0.1 99.3 ± 0.1 99.3 ± 0.1 99.3 ± 0.1</td></tr><tr><td colspan="3">M 45 • 97.4 97.1 98.8</td><td colspan="3">98.7 99.2 ± 0.1 99.0 ± 0.2 99.2 ± 0.1 99.3 ± 0.1 99.3 ± 0.1</td></tr><tr><td colspan="3">M 60 • 96.9 96.6 98.3</td><td colspan="3">98.6 99.3 ± 0.1 99.4 ± 0.1 99.4 ± 0.1 99.4 ± 0.1 99.2 ± 0.2</td></tr><tr><td colspan="3">M 75 • 89.1 92.1 90.0</td><td colspan="3">90.4 93.0 ± 0.4 93.8 ± 0.4 93.8 ± 0.2 93.5 ± 0.4 93.2 ± 0.3</td></tr><tr><td>Avg</td><td colspan="2">94.3 95.3 95.8</td><td colspan="3">95.2 97.2 ± 1.3 97.5 ± 1.1 97.5 ± 1.2 97.4 ± 1.3 97.3 ± 1.3</td></tr><tr><td colspan="6">much larger than the amount of labeled data the balancing of loss terms become increasingly more</td></tr><tr><td colspan="6">challenging which can lead to a decling performance of DIVA, as seen in the last two columns of</td></tr><tr><td>Table 1.</td><td/><td/><td/><td/></tr><tr><td colspan="5">4.1.3 ADDITIONAL UNLABELED DOMAINS</td></tr></table>

Comparison of DIVA trained supervised to DIVA trained semi-supervised with additional unlabeled data from M 30 • and M 60 • . We report the average and standard error of the classification accuracy on M 75 • .

Table content: <table><tr><td colspan="3">Unsupervised domain DIVA supervised DIVA semi-supervised</td></tr><tr><td>M 30 •</td><td>93.1 ± 0.5</td><td>93.3 ± 0.4</td></tr><tr><td>M 60 •</td><td>73.8 ± 0.8</td><td>80.6 ± 1.1</td></tr><tr><td>4.2 MALARIA CELL IMAGES</td><td/><td/></tr></table>

Results of the supervised experiments for the second part of domains. As well as the average across all domains. We report the average and standard error of ROC AUC.

Table content: <table><tr><td>Model</td><td>C39P4</td><td>C59P20</td><td>C68P29</td><td>C99P60</td><td>Average</td></tr><tr><td colspan="6">Baseline 97.1 ± 0.4 82.8 ± 2.8 95.3 ± 0.6 96.2 ± 0.1 95.2 ± 1.6</td></tr><tr><td>DA</td><td colspan="5">97.4 ± 0.3 83.2 ± 3.3 96.3 ± 0.1 96.1 ± 0.3 95.4 ± 1.6</td></tr><tr><td>DIVA</td><td colspan="5">97.8 ± 0.2 82.1 ± 3.0 96.3 ± 0.2 96.6 ± 0.3 95.8 ± 1.6</td></tr></table>

Results of the semi-supervised experiments for domain C116P77. Comparison of baseline method, DA and DIVA trained with labeled data from domain C59P20, unlabeled data from domain C59P20 and no data from domain C59P20. We report the average and standard error of ROC AUC. have proposed DIVA as a generative model with three latent subspaces. We evaluated DIVA on Rotated MNIST and a Malaria Cell Images dataset. In both cases DIVA is able to learn disentangled representations that match the ground truth factors of interest, represented by the class y and the domain d. By learning representations z y that are invariant with respect to the domain d DIVA is able to improve upon other methods on both datasets. Furthermore, we show that we can boost DIVA's performance by incorporating unlabeled samples, even from entirely new domains for which no labeled examples are available. This property is highly desirable in fields like medical imaging where the labeling process is very time consuming and costly.

Table content: <table><tr><td>Training data</td><td>Baseline</td><td>DA</td><td>DIVA</td></tr><tr><td>Labeled data from C59P20</td><td colspan="3">90.6 ± 0.7 90.6 ± 1.7 93.3 ± 0.4</td></tr><tr><td>Unlabeled data from C59P20</td><td>-</td><td colspan="2">72.05 ± 2.2 79.4 ± 2.8</td></tr><tr><td>No data from C59P20</td><td colspan="3">70.0 ± 2.6 69.2 ± 1.9 71.9 ± 2.7</td></tr></table>

Architecture for q φ d (z d |x), q φx (z x |x) and q φy (z y |x). Each network has two heads one for the mean one and for the scale. The parameters for Conv2d are output channels and kernel size. The parameters for MaxPool2d are kernel size and stride. The parameter for Linear is output features.

Table content: <table><tr><td>block</td><td>details</td></tr><tr><td>1</td><td>Conv2d(32, 5), BatchNorm2d, ReLU</td></tr><tr><td>2</td><td>MaxPool2d(2, 2)</td></tr><tr><td>3</td><td>Conv2d(64, 5), BatchNorm2d, ReLU</td></tr><tr><td>4</td><td>MaxPool2d(2, 2)</td></tr><tr><td>5.1</td><td>Linear(64)</td></tr><tr><td>5.2</td><td>Linear(64), Softplus</td></tr></table>

Architecture for q ω d (d|z d ) and q ωy (y|z y ). The parameter for Linear is output features.

Table content: <table><tr><td>block</td><td>details</td></tr><tr><td>1</td><td/></tr></table>

Comparison of DIVA with a VAE with a single latent space, a standard Gaussian prior and two auxillary tasks on Rotated MNIST. We report the average and standard error of the classification accuracy.We compare DIVA as proposed in Section 2.1 to two ablated versions of DIVA:1. DIVA without z d : The domain label d is not used during training. Therefore, there exist no latent space z d , no encoder q φ d (z d |x), no prior p θ d (z d |d) and no classifier q ω d (d|z d ). The decoder becomes p θ (x|z x , z y ).

Table content: <table><tr><td>Test</td><td>VAE</td><td>DIVA</td></tr><tr><td colspan="3">M 0 • 88.4 ± 0.5 93.5 ± 0.3</td></tr><tr><td colspan="3">M 15 • 98.3 ± 0.1 99.3 ± 0.1</td></tr><tr><td colspan="3">M 30 • 97.4 ± 0.2 99.1 ± 0.1</td></tr><tr><td colspan="3">M 45 • 97.4 ± 0.4 99.2 ± 0.1</td></tr><tr><td colspan="3">M 60 • 97.9 ± 0.2 99.3 ± 0.1</td></tr><tr><td colspan="3">M 75 • 84.0 ± 0.3 93.0 ± 0.4</td></tr><tr><td>Avg</td><td colspan="2">93.9 ± 0.1 97.2 ± 1.3</td></tr><tr><td colspan="2">5.1.7 ABLATION STUDY: DIVA WITHOUT z d AND z x</td><td/></tr></table>

Results of ablation study.

Table content: <table/>

Peer review (iclr2020):
The paper introduces a VAE that can be used in problems in which domain information is available at training time to increase the classification performances on unseen domains. The model can also be used in a semi-supervised setting if unlabelled data is available (even from unseen domains). As the authors state, this is a quite common scenario in many interesting applications such as medical imaging. As such, I found the paper interesting to read (the paper is also written quite well). To allow the classification of data from any domain, in the inference network the labels d are not used to infer the latent states, but only as an auxiliary loss that forces z_d to capture domain-specific information. However, this makes me wonder if z_d is needed at all? I wouldn*t be surprised if the model performed equally well if domain information d was not passed to the model even during training, in which case z_x would also capture domain-specific information. To understand if this is the case, it would be very helpful to add a baseline model in which you use a version of DIVA in which z_d and d are not present both in the generative model and in the inference network. Since from the technical point of view the novelty of the model is limited, I would have liked to see a stronger experimental section to show the real-life applicability of the model: - The MNIST experiments are visually helpful to understand the disentanglement in the model. However you solve a quite simple task. What are the performances of a baseline classifier on this? - The malaria cell experiment is definitely more realistic and therefore interesting, and the results are quite convincing (despite being on quite low-resolution images). Since I consider the MNIST experiment a *toy task*, I think the paper would greatly improve if a new real-world experiment was performed (e.g. other medical imaging datasets). Overall I liked the paper and I think it is relevant for the ICLR community, therefore I am voting towards acceptance. However, a more convincing experimental section is needed for me to increase the score. Small comments: - you should make clearer from the abstract that the goal of this paper is to build a domain-invariant classifier (as opposed to solving more VAE-like tasks) - in the beginning of section 2.1 you write twice p(x|z_d, z_x, z_d), without z_y