{'fraction_non_alphanumeric': 0.03944989054915771, 'fraction_numerical': 0.01341962501189683, 'mean_word_length': 5.105461940732132, 'pattern_counts': {'":': 0, '<': 0, '<?xml version=': 0, '>': 2, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
MaxStyle: Adversarial Style Composition for Robust Medical Image Segmentation

Convolutional neural networks (CNNs) have achieved remarkable segmentation accuracy on benchmark datasets where training and test sets are from the same domain, yet their performance can degrade significantly on unseen domains, which hinders the deployment of CNNs in many clinical scenarios. Most existing works improve model out-of-domain (OOD) robustness by collecting multi-domain datasets for training, which is expensive and may not always be feasible due to privacy and logistical issues. In this work, we focus on improving model robustness using a single-domain dataset only. We propose a novel data augmentation framework called MaxStyle, which maximizes the effectiveness of style augmentation for model OOD performance. It attaches an auxiliary style-augmented image decoder to a segmentation network for robust feature learning and data augmentation. Importantly, MaxStyle augments data with improved image style diversity and hardness, by expanding the style space with noise and searching for the worst-case style composition of latent features via adversarial training. With extensive experiments on multiple public cardiac and prostate MR datasets, we demonstrate that MaxStyle leads to significantly improved out-of-distribution robustness against unseen corruptions as well as common distribution shifts across multiple, different, unseen sites and unknown image sequences under both low- and high-training data settings. The code can be found at https://github.com/cherise215/MaxStyle.


Introduction
Convolutional neural networks have demonstrated remarkable segmentation accuracy on images that come from the same domain (e.g. images from the same scanner at the same site), yet they often generalize poorly to unseen out-ofdomain (OOD) datasets, which hinders the deployment of trained models in real-world medical applications. The performance degradation is mainly caused by the distribution mismatch between training and test data, often originating from the change of vendors, imaging protocols across different hospitals as arXiv:2206.01737v2 [eess.IV] 19 Jun 2022 well as imperfect acquisition processes which affect image quality. To alleviate this problem, a group of works focus on learning domain-invariant features with multi-domain datasets [1][2][3][4]. However, collecting and labeling such large datasets can be extraordinarily time-consuming, expensive, and not always feasible due to data privacy and ethical issues. In this work, we consider a more realistic yet more challenging setting: domain generalization from a single source only.
A straightforward solution to improve domain robustness is data augmentation, which transforms and/or perturbs source domain data to resemble unseen data shifts [5][6][7][8]. Existing works mainly consider directly perturbing the input space, which in general requires domain knowledge and expertise to design the perturbation function [7]. Very few approaches investigate feature augmentation possibly due to the risk of perturbing semantic content of images. Perturbing features might change semantic attributes such as anatomical structures, which are essential for precise segmentation. An exception is MixStyle [9], which conducts content-preserving feature augmentation by randomly interpolating two samples' feature style statistics. However, there are several limitations with MixStyle: 1) difficulty in visualizing and interpreting augmented features in the high-dimensional space, 2) limited diversity of augmented styles due to the linear interpolation mechanism, 3) sub-optimal effectiveness for model robustness as it does not take the network's vulnerability into account at training.
In this work, we propose a novel data augmentation architecture, where an auxiliary image decoder is attached to a segmentation network to perform selfsupervised image reconstruction and style augmentation. Such a design not only improves the interpretability of style augmented examples but also forces the network to learn auxiliary reconstructive features for improved out-of-domain robustness (Sec. 3.2). We further propose an enhanced style augmentation method: MaxStyle, which maximizes the effectiveness of style augmentation for model OOD performance (Sec. 3.3). Different from MixStyle, we expand the style space with additional noise and search for the worst-case style composition for the segmentor via adversarial training. Through extensive experiments, we show that MaxStyle achieves competitive robustness against corruptions and improves robustness against common distribution shifts across different sites and different image sequences (Sec. 4.3).

Related work
Style transfer: Style transfer modifies the visual style of an image while preserving its semantic content. Previous works on style transfer mainly focus on designing advanced generative adversarial networks (GAN) for improved image diversity and fidelity under the assumption that a large-scale dataset with diverse image styles is available [10,11]. Recent findings show that domain shift is closely related to image style changes across different domains [9,12] and can be alleviated by increasing the diversity of training image styles [9,[13][14][15][16][17]. One such successful example is MixStyle [9], which generates 'novel' styles via simply linearly mixing style statistics from two arbitrary training instances from the same domain at feature level. DSU [15] augments feature styles with random noise to account for potential style shifts. Compared with MixStyle and DSU, our proposed method, MaxStyle does not only span a larger area in the feature style space but also covers harder cases. Adversarial data augmentation: Adversarial data augmentation focuses on generating data samples that fool the network to predict the wrong class [18,19]. Such an approach can improve robustness against adversarial and natural corruptions [18,20], and has shown promise for improved model generalization [7,8,17,[21][22][23]. Most methods apply adversarial perturbation to the input space to improve unseen domain performance, e.g., adversarial noise [22][23][24], and adversarial bias field [7]. Fewer explore feature space perturbation. Huang et al. proposed to adversarially drop dominant features (RSC) during training as a way to improve cross-domain performance [25]. Chen et al. proposed to project masked latent features back to input space in an adversarial manner for improved interpretability and effectiveness [8]. Our method follows this feature-to-input space data augmentation mechanism, but restricts the adversarial perturbation at the style level, generating style-varying, shape-preserving hard examples.

Preliminaries: MixStyle
As mentioned before, MixStyle [9] is a feature augmentation method for improving model generalization and robustness, which perturbs feature style statistics to regularize network training. Formally, let f i , f j ∈ R c×h×w be c-dimensional feature maps extracted at a certain CNN layer for image x i and image x j , respectively. MixStyle performs style augmentation for f i by first normalizing it with its channel-wise means and standard deviations µ and then transforming the feature with a linear combination of style statistics i : {σ(f i ), µ(f i )} and j : {σ(f j ), µ(f j )}. This process can be defined as: (1) where denotes element-wise multiplication; λ mix is a coefficient controlling the level of interpolation, randomly sampled from [0, 1]. Acting as a plug-andplay module, MixStyle can be inserted between any CNN layers. It is originally designed as an explicit regularization method for a standard encoder-decoder structure, which perturbs shallow features (e.g., features from the first three convolutional blocks) in an image encoder E θ parametersied by θ, see Fig. 1. A segmentation decoder D φs then performs prediction with the perturbed highlevel representationẑ. The whole network is optimized to minimize the segmentation loss L seg (D φs (ẑ), y), supervised by the ground-truth y. Fig. 1: A) the original use of MixStyle as feature augmentation-based regularization method with a standard encoder-decoder structure. B) MixStyle applied to regularize a dual-branch network with an auxiliary image decoder D φi attached for image reconstruction. C) We propose to apply MixStyle in the auxiliary decoder D φi to generate stylized images for feature-to-input space data augmentation instead (MixStyle-DA), which leads to improved model robustness across different OOD test data, compared to A, B (sebottom). GT: ground-truth.

Robust feature learning and improved interpretability with auxiliary image decoder
In this work, for improved OOD robustness and better interpretability of style augmentation, we propose to adapt the standard encoder-decoder to a dualbranch network with an auxiliary image decoder D φi attached, see Fig. 1B,C. The network is supervised with an additional image reconstruction loss L rec (x, x), allowing itself to exploit both complementary image content features and taskspecific shape features for the segmentation task [8]. We further propose to insert the style augmentation layers in the image decoder D φi (Fig. 1C) rather than in the encoder E θ (Fig. 1B), allowing to generate diverse stylized images with the same high-level semantic features z for direct data augmentation. Such a design also improves the interpretability of feature style augmentation. More importantly, our experimental results show that C > B > A in terms of OOD robustness, see Fig. 1 (bottom) and Fig. S1 (supplementary). The segmentation network trained w/ approach C is more robust against corruptions and unseen domain shifts across different sites and different image sequences. We name this new method as 'MixStyle-DA' to differentiate it from the original one. We believe this data augmentation-based approach is preferred for model robustness as it tackles model over-fitting from the root, limited training data.

MaxStyle
On top of the dual-branch architecture with the data augmentation strategy presented above (Fig. 1C), we propose MaxStyle, a novel method that consists of both style mixing and noise perturbation, improving the diversity and sample hardness. As visualized in Fig. 2(a), we introduce additional style noise to expand the style space and apply adversarial training in order to find optimal linear coefficients as well as to generate adversarial style noise for effective data augmentation. Specifically, given feature f i extracted at a certain CNN layer in the image decoder D φi with x i as input, MaxStyle augments f i via: where the normalized feature f i is transformed with mixed styles γ mix , β mix (Eq. 1) plus additional style noise Σ γ · γ , Σ β · β ∈ R c to better explore the space of possible unknown domain shifts. In order to bound the style noise within a reasonable range, similar to [15], we sample the style noises from a re-scaled Gaussian distribution with variance Σ γ , Σ β ∈ R c estimated from a batch of B instances' style statistics (including Style optimization via adversarial training: The generated noise γ , β and the style mixing coefficient λ mix are then updated by maximizing the segmentation loss L seg so that the synthesized imagex = D φi (E θ (x); γ , β , λ mix ) 7 could fool the network to produce an incorrect predictionp = D φs (E θ (x)). Gradient ascent is employed to update the underlying style-related parameters: λmix ← Clip [0,1] (λmix + α∇ λ mix Lseg(p, y)).
Here α denotes the step size. We clip the value of λ mix to ensure it lies in [0, 1]. To summarize, training with MaxStyle augmentation can be then written as minimax optimization using the training set D: x as input for network optimization x * as input for network optimization The whole network is optimized using both input image x and its style augmented imagex * , minimizing the multi-task loss: segmentation loss L seg and image reconstruction loss L rec . Herex * = D φi (E θ (x); λ * mix , * γ , * β ) is generated using optimized style parameters. An example of MaxStyle generated images is shown in Fig. 2b. The network is fooled to under-segment the style-augmented imagex * although the underlying target structures remain almost the same. More examples are provided in the supplementary. Of note, MaxStyle is suitable for general segmentation networks thanks to its plug-and-play nature and the attached decoder can be removed at test time.

Data: Cardiac MR segmentation datasets
a) Single source domain: The public ACDC dataset [26] is used for network training and intra-domain test, which contains 100 subjects (bSSFP sequences) collected from a single site. We randomly split the dataset into 70/10/20 for training/validation/intra-domain test.To simulate common clinical scenarios where the training data is far less than testing data, we randomly selected 10 subjects (10 out of 70) for training and repeated experiments three times. We also validated our method using all 70 training subjects following [8]. b) Multiple unseen test domains: We collated several public datasets where each capture different types of distribution shift or quality degradation for comprehensive OOD performance evaluation. They are 1) ACDC-C for robustness against imaging artefacts evaluation. Following [8], we synthesized a corrupted version of the ACDC test set where each test image has been randomly corrupted by one of four, different types of MR artefacts, three times for each artefact type, using TorchIO toolkit [27]; ACDC-C contains 240 (20 × 3 × 4) subjects in total; 2) a large cross-site test set with real-world distribution variations. It consists of 195 subjects (bSSFP sequences) across four, different sites, which are from two public challenge datasets: M&Ms [28], MSCMRSeg [29]; 3) cross-sequence test set, which consists of 45 LGE sequences from MSCMRSeg [29]. Detailed information can be found in the Supplementary. We employed the image preprocessing and standard data augmentation (incl. common photo-metric and geometric image transformations) described in [8] as our default setting.

Implementation and experiment set-up
We adopted the dual-branch network presented in [8] as our backbone, which has demonstrated state-of-the-art robustness on the cardiac segmentation task. We applied MaxStyle layers to shallow features in D φi for optimal performance, i.e. inserted after each of the last three convolutional blocks. Each layer is activated at a probability of 0.5 and batch features at each layer are randomly shuffled for style mixing to trade-off diversity and strength as suggested by [9]. For the adversarial style optimization, we randomly sample λ mix from the uniform distribution U [0,1] and γ,β from N (0, 1). Adam optimizer was adopted for both style optimization and network optimization. We empirically set α = 0.1 with 5 iterations, yielding sufficient improvement. For network optimization, we set learning rate = 1e −4 and batch size = 20, following [8]. For cardiac small training set, we trained the network for 1,500 epochs to ensure convergence. For larger training data, 600 epochs were sufficient. We employed mean squared error loss for L rec and cross-entropy loss for L seg . We compare our method with the baseline (w/o MaxStyle augmentation) and competitive random and adversarial augmentation methods using the same network and the same multi-task loss, including: a) input space augmentation: RandConv [6], adversarial noise (Adv Noise) [24], and adversarial bias field (Adv Bias) [7]; b) feature augmentation: RSC [25], MixStyle [9], DSU [15]; c) feature-to-input space data augmentation via decoder D φi : latent space masking (LSM) [8]. All methods were implemented in PyTorch with their recommended set-ups.

Results
Results of models trained with cardiac low data regime and high data regime are provided Table 1. We also plot the segmentation results in Fig. 3 for visual comparison. From the results, we see that MaxStyle outperforms all baseline methods across all OOD test sets with different types of domain shifts, providing the largest improvements in both low-and high-data training regimes (+25%, +11%). In particular, MaxStyle significantly improves the segmentation performance on the most challenging cross-sequence dataset with the largest domain shift. By generating images with challenging styles during training, MaxStyle forces the model to be more shape-biased rather than texture/style-biased, which is beneficial for model robustness [30]. To provide additional insights of MaxStyle, we also provide t-SNE visualization of latent feature embeddings in the supplementary. We also found that the model trained w/ MaxStyle using 10 ACDC subjects even achieves higher OOD performance than the baseline model trained w/ 70 subjects (0.7420 vs 0.7287), suggesting MaxStyle's superior data efficiency. In addition to cardiac segmentation, we also validate our method on public prostate segmentation datasets [2,3,[31][32][33][34] to test the generality of our method for medical image segmentation. MaxStyle also achieves the top OOD performance against the competitive methods across six, different, unseen test sites. Datasets details and results are shown in the supplementary.  Ablation study: We highlight the importance of increased style diversity via composing style mixing and style noise as well as improved style hardness with adversarial training in the ablation study. Results are shown in Table 2. It can be observed that removing each component leads to performance degradation.

Discussion and conclusion
We introduced MaxStyle, which is a powerful plug-in data augmentation module for single domain generalization. It attaches an auxiliary style-augmented image decoder to a segmentation network for image reconstruction and style augmentation. MaxStyle is capable of generating stylized images with improved diversity and hardness, forcing the network to learn robust features for domain generalization. From the causal perspective [35], the image decoder with MaxStyle can be viewed as a latent data generation process with multi-scale style interventions, conditioned on the extracted high-level causal variables (e.g., content and style). By explicitly feeding the network with images of diverse 'hard' styles, the spurious correlation between image style and labels are weakened. The network thus gains the ability to resist unseen distributional shifts. We also highlighted the importance of combining both reconstructive features and discriminant features for robust segmentation (Sec. 3.2), which is in line with classical robust subspace methods [36]. We validated MaxStyle's efficacy on both cardiac datasets and prostate datasets across various unseen test sets, demonstrating its superiority over competitive methods under both low-and high-data training regimes. It is worth mentioning here that our method does not necessarily sacrifice the IID performance. On the prostate segmentation task, our method can significantly improve the IID performance compared to the baseline method (0.8597 vs 0.8277, see Table S3). For the cardiac segmentation task, the IID performance slightly drops (e.g, 0.8104 vs 0.8108). We hypothesize that the IID performance degradation is task and dataset-dependent. Like other adversarial data augmentation methods [18,24], the main limitation of MaxStyle is that the improved robustness comes at the cost of longer training time due to the adversarial optimization procedure, e.g. increased by a factor of ∼ 1.8 in our case. We hope that MaxStyle will enable more data-efficient, robust and reliable deep models. Integrating MaxStyle into composite data augmentation frameworks [37] would be an interesting direction. ACDC [26]+TorchIO [27] M&Ms [28] M&Ms [28] M&Ms [28] MSCMRSeg [29] MSCMRSeg [29] Fig. S1: Cardiac intra-domain and out-of-domain segmentation performance of networks trained with the three approaches presented in Fig.1. The feature-to-input space data augmentation-based (C) clearly outperforms feature augmentation based ones (A,B) on the out-of-domain test data, especially on the most challenging cross-sequence test set. Models were trained under the cardiac low training data regime.    Table S3: Evaluation results on the prostate intra-domain and unseen cross-site test sets. Models were all trained using the same setting for fair comparison, e.g., the same backbone dual-branch network, the same multi-task loss with an Adam optimizer (batch size= 20 learning rate= 1e −4 , 600 epochs).  Table S4: The effect of the number of iterations for style optimization (n iter ). Reported values are mean (std) Dice scores over ten test (sub) sets using models trained under the high-data training setting. MaxStyle is stable with respect to different iterations. The segmentation performance reaches the best results when performing 5 iterations (our default setting) for style optimization.