Domain Generalization with Small Data

In this work, we propose to tackle the problem of domain generalization in the context of \textit{insufficient samples}. Instead of extracting latent feature embeddings based on deterministic models, we propose to learn a domain-invariant representation based on the probabilistic framework by mapping each data point into probabilistic embeddings. Specifically, we first extend empirical maximum mean discrepancy (MMD) to a novel probabilistic MMD that can measure the discrepancy between mixture distributions (i.e., source domains) consisting of a series of latent distributions rather than latent points. Moreover, instead of imposing the contrastive semantic alignment (CSA) loss based on pairs of latent points, a novel probabilistic CSA loss encourages positive probabilistic embedding pairs to be closer while pulling other negative ones apart. Benefiting from the learned representation captured by probabilistic models, our proposed method can marriage the measurement on the \textit{distribution over distributions} (i.e., the global perspective alignment) and the distribution-based contrastive semantic alignment (i.e., the local perspective alignment). Extensive experimental results on three challenging medical datasets show the effectiveness of our proposed method in the context of insufficient data compared with state-of-the-art methods.


Introduction
Nowadays, we have witnessed a lot of successes with the application of machine learning techniques in a variety of tasks related to computer vision (Li et al., 2022;Zaidi et al., 2022) and natural language processing (Mridha et al., 2022).Despite many achievements so far, the widely-adopted assumption for most existing methods, i.e., the data are identically and independently distributed in training and testing, may not always hold in actual applications (Zhou et al., 2022;Liu et al., 2022).In the real-world scenario, it is quite common that the distributions between training and testing data may be different, owing to changed environments.For example, acquired histopathological images of breast cancer from different healthcare centers exhibit significant domain gaps (a.k.a., domain shift, see Figure 1 for more detail) caused by differences in device vendors and staining methods, which may lead to the catastrophic deterioration of the performance (Qi et al., 2020).To address this Recently, researchers proposed several domain generalization approaches, such as data augmentation with randomization (Yue et al., 2019), data generalization with stylization (Verma et al., 2019;Zhou et al., 2021), meta learning-based training schemes (Li et al., 2018;Kim et al., 2021), among which representation learning-based methods are one of the most popular ones.These representation learning-based methods (Balaji et al., 2019) aim to learn domain-invariant feature representation.To be specific, if the discrepancy between source domains in feature space can be minimized, the model is expected to generalize better on unseen target domain, due to learned domaininvariant and transferable feature representation (Ben-David et al., 2006).For instance, an classical contrastive semantic alignment (CSA) loss proposed by Motiian et al. (2017) was to encourage positive sample pairs (with same label) from different domains closer while pulling other negative pairs (with different labels) apart.Dou et al. (2019) introduced the CSA loss which jointly considers local class alignment loss (for point-wise domain alignment) and global class alignment loss (for distribution-wise alignment).
Despite the progress so far, a reliable contrastive semantic loss with point-wise (or local) perspective usually requires sufficient samples on source domains such that diverse sample-to-sample pairs can be constructed (Sohn, 2016;Khosla et al., 2020).For example, Khosla et al. (2020) proposed a supervised contrastive semantic loss with a considerable volume of batch size on large-scale datasets such that decent performance can be guaranteed.Yao et al. (2022) also emphasized the importance of the number of sample-to-sample pairs influenced by data sizes for contrastive-based loss on DG problem.On the other hand, in the eye of distributionwise (a.k.a., global) alignment between domains (Dou et al., 2019), a consistent distribution measurement (e.g., Kullback-Leibler (KL) divergence) theoretically relies on sufficient samples for the distribution estimation as discussed by (Bu et al., 2018).However, these sufficient samples from multiple source domains may not always be available or accessible in the real world.For example, for the medical imaging data, insufficient sample scenarios either exist in all source domains (e.g., rare diseases inherently have a small volume of data from all healthcare centers (Lee et al., 2022)) or in some source domains (e.g., some specific domains have significantly smaller sample sizes than others, resulting from the differences of the ethnicity (Johnson and Louis, 2022), the demography (Gurdasani et al., 2019), and the privacy-preserving regulation (Can and Ersoy, 2021)).It is therefore necessary to develop reliable and effective semantic alignments from both local and global perspectives in the context of insufficient samples (a.k.a., small-data scenario) based on the source domains, in order to achieve better domain-invariant representations.
In this paper, we propose to learn domaininvariant representation from multiple source domains to tackle the domain generalization problem in the context of insufficient samples.Instead of extracting latent embeddings (i.e., latent points) based on deterministic models (e.g., convolutional neural networks, CNNs), we propose to leverage a probabilistic framework endowed by variational Bayesian inference to map each data point into probabilistic embeddings (i.e., the latent distribution) for domain generalization.Specifically, by following the domain-invariant learning from global (distribution-wise) perspective, we propose to extend empirical maximum mean discrepancy (MMD) to a novel probabilistic MMD (P-MMD) that can empirically measure the discrepancy between mixture distributions (a.k.a., distributions over distributions), consisted of a serial of latent distributions rather than latent points.From a local perspective, instead of imposing the CSA loss based on pairs of latent points, a novel probabilistic contrastive semantic alignment (P-CSA) loss with kernel mean embedding is proposed to encourage positive probabilistic embedding pairs closer while pulling other negative ones apart.Extensive experimental results on three challenging medical imaging classification tasks, including epithelium stroma classification on insufficient histopathological images, skin lesion classification, and spinal cord gray matter segmentation, show that our proposed method can achieve better cross-domain performance in the context of insufficient data compared with state-of-the-art methods.

Domain Generalization with Medical Images
Existing DG methods can be generally categorized into three different streams, namely data augmentation/generation (Yue et al., 2019;Graves, 2011;Zhou et al., 2021), meta-learning (Li et al., 2018;Kim et al., 2021) and feature representation learning (Li et al., 2018;Gong et al., 2019;Xiao et al., 2021).Among these methods, feature representation learning, which aims to explore invariant feature information that can be shared across domains, demonstrates to be a widely adopted method for the problem of DG.For the feature representation learning-based DG method, (Li et al., 2018) proposed to conduct multi-domain alignment in latent space via a multi-domain MMD distance.Gong et al. (2019) leveraged adversarial training to eliminate the domain discrepancy such that domain-invariant representation can be learned in a manifold space.Due to the varieties of imaging protocol (e.g., the choice of image solution for MRI image), device vendors (e.g., Philips or Siemens CT scanners), and patient populations (the race and age group), the acquired imaging data from different medical sites may exist significant domain shift problem (Liu et al., 2021).Dou et al. (2019) proposed a meta-learning framework to perform local and global semantic alignment for medical image classification.A similar design is also adopted by Li et al. (2022) for tissue image classification.Qi et al. (2020) utilized the curriculum learning scheme to transfer the knowledge for histopathological images classification.Li et al. (2020) combined the data augmentation and domain alignment to achieve decent performance on multiple medical data classification tasks.However, these methods may not focus on learning domain-invariant representation on insufficient samples from source domains.

Probabilistic Neural Networks
Compared with deterministic models, probabilistic neural networks turns to learn a distribution over model parameters, which can integrate the uncertainty in predictive modeling (Kingma et al., 2015;Gal and Ghahramani, 2016).When the data is insufficient, probabilistic models usually can achieve better generalized performance due to its probabilistic property (as an implicit regularization) (Blundell et al., 2015).In the context of insufficient samples, Bayesian neural network (Neal, 2012) (BNN) with variational inference, a representative probabilistic model, not only can improve predictive accuracy as a classifier (Wilson and Izmailov, 2020), but also can build up the quality of low-dimensional embeddings of insufficient data (Mallick et al., 2021), which is a crucial motivation for this paper.Meanwhile, modern analytical approximation techniques (e.g., Variational inference (Blei et al., 2017), empirical Bayes (Krishnan et al., 2020)) can efficiently infer the posterior distribution of model parameters with stochastic gradient descent method, which can integrate BNN with deterministic DNN conveniently.
In Xiao et al. (2021), the authors proposed to consider the uncertainty of a generalizable model based on BNN, where the distances of positive probabilistic embedding pairs and class distribution are minimized via KL measure.Despite the effectiveness, the dissimilar pairs (i.e., negative pairs) are ignored, which may not benefit feature representation learning.Moreover, they only focused on sample similarity while the distribution information is ignored.Instead, our proposed method comprehensively considers both positive and negative probabilistic embedding pairs via a novel distribution-based contrastive semantic loss.Last but not the least, our proposed method highlights the benefit of the BNN for building up the quality of latent embeddings under insufficient sample scenarios.

Probabilistic Embedding
Compared with deterministic point embeddings, probabilistic embeddings aim to characterize the data with a distribution.Due to its high robustness and effective representation (Nguyen et al., 2017), probabilistic representation has been applied to several fields, such as video representation learning (Park et al., 2022), image representation learning (Oh et al., 2018), face recognition (Shi and Jain, 2019;Chang et al., 2020), speaker diarization (Silnova et al., 2020), and human pose estimation (Sun et al., 2020).Recently, some researchers further leveraged the probabilistic embeddings to bridge the gap between data modalities (Chun et al., 2021;Neculai et al., 2022;Chun, 2023).For example, Chun et al. (2021) found that the probabilistic representation can lead to a richer embedding space for the challengeable relation reasoning between the images and their captions.These probabilistic embedding-based approaches either inherit the inherent distribution property of data (e.g., the multiple frames of a video) or tackle the one-to-many correspondences through distributional representation.Instead, our proposed method imposes the Bayesian neural network to generate probabilistic embedding.As such, the representative capacity of the data in the small-data regime can be enhanced.Moreover, we devise a novel probabilistic MMD to measure the discrepancy between mixture probabilistic embeddings for domain-invariant learning.

Methodology
Preliminary.Assume that there are K domains from different collected environments.The samples in each domain can be represented as R d×1 denotes a sample with the d dimension vector in the l-th domain.n l is the total number of samples in the l-th domain.The corresponding labels of samples X l in each domain can be denoted as Y l = {y l1 , • • • , y ln l }, where y li ∈ R m×1 is the form of one-hot encoding with m classes in total.For the setting of domain generalization, the source domain data represented as {X S l , Y S l } K l=1 , can be available in the training phase only, whereas the target domain data, denoted by X T , are only seen in test phase.
Overall.We provide a framework that can learn better domain-invariant representation when there is insufficient source domain data.The probabilistic neural network is imposed to enable high-quality and powerful feature representation in the context of insufficient samples.To effectively perform global perspective alignment, a novel probabilistic MMD is proposed to empirically measure the discrepancy between distributions over distributions based on reproducing kernel Hilbert space.We also propose a probabilistic contrastive semantic alignment to adapt probabilistic embeddings with local perspective.The details of our proposed method are discussed as below.
Probabilistic Embedding of Insufficient Data.Compared with deterministic models, the probabilistic models can learn a distribution over model weights, which has shown a better capacity to represent latent embeddings under insufficient sample scenario (Mallick et al., 2021).In this work, Bayesian neural network (BNN) (Blei et al., 2017) is utilized to extract the low-dimensional embeddings from high-dimensional inputs.By feeding the inputs into BNN with a parameter W ∼ p(W) , the samples X l = {x l1 , • • • , x ln l } of each domain can be represented by a set of probabilistic embeddings (i.e., latent distributions), i.e., p(Z|X l ) = {p(z|x l1 , W), • • • , p(z|x ln l , W)} where W ∼ p(W) is sampled stochastically.The variational inference is used to approximate the posterior distribution of W with the evidence lower bound (ELBO) (more details can be found in Appendix A.1).By using Monte Carlo (MC) estimators with T stochastic sampling operations from W, the predictive distribution of each p(z|x) can be an unbiased approximation.

Distribution Alignment via Probabilistic Maximum Mean Discrepancy
In this section, we introduce an approach to learning domain-invariant representation from a global perspective by minimizing the discrepancy among domains.Among various distribution distance metrics, Maximum Mean Discrepancy (MMD) is widely adopted (Long et al., 2017;Li et al., 2018) which aims to measure the distance between two probability distributions in a non-parametric manner.Specifically, assume that latent embeddings are drawn from two unknown distributions P l and P t .The probability measure P can be mapped into a reproducing kernel Hilbert space (RKHS) H as a element by setting, (1) where a reproducing kernel k : X × X → R and corresponding feature map ϕ : X → H are defined.Let the kernel k is characteristic such that the map µ : P → µ P is injective.In this case the MMD can be defined as the distance ∥µ P l − µ P k ∥ H in H between mean embeddings and it can be used as a measure of distance between the distributions P l and P t (Borgwardt et al., 2006;Gretton et al., 2012).The explicit computation of MMD can be derived by unbiased empirical estimation of mean map (Gretton et al., 2012), i.e., (2) The idea of using MMD for domain generalization has been explored in several works (e.g., (Li et al., 2018;Hu et al., 2020)).
In the probabilistic framework, instead of the individual latent embeddings z l1,... , we have latent probabilistic embeddings Π l1 := p(z|x l1 , W), . ... For a source domain D l , we have the associated distribution over distributions For this scenario, we propose to extend the existing point-based empirical MMD estimate to a distribution-based empirical probability MMD (P-MMD) estimate.P-MMD utilizes empirical estimation by kernels on distributions to measure the discrepancy between mixture distributions P l and P t under the probabilistic framework.
Specifically, we first represent latent probabilistic embeddings as elements in RKHS H k using the kernel k, that we coin a level-1 kernel in the sequel, e.g., µ which is an analog to the Eq. ( 1).The kernel mean embedding µ Π l 1 can be regarded as a new feature map for a variety of tasks (Yoshikawa et al., 2014).
Here, to enable non-linear learning on distributions, we introduce a level-2 kernel K (Muandet et al., 2012).Consider a level-1 kernel κ on H and its reproducing kernel Hilbert space (RKHS) H κ .Define K as (3) where K and its explicit form on kernel mean embeddings κ are p.d. kernels (Berlinet and Thomas-Agnan, 2011).We define a novel probabilistic MMD (P-MMD) empirical estimation method using the level-2 kernel K: In this work, the level-1 and level-2 kernels, k and K, are both Gaussian RBF kernel due to its impressive performance on a limited amount of distribution data (Muandet et al., 2012).Namely, where m l and m t are determined by sampling times T .The kernel mean embedding using the level-1 kernel k creates distributions µ(P 1 ), . . ., µ(P N ) represented by the samples {µ Π l 1 , . . ., µ Π ln } for l = 1, . . ., N respectively in the RKHS H k .The underlying strategy of P-MMD is to apply the classic MMD to these distributions (with respect to the kernel κ) .To access the effect that the minimization of P-MMD has on the original latent probability distributions across different domains, we recall the following: Theorem 1 (Muandet et al. ( 2012)).Let P 1 , . . ., P N be probability distributions and P := Then the distributional variance given by 1 N ∥µ Pi − µ P∥ is 0 iff P 1 = P 2 = . . .= P N .Corollary 3.1 (Li et al. (2018)).The upper bound of the distributional variance can be written as In our setting Theorem 1 and Corollary 3.1 along with the fact that k is a characteristic kernel imply the following: Corollary 3.2.iff all moments of latent distributions Π l associated to points of domain D l for l = 1, . . ., N are distributed identically across domains, 1≤i,j≤K P-MMD(P i , P j ) 2 = 0 holds.Following Corollary 3.2 we define the following loss function: Corollary 3.2 implies that as Eq. 6 tends to 0 so does the distance between the distributions of means, variances and higher moments of the distributions Π l associated to points of different domains.Remark 1.In section 4.5, we compare the P-MMD approach to simply taking the mean (i.e., first moment) of latent probabilistic embeddings , and then minimizing the associated "vanilla" MMD.Although this scheme is more efficient computationally over our proposed method, it discards most information about high-level statistics as discussed by Muandet et al. (2017).We empirically verify that our approach has better performance across domains.The visualized computation of P-MMD is shown in Figure 2.
Although we focus on the scenario of insufficient samples, the computational consumption from Eqs. ( 4) and ( 5) may be still prohibitive as the calculation of MMD distance between distributions can scale at least quadratically with the increasing of sample size (especially for image segmentation task), i.e., O(n 2 ) in a domain.Here, by following the linear statistic theory of MMD, the unbiased estimate can be derived by drawing pairs from two domains with replacement, i.e., P-MMD ), where assuming n l = n t for simplicity.Borgwardt et al. (2006) gives proof about the unbiased property of the linear statistic of MMD and shows that statistic power does not be sacrificed too much.
To learn domain-invariant representation from a local perspective, a popular idea is to encourage positive pairs with same label closer together, while pulling other negative ones with different labels further apart (Motiian et al., 2017;Dou et al., 2019).These methods usually measure the Euclidean distance between samples in the embedding space.However, this scheme may not satisfy our probabilistic framework due to its probabilistic embeddings.
To this end, we propose a probabilistic contrastive semantic alignment (P-CSA) loss that can utilize the empirical MMD to measure the discrepancy between probabilistic embeddings.The proposed P-CSA loss L local consists of two components, including the positive probabilistic contrastive loss and negative probabilistic contrastive Table 1 Experiment results of Epithelium Stroma Classification of Histopathological Images.Each column denotes a cross-domain task.For example, in the second column, we use IHC dataset as the target domain and the remaining datasets as the source domains.Note that all baseline methods adopt the SWAD method (Cha et al., 2021) (Cha et al., 2021) 79.74± 0.15 74.84± 0.13 84.29± 0.12 79.62 BDIL (Xiao et al., 2021) 85.56± 0.12 71.89± 0.14 85.90± 0.18 81.05DNA (Chu et al., 2022) 83.93± 0.18 73.94± 0.15 85.57± 0.17 81.14 DSU (Li et al., 2022) 81.56± 0.14 72.47± 0.12 83.94± 0.16 79.32 MIRO (Cha et al., 2022) 82 loss.The former aims to minimize the distance between the intra-class distributions from different domains, i.e., where M Θ (•) denotes the embedding network of metric learning, which will contribute to learn the distance between features better (Dou et al., 2019).Note that y n = y q needs to be satisfied.Then, the negative probabilistic contrastive loss is denoted by where ξ is a distance margin that can guarantee an appropriate repulsion range.Note that y n ̸ = y q needs to be satisfied.
Model Training.Our proposed framework consists of three modules, a BNN-based probabilistic extractor Q ϕ , a BNN-based classifier C ω , and a metric network M Θ (•).For the Q ϕ , we only add a Bayesian layer with ReLU layer on the bottom of a pretrained deterministic model (e.g., ResNet18 by removing fully-connected layers) by following Xiao et al. (2021).For the C ω , a Bayesian layer is also introduced to adapt the classification on insufficient sample better.More implement details of BNN can be found in Appendix A.1.The structure of M Θ is the same as Dou et al. (2019).The images X = {x li } conduct T stochastic forward passes on the Q ϕ and C ω by MC sampling to obtain probabilistic predicts {ŷ j li } T j=1 , where the outputs (i.e., probabilistic embeddings) of Q ϕ serve as the inputs for the calculations of L global and L local .The final predicts {ŷ j li } are the expectation of {ŷ j li } T j=1 .The total objectives can be summarized as follows, Discussion.The rationale that our proposed method can benefit DG performance on smalldata scenario can come from two aspects.First, BNN can be adaptive to insufficient data well compared with deterministic models (Graves, 2011;Mallick et al., 2021).For our proposed method, BNN is introduced to the DG problem in the context of insufficient data, where BNN-based feature extractor and classification layers can take both consistent improvements (see 2nd and 3rd columns in Table 4).More importantly, domain-invariant representation learning under this probabilistic framework from global and local perspectives contributes to more robust cross-domain performance (see 4th and 5th columns in Table 4; Figure 3 in Section 4.5 for the effectiveness of P-MMD).

Experiments
We evaluate our proposed method on three medical imaging tasks: 1) epithelium stroma classification, 2) skin lesion classification, 3) spinal cord gray matter segmentation.The used datasets in these tasks are collected from different healthcare institutes and suffer from the domain shift problem in the context of insufficient samples, i.e. insufficient sample scenarios exist either in all or some source domains.
Table 2 Domain generalization results on skin lesion classification.Each column denotes a cross-domain task.For example, in the second column, we use DMF dataset as the target domain and the remaining datasets as the source domains.The best and second-best performance on each target domain are bolded and underlined, respectively.Note that all baseline methods adopt the SWAD method (Cha et al., 2021)  for training.The batch size is 32 for each source domain with 4000 iterations.The hyperparameters are selected in a wide range on the validation set, where the β 1 and β 2 are 0.1 and 0.7 for the L local and the L global , respectively.For the P-MMD, level-1 and level-2 kernels are the Gaussian RBF kernels (the kernel bandwidth is empirically set to 1 for all kernels) by following Muandet et al. (2012).For the P-CSA loss, the distance margin ξ is set to 1.By balancing the performance and computational efficiency, the number of MC sampling in each 1 http://fimm.webmicroscope.net/supplements/epistroma Bayesian layer (a.k.a., T ), is set to 10.We also discuss the influence of using different T in the section 4.5.We report the results based on average value and standard deviation in each target domain by running the experiment for five different times.
Results.Table 1 shows the epithelium stroma classification results on different target domains.We compare with five different approaches.All methods are constructed via a SWAD-based (Cha et al., 2021) framework (where a pretrained ResNet18 as the backbone) with the same training schedule.DeepAll is a deterministic version of our proposed method that is trained on all source domains without any DG strategy in the sequel.Some observations can be summarized as following.First, both our proposed method and BDIL (Xiao et al., 2021) achieve promising results on both IHC and VGH tasks, which may benefit from the positive impact of probabilistic framework on insufficient samples.However, BDIL has an obvious performance drop on the more challenging NKI domain (which has a lower average accuracy compared with other target domains) compared with our proposed method (i.e., 71.89% v.s.76.71%).This may be due to the introduction of global alignment (i.e., P-MMD, as used by ours), which is more powerful for learning domain-invariant representations than only using local negative pairs (as used by BDIL).Second, compared with contrastive semantic alignment-based method (i.e., MSFA (Dou et al., 2019)), our proposed method achieves a significantly better performance (80.45% v.s.88.82% on IHC domain), due to a more reliable distribution-based contrastive learning manner on insufficient samples from all source domains.
Table 3 Domain generalization results on gray matter segmentation task.For the DSC, CC, TPR, and JI, the higher the better.For the ASD, the lower the better.Note that all baseline methods adopt the SWAD method (Cha et al., 2021)  Finally, our proposed method achieves the best average performance with a clear margin compared with other approaches (i.e., LDDG (Li et al., 2020), KDDG (Wang et al., 2021), DNA (Chu et al., 2022), MIRO (Cha et al., 2022), and DSU (Chu et al., 2022)).

Skin Lesion Classification
Seven public skin lesion datasets Results.Table 2 shows the skin lesion classification accuracies on different target domains.Six different methods are utilized for comparison.All approaches are implemented using the SWADbased framework and a pretrained ResNet18 model as the backbone.One has some observations as following.First, compared with contrastive semantic alignment-based method (e.g., MASF), our proposed method provides more reliable distributionbased pairs, leading to a better performance on insufficient samples from some source domains (MASF:0.2692 v.s.Ours: 0.3781 on DMF domain, where PH2 and UDA as the parts of source domain).Second, although BDIL slightly outperforms our proposed method on D7P domain (0.6204 v.s.0.6120), our proposed method has a significantly better performance on the challenging DMF domain (0.2985 v.s.0.3781) and the average results (0.7049 v.s.0.7328) and other domains.Third, it seems that other baseline methods (e.g., SWAD, DNS, and DSU) impose respective schemes to relieve the impact of insufficient samples from some source domains.For example, DSU achieves the best performance on DMF domain.This may be due to the positive impact of straightforward domain randomization.Yet, it is difficult for DSU to realize consistently better results in multiple domains compared with our proposed method, owing to the lack of explicit domain alignment.

Spinal Cord Gray Matter Segmentation
The spinal cord gray matter (GM) segmentation (pixel-level classification) is an emergent task for predicting disability via evaluating the atrophy of GM area.The acquired magnetic resonance imaging (MRI) data are collected from four healthcare centers 3 :"site1" with 30 slices, "site2" with 113 slices, "site3" with 246 slices, and "site4" with 122 slices.One can observe that the insufficient sample problem exists in some source domains, especially in "site1" domain.By following previous work (Li et al., 2020), we randomly split the data of each source domain into a training set (80%) and a test set (20%) and adopt the leave-one-domainout strategy for evaluation.The hyperparameters are selected in a wide range on the validation set, where the β 1 and β 2 are 0.01 and 0.001 for the L local and the L global , respectively.The 2D-Unet 3 http://niftyweb.cs.ucl.ac.uk/challenge/index.php (Ronneberger et al., 2015) is leveraged as the backbone for all methods.The structures of Q ϕ and C ω as well as more experimental details can be found in Appendix B. By following Li et al. (2020), the average results in each target domain are reported by running three times.
Results.Table 3 shows the spinal cord GM segmentation results on different target domains.Dice Similarity Coefficient (DSC), Jaccard Index (JI), and Conformity Coefficient (CC) are used to measure the accuracy of obtained segmentation results.True Positive Rate (TPR) and Average Surface Distance (ASD) are introduced from statistical and distance-based perspectives.We compare with five different methods (which have effective segmentation performance).Some observations can be found as follows.First, our proposed method outperforms all baseline methods in terms of average results for five quantitative metrics.Second, compared with the contrastive semantic alignmentbased method (e.g., MASF), reliable pixel-level pairs constructed by our proposed method also contribute to improving performance in scenarios with insufficient samples from some source domains.Third, as we can see, our proposed method and DSU achieve the best and second-best performance compared with other baselines, which may be reasonable as they can benefit from the modeling of the data uncertainty in the small-data regime using the BNN or the distribution modeling.

Ablation Analysis.
The spinal cord gray matter segmentation task is utilized to explore the effectiveness of each component for our proposed method, due to its various quantitative metrics.The results can be shown in Table 4. First, we observe that better performance can be achieved by introducing a probabilistic layer compared with the results that using Unet, which  reflects the superiority of probabilistic models.Secondly, we observe that by either introducing local or global alignment for domain-invariant information learning, better performance can be achieved compared with the results of only using the probabilistic layer, which shows the effectiveness of the introduced probabilistic feature regularization term.Last but not least, by imposing domaininvariant learning with both local and global views, the performances are further improved, which justifies the effectiveness of our proposed method by jointly considering local and global alignment.
Effectiveness of domain-invariant loss.We are also interested in the impacts of domaininvariant losses on different tasks.Thus, we visualize the learning curves of different task in Figure 3.As we can observe, for the skin lesion (on DMF) and epithelium-stroma (on IHC) classification tasks, the loss curves with iterations reflect the global discrepancy converges faster than the local discrepancy, while the more challenging crossdomain task converges more slowly on global alignment.The mean embedding operation with Euclidean distance is utilized between probabilistic embedding pairs.Kernel Mean Embedding: The kernel mean embedding with MMD distance is utilized between probabilistic embedding pairs.(b) Global alignment.Mean Embedding: The mean embedding operation with MMD distance is utilized between domains (as distributions).Kernel Mean Embedding: The kernel mean embedding with P-MMD distance is utilized between domains (as distributions over distributions).

Further analyses of our proposed method
Results on Different Fractions of Training Data.We are interested in how different fractions of training samples influence the final performance based on small-data scenario.To this end, we adopt skin lesion classification task for evaluation since the number of samples in each domain turns out to be imbalance (some domains such as HAM10000 contain sufficient data while the number of samples in some other domains such as PH2 and UDA is insufficient).As such, we can better simulate the scenario that the issue of insufficient samples either exists in all source domains or in partial source domains.We choose MSK dataset with the secondhighest number of samples as the target domain and the remaining datasets as the source domains (including PH2 and UDA).Table 5 shows the accuracies.As we can see, compared with DNA (with second-best performance on 100% of samples), our proposed method and BDIL have better average results and lower performance attenuation as the decrease of sample number, due to their probabilistic gain under small data scenarios.Compared with BDIL, our proposed method shows a more robust performance on this challenging small data scenario, due to the integration of local (P-CSA) and global (P-MMD) alignments.
Results on Different Numbers of Samples for Training Data.We are also interested in how different numbers of samples per class influence the final performance based on small-data scenarios.To this end, we also adopt skin lesion classification task for evaluation.Specifically, we randomly draw T samples from each class in a source domain to represent this domain for training.Here, we set T to 20,30, and 40, respectively, in different experiments.
The results can be found in Table 6.As we can see, our proposed method achieved the best performance among all settings compared with all baseline methods.Meanwhile, it seems that the Bayesian-based DG approaches (e.g., our proposed method and BIDL) have better performance compared with other methods, which is reasonable as the BNN can be adaptive to the small data scenario well.Especially, our proposed method has around 5% improvements compared with the second-best method when T is set to smaller, i.e., 20.
Kernel Mean Embedding (i.e., P-MMD) v.s.Mean Embedding.We explore the effect of different schemes for probabilistic embeddings.A straightforward method is to represent probabilistic embeddings with the expectation, which is called the "Mean Embedding".Then, a probabilistic embedding can be considered as a latent point and the MMD can be used to measure the discrepancy between distributions consisting of latent points.
For the mean embedding-based L global , the computational process of this scheme for MMD
Here, we validate the effectiveness of different schemes on the NKI task of Epithelium Stroma classification in each aligned view.The experimental settings are similar for different methods.The experimental results can be found in Figure 4.As we can see, our proposed method achieves consistent improvements in each alignment method with different Monte Carlo samples, which may be reasonable as the kernel mean representation can preserve many statistical components due to the injective property.Second, when the number of MC samples is 10, we can observe an obvious margin in global alignment, which refers to the computation between mixture distributions.
Influence of Different Number of MC Samples.It is much important to balance the number of Monte Carlos samples and the computational efficiency.On the one hand, the property of probabilistic embeddings can be affected by the Monte Carlos sampling.On the other hand, too many Monte Carlos samples may suffer from the heavy computational cost.Xiao et al. (2021) suggested that the distributional property and computational cost are both acceptable for the computation of the KL divergence when the number of Monte Carlos samples is chosen appropriately, the practical performance of our proposed method needs to be explored.We conduct the experiments on the NKI task of Epithelium-Stromal classification with different Monte Carlo samples T .
The results are shown in Figure 5.As we can see, if the number of Monte Carlo samples is too small, it is difficult to capture the property of distribution for probabilistic embeddings.As the increase of T , there is an obvious improvement for our proposed method.Interestingly, the performance is gradually saturated.As a result, by balancing the number of Monte Carlos samples and the computational efficiency, the number of Monte Carlos samples T in each Bayesian layer is set to 10.Here, our proposed method is optimized by Adam optimizer with learning rate as 5 × 10 −5 .The batch size for each source domain is 32.The training steps are set to 20000 for PACS and Office-Home, and 2000 for VLCS.By following the SWAD framework, the training process will be stopped for our proposed method when the validation loss increases significantly.The hyperparameters are selected in a wide range on the validation set.For the L local and L global , the β 1 and the β 2 are set to 0.1 and 1 for all benchmark datasets.Other hyperparameters such as kernel function, kernel bandwidth and distance margin are similar to the settings mentioned before.
The experimental results on PACS, Office-Home and VLCS can be shown in Table 7, 8, and 9.As we can see, compared with domaininvariant-based approaches (e.g., DANN), our proposed method has a significant improvement due to the introduction of a probabilistic framework.Our proposed method also outperforms the data augmentation-based approach (e.g., Mixstyle, Manifold Mixup, and CutMix).Although data generation methods (e.g., MixStyle) can effectively tackle the insufficient sample problem via additional generative samples, the lack of effective domain-invariant learning may hamper the improvement of the performance.Our proposed method achieves better performances compared with feature disentanglement-based (e.g., pAdaI).Last but not least, compared with the stateof-the-art domain generalization method (e.g., MIRO), our proposed method achieves comparable performance on small-scale benchmark datasets, which demonstrates the scalability of our proposed method in a small-data regime.

Discussion
Limitation. 1) MC sampling.Our probabilistic embeddings derive from the distribution over the model weights.Similar to widely-used BNN-based models (Blundell et al., 2015;Mallick et al., 2021;Xiao et al., 2021), the predictive distribution of probabilistic embeddings needs to be approximated by MC sampling.This may result in more computational consumption compared with the original deterministic model-based scheme.Although heavy computational consumption can be alleviated in our settings (i.e., DG problem in the context of small data), the computational cost needs to be reduced more on very large-scale datasets in the future.2) Approximate posterior.Although the mean-field variational inference (MFVI) (we used) is effective in rendering an approximate posterior of BNN.The potential amortization gap due to the fully factorized Gaussian assumption of MFVI would limit further performance improvement on very challenging datasets (Cremer et al., 2018).This limitation will be explored by replacing it with more expressive approximate posteriors (such as normalizing flows) in the future.
Tradeoff.In this paper, we carefully make a tradeoff between effectiveness and computational complexity.Specifically, due to the introduction of probabilistic embeddings for the DG problem in the context of insufficient data, the probabilistic MMD is proposed based on the level-2 kernel for more high-level statistics, which may be more complex than other baseline methods with "vanilla" MMD.However, it shows improved effectiveness in addressing the problem of global semantic alignment between domains, consisting of a series of probabilistic embeddings.Other simpler methods may not achieve the same level of performance using just the first moment (i.e., the mean embedding).Moreover, we adopt some strategies, such as the unbiased estimate of MMD with linear complexity and the number selection of appropriate MC sampling, to offset the extra computational complexity compared with other baseline methods.
Usage of our proposed method.Compared with a deterministic framework, where a source domain as a distribution consists of a set of point embeddings, a source domain generated by our probabilistic framework includes a set of distributions, i.e., the so-called distribution over distributions or the probability of probability.The vanilla MMD may not directly cope with this situation.Instead, our proposed P-MMD leverages the level-2 kernel to measure the discrepancy between mixture distributions based on the empirical MMD framework and preserve most information about high-level statistics.
In this paper, we focus on the DG problem in the context of insufficient data.Especially, for the medical imaging data, insufficient sample scenarios either exist in all source domains or in some source domains.If the number of training samples from all source domains is sufficient, it is reasonable to choose another DG method.For instance, the Domain-Net datasets for natural images have six source domains, whereas the source domain ("clipart") with the smallest number of training samples still has 50,000 training samples.Moreover, our proposed method shows good scalability on benchmark datasets with a larger number of samples, although it is designed based on the DG scenario of insufficient data.
Gains of Probabilistic Embeddings.To further show the gain of introducing probabilistic embeddings for insufficient data, we conducted an ablation study on the Epithelium Stroma Classification and Skin Lesion Classification.We only add a Bayesian layer (for probabilistic embeddings) with ReLU layer on the bottom of a deterministic baseline model .
The results can be found in Tables 10.As we can see, consistent improvements can be observed in these small-data tasks due to the introduction of probabilistic embeddings:

Conclusion
In this work, we address the DG problem in the context of insufficient data, which can occur in all or some source domains.To this end, we introduce a probabilistic framework into the DG problem to derive probabilistic embeddings (which can be adaptive to insufficient samples better compared with deterministic models) for domain-invariant learning.Under this probabilistic framework, an extension of MMD called P-MMD is proposed for measuring the distribution over distributions.Moreover, a probabilistic CSA loss is proposed for local alignment.Extensive experiments on insufficient cross-domain medical imaging data show the effectiveness of this method.laye are 64 and 1, respectively.The BayesianTorch can enable to convert ordinary convolutional layer into Bayesian convolutional neural network easily.The Bayesian neural network adopts MFVI to approximate the posterior distribution of weights.The parameters of Bayesian layer are the same as aforementioned settings.The structure of the Bayesian layer in the probabilistic classifier C ω is a Bayesian-based 1 × 1 convolutional layers.The input and output channels are 64 and 1, respectively.The construction of C ω is the same as that of Q ϕ .Here, all methods adopt a two-stage scheme for coarse-to-fine segmentation, as used in (Li et al., 2020).Specifically, we first conduct preliminary segmentation to obtain the spinal cord area from the original 2D slice.Then, we perform elaborative segmentation on obtained spinal cord results to derive gray matter results.
The Adam optimizer is utilized with learning rate as 1 × 10 −4 , weight decay as 1 × 10 −8 .The batch size is 8 for each source domain.The total epochs are 200, where the learning rate will be decreased every 80 epochs with a factor of 10.Other hyperparameters such as kernel function, kernel bandwidth and distance margin are similar to the settings in skin lesion classification and epitheliumstroma classification.The segmentation can be regarded as the pixel-level classification.For the L local and L global , we follow (Motiian et al., 2017) to randomly sample some positive and negative pairs from two domains such that the computational efficiency can be improved significantly.Here, we randomly sample 400 positive and negative pixel pairs from two domains in a mini-batch for the computation of L local , respective.By leveraging selected pixels of a domain in L local , we further utilize these pixels to calculate the L global , which may induce a more accurate measurement owing to the balanced class distribution, as well as reducing the computational cost.

Fig. 1
Fig. 1 Histopathological image examples of breast cancer tissue from three different healthcare institutes, including NKI with 626 images, IHC with 645 images, and VGH with 1324 images.There are two different tissue types, including epithelium and stroma.Obvious domain gaps (e.g., the density of tissue and the staining color) can be observed.

Fig. 2
Fig.2A visualized computational process for probabilistic MMD (P-MMD) on two source domains.The same color for samples in different domains denotes the same label.

Fig. 3
Fig. 3 The loss curve of iteration on skin lesion and epothelial-stromal classficaiton tasks.(a) Global alignment loss (b) Local alignment loss.

Fig. 4
Fig. 4 The performance comparison between mean embedding method and kernel mean embedding method with different Monte Carlo samples T .For each sub-figure, we use only one alignment operation.(a) Local alignment.Mean Embedding:The mean embedding operation with Euclidean distance is utilized between probabilistic embedding pairs.Kernel Mean Embedding: The kernel mean embedding with MMD distance is utilized between probabilistic embedding pairs.(b) Global alignment.Mean Embedding: The mean embedding operation with MMD distance is utilized between domains (as distributions).Kernel Mean Embedding: The kernel mean embedding with P-MMD distance is utilized between domains (as distributions over distributions).

Fig. 5
Fig. 5 The performance of our proposed model on the NKI task of Epithelium Stroma classification with different Monte Carlo samples T .
for weight averaging.The baseline in the sixth row, namely SWAD, denotes the ERM training strategy with the SWAD method.
for weight averaging.The baseline in the sixth row, namely SWAD, denotes the ERM training strategy with the SWAD method.
1 : IHC, NKI, and VGH.After the patching operation, IHC, NKI and VGH datasets respectively have 1342,1230, and 1376 patches, which means that the insufficient sample problem exist in all source domains compared with large-scale natural images.We randomly split the data of each source domain into a training set (80%) and a test set (20%) and adopt the leave-one-domain-out strategy for evaluation.The pretrained ResNet18 is introduced as the backbone.The structure of Bayesian layer in Q ϕ is a fully-connected-based BNN with 512 × 512.The structure of Bayesian layer in C ω is also a fullyconnected-based BNN with 512 × 2. We utilize Adam optimizer with learning rate as 5 × 10 −5 for weight averaging.The baseline, namely SWAD, denotes the ERM training strategy with the SWAD method.

Table 4
Ablation study on each component of our proposed method for spinal cord gray matter segmentation task (where "site2" is as the target domain).The model on the first row denotes the basic Unet model.

Table 5
Domain generalization results on MSK dataset by randomly picking same proportion of samples from each source domain.A smaller proportion (< 40%) is unavailable because equal batch sizes cannot be maintained in PH2 dataset.

Table 6
Domain generalization results on MSK dataset by randomly picking same number of samples from each class in each domain.

Table 10
Ablation study on Epithelium Stroma Classification in Histopathological Images.PE denotes the introduction of probabilistic embeddings.