SlowGuess/NeurIPS_2023_OCR huggingface dataset:
COLOROBJECT. Following Ahmed et al. [1] and Zhang et al. [51], we superimpose objects from 10 classes in MSCOCO dataset onto 10 colors. The RGB values of the predefined colors are: [0, 100, 0], [188, 143, 143], [255, 0, 0], [255, 215, 0], [0, 255, 0], [65, 105, 225], [0, 225, 225], [0, 0, 255], [255, 20, 147], [160, 160, 160]. The object classes are: boat, airplane, truck, dog, zebra, horse, bird, train, bus, motorcycle. Each image has the size  $3 \times 64 \times 64$ , and the dataset sizes are 8000 for the train set and 1000 for validation, ID test, and the two OOD test sets. Since we use two environments in training ( $p_{co} = 0.9$ , 0.7), models see 16000 images during training. In the BACKGROUND-INVARIANCE setting,  $p_{co}$  is set to 0.0. In the OBJECT-DISAMBIGUATION setting,  $p_{co}$  is set to 1.0, and we apply 15 kinds of natural corruption, each with 5 levels of severity, to the foreground images before superimposing them with the backgrounds.
SCENEOBJECT. Following Ahmed et al. [1], Zhang et al. [51], we superimpose objects from 10 classes in MSCOCO dataset onto 10 scene classes in Places dataset. The object classes are the same as COLOROBJECT, and the background scene classes are: beach, canyon, building facade, staircase, desert sand, crevasse, bamboo forest, broadleaf, ball pit, and kasbah. The co-occurrence probabilities  $p_{co}$  are set to 1.0 and 0.7. The image size and dataset sizes are the same as COLOROBJECT as well.
A.2 Model and Training Details
Model Architecture and Hyperparameters. For the synthetic dataset, we use simple MLPs with 3 hidden layers and 5 neurons each hidden layer with ReLU activation. We train each model for 750 epochs with SGD with a learning rate of 0.1. The learning rate is decreased by a factor of 10 every 250 epochs. For COLOROBJECT and SCENEOBJECT, we use Wide ResNet 28 following prior works [49]. To adapt to the 64 by 64 image size, we change the average pooling layer window size from 8 to 16. The learning rate is set to 0.1, which is by a factor of 10 for every 1500 update steps. The model is updated with 4000 steps in total. The batch sizes are 128 and 64 for COLOROBJECT and SCENEOBJECT respectively.
Tuning for Proposed Augmentation Method. We tune the weights for different objectives by fixing  $\alpha_0 = 1$  and  $\alpha_{1} + \alpha_{2} = 1$  so that we can keep the same learning rate. We train on all combinations with a stride of 0.1 for  $\alpha_{1},\alpha_{2}$  (ranging from 0.0 to 1.0). This results in 11 conditions, and we train 10 models with different random seeds. Model checkpoints are selected based on in-distribution validation set accuracy. To pick one condition to report in Sec. Sec. 7 and Table 2, we pick hyperparameter values for which our method matches the performance of the best baseline on one
Figure 6: Framework of RSA. We compute the model RDM and its correlation with the reference RDM, which is used as a metric for factorization. Each cell in the RDM represents the dissimilarity between representations of two images (the value at the position  $(i,j)$  represents the dissimilarity between representations of image  $i$  and image  $j$ ). The diagonal cells represent the dissimilarity of each image with itself, which is always zero.
OOD test while improving on the other (i.e. achieves a Pareto improvement). These hyperparameters are  $\alpha_{1} = 0.7$  and  $\alpha_{2} = 0.3$  in both datasets.
Model Population. For the synthetic dataset, we train 196 models in total. We vary the co-occurrence probability  $p_{co}$  in [0.7, 1.6] and noise level in [0.5, 0.98], yielding 200 environments, and we train one model per environment. For COLOROBJECT and SCENEOBJECT, we train 170 models in total. All methods are trained with 10 random seeds. Therefore, we have 60 models for the 6 baseline methods (ERM, IRM[2], VREx[21], GroupDRO[38], Fish[42], and MLDG[25]). For our proposed augmentation method (see Sec. 7), we fix  $\alpha_{1} + \alpha_{2} = 1$  so that we can keep the learning rate the same. We then vary  $\alpha_{1}$  from 0 to 1 with 0.1 as the intervals and train 10 models for each, which gives us 110 models.
Training Environments. All experiments are conducted using Nvidia RTX 2080 Ti. It takes about half an hour to train one Wide ResNet model. Simple MLPs are trained on CPUs.
B Analysis Details
B.1 Regression Analysis Details
We use 9 factorization metrics and 4 feature weighting metrics to predict OOD performances in a linear regression analysis. We measure the three factorization metrics (linear probing, RSA, and geometric methods) across the 3 blocks of Wide-ResNet and our simply MLPs, giving us 9 metrics in total. We also measure the FPPS metrics across the 3 blocks and the final output probability layer. We use L2 distance for the 3 blocks and KL divergence for the output layer, giving us 4 metrics in total. These metrics are used to predict OOD performances with 10k booststrapping.
Factorization Metrics Details.
1. Linear Probing. We first create foreground-only and background-only images using ID test set data. We then extract model representations and predict the foreground or background class with a linear model. That is, if we have  $n$  foreground classes and  $n$  corresponding background classes in total, we do  $2n$ -way classification. We name this probing method  $probe_{2n}$ . The probing dataset size is therefore 2000, twice the size of the ID test set. We compute average accuracy with 5-fold cross-validation and use it as the measurement of feature factorization.
2. RSA Analysis. We first extract foreground-only and background-only features using ID test data with additional annotation. Then we compute pairwise similarities of the extracted features with Euclidean distance, giving a model Representation Dissimilarity Matrix (RDM) (see Fig. 6 for a visualization). The RDMs have a size of  $n$  by  $n$ , where  $n$  denotes the number of images in
the dataset. The value at position  $(i,j)$  is the Euclidean distance between image  $i$  and image  $j$  in the representational space. The diagonal values represent the dissimilarity of each image with itself, which is always zero. The reference RDM shows an ideal representational geometry. In the case of factorization, we want the images of the same class to have similar representations (dissimilarity=0), while images of different classes to have different representations (dissimilarity=1). Similar to the probing method, foreground and background classes are regarded as different classes in order to test the ability of the models to separate foreground features from background features (e.g. 20 classes in total for our COLOROBJECT and SCENEOBJECT datasets). We then compute the Pearson correlation between the model RDM and the reference RDM and use the  $r$  number as a metric for factorization. Note that since we do not normalize the model RDM, the absolute value of  $r$  is meaningless. In a regression analysis where we are trying to predict OOD generalization, the relative differences among the  $r$  values are what matters.
3. Geometric Analysis. Following Lindsey and Issa [28], we compute the factorization of foregrounds against backgrounds as factorization  $f_{g} = 1 - \frac{\mathrm{var}_{fg|bg}}{\mathrm{var}_{fg}}$ , where  $\mathrm{var}_{fg}$  denotes the variance in the representation space induced by foreground perturbations and  $\mathrm{var}_{fg|bg}$  denotes the variance induced by foreground perturbations within the background subspace.
To get  $\mathrm{var}_{fg}$ , we compute the variance induced by the foreground perturbations. Specifically, for each of the 1000 test background images, we pair it with 100 random foregrounds and obtain model representations for each combined image. For each background image, we compute the scalar variance induced by the 10 random foregrounds by first computing the variance within each vector dimension and then summing over all dimensions. Then we average this per-background-image variance over the 1000 backgrounds to get  $\mathrm{var}_{fg}$ . Second, to compute  $\mathrm{var}_{fg|bg}$ , we need to find a subspace for background information. To do so, we use the same set of background images paired with 10 random foreground images. We obtain a special set of background representations from 1000 test background images, each paired with 10 random foregrounds. The representations are the average model representation per background image, averaged across the image's 10 random foregrounds. Then, we conduct PCA on this set of representations, and we select the top- $k$  principal components to get a subspace  $U_{bg}$  that explains  $99\%$  of the variance in the representations. Finally, to get  $\mathrm{var}_{fg|bg}$ , we project the representations of the 100,000 background plus random foreground images (same as used to compute  $\mathrm{var}_{fg}$ ) into the background subspace. For these projected representations, we repeat the process of computing a single scalar variance (as with  $\mathrm{var}_{fg}$ ) to obtain the variance induced by foreground perturbation in the background subspace,  $\mathrm{var}_{fg|bg}$ .
B.2 Causal Analysis Details
Manipulating Factorization We first compute the top- $k$  PCs of the mean representation of each foreground class so as to explain  $99\%$  of the variance, referred to as the inter-class PCs  $U_{inter}$ . Specifically, for each class, we have 100 foreground images, each randomly paired with 100 backgrounds. The mean representation of each class (class center) is the average representation of the 10000 images. Then we also computed the PCs of the data with corresponding class centers subtracted from each activity pattern, referred to as the intra-class PCs  $U_{intra}$ . Specifically, for each datapoint  $\mathbf{x}$ , we subtract its corresponding class center from it:  $\mathbf{x}' = \mathbf{x} - c_i$ , where  $c_i$  is its class center. Then we compute  $U_{intra}$  with all subtracted datapoints. Then, we transformed the data by applying to the class centers a change of basis matrix that rotated each inter-class PC into the corresponding (according to the rank of the magnitude of its associated eigenvalue) intra-class PC:  $U = (U_{intra}[: num\_of\_classes])^T * U_{inter}$ , where  $U$  is the desired transformation, the rows of  $U_{inter}$ ,  $U_{intra}$  are sorted according to their eigenvalue, and num_of_classes is the number of classes (10 in our cases). We limit the intra-class PCs to its top-num_of_classes PCs since the number of classes is much smaller than the dimensionality of the extracted features and  $U_{inter}$  has much fewer rows than  $U_{intra}$ . This transformation has the effect of decreasing factorization while controlling for all other statistics of the representation that may be relevant to object classification performance (like invariance). Finally, after transforming the data by  $\mathbf{x} * U^T$ , we can measure the OOD performances and the factorization metrics and observe the causal relationship between them.
Manipulating Feature Weighting. To manipulate feature weighting, we first compute the subspace of interest (foreground or background) using PCA. Specifically, similar to the geometric method of measuring factorization, we compute the average representations of foreground/background images by averaging it over 100 images paired with random backgrounds/foregounds. We then conduct
Table 3: OOD evaluation for baseline models. OOD1 refers to BACKGROUND-INVARIANCE, while OOD2 refers to OBJECT-DISAMBIGUATION. Prior methods focusing on learning causal features consistently improve generalization on BACKGROUND-INVARIANCE settings, but are unhelpful or even hurt performances on OBJECT-DISAMBIGUATION settings. Confidence intervals are one standard deviation across 10 seeds.
COLOROBJECT	SCENEOBJECT
ID Acc	OOD1 Acc	OOD2 Acc	ID Acc	OOD1 Acc	OOD2 Acc
ERM	87.15±0.40	29.11±3.39	95.24±0.83	72.28±0.93	35.37±1.97	71.93±1.27
IRM	87.10±0.58	31.68±1.70	94.15±0.82	71.53±0.69	34.33±0.97	70.98±1.37
VReX	87.60±0.48	36.38±3.16	92.65±0.77	72.01±0.56	35.43±1.15	71.27±1.09
GroupDRO	87.47±0.70	40.92±3.72	90.58±2.06	69.71±0.67	34.18±0.96	68.19±1.15
Fish	88.48±0.85	41.13±7.27	92.65±2.37	73.47±0.79	36.91±1.49	71.30±0.74
MLDG	87.90±0.39	36.54±2.63	93.30±1.92	73.79±0.63	36.59±1.01	72.26±0.82
PCA on the average representations for both the foregrounds  $(U_{fg})$  and the backgrounds  $(U_{bg})$ . Then, we compute the importance relative to a subspace of interest (foreground or background)  $e_i$  for each feature  $\mathbf{x}_i$  in the original space, where  $i$  is the index of the feature. To do so, we sum up the absolute weights in the PCA transformation matrix weighted by the ratio of variance explained:  $e_i = \sum_j U_{fg}[j,i] * \sqrt{r_j}$ , where  $U_{fg}[j,i]$  refers to the  $i$ -th weight of the  $j$ -th PC component and  $r_j$  refers to the ratio of variance explained by the  $j$ -th PC component. We then normalize  $e_i$  and multiply them by a factor  $g$  to get the boost weights for each feature in the original space. Finally, we get the boosted feature  $\mathbf{x}_{boosted} = \mathbf{x} * e * g$ .
Since changing the variance of the data already has an effect on the accuracy of a linear classifier because of the L2 regularization, we control for this effect by computing the accuracy of boosting all features uniformly:  $\mathbf{x}_{control} = \mathbf{x} * g$ . We report the differences in 5-fold cross-validation performances of linear classifiers trained on  $\mathbf{x}_{boosted}$  versus  $\mathbf{x}_{control}$ . Note that if the foreground and background subspaces are overlapping, then boosting one will boost the other as well. But as long as the two subspaces are not completely overlapping, we can boost or decrease one of them more than the other.
C.1 OOD Evaluation
Methods focusing on learning causal features improve performance on BACKGROUND-INVARIANCE but lower performance on OBJECT-DISAMBIGUATION. As shown in Table 3, methods designed to learn causal features (e.g. IRM, VREx, GroupDRO, Fish, and MLDG) demonstrate improved performance in the BACKGROUND-INVARIANCE setting, but they significantly hurt OBJECT-DISAMBIGUATION performance on COLOROBJECT compared to ERM and four of five lower performances on SCENEOBJECT.
OOD Evaluation with various training sizes. We evaluate performances with various training sizes (4k, 8k, 16k). As shown in Figure 7(a), we see clear Pareto frontiers across various training sizes. In addition, the Pareto frontiers move outwards as the training size gets larger. With 8k data, the frontier is close to the frontier with 16k data, suggesting that the frontier is close to saturation and that our argument is unlikely to be restricted by our training size.
OOD Evaluation on transformer architecture. We also evaluate performances on vision transformers (Swin-tiny) on the two OOD settings in SCENEOBJECT [30]. Since applying domain generalization methods (like Fish) to transformers requires a significant amount of hyperparameter tunings, we only evaluate a population of models trained with our augmentation method and baseline ERM. As shown in Figure 7(b), we see clear trade-offs between BACKGROUND-INVARIANCE and OBJECT-DISAMBIGUATION for Swin-tiny, despite that they have significantly better performances than ResNets. This suggests that our argument is unlikely to be restricted to particular architecture choices.
(a) Pareto Frontier with Various Training Sizes
(b) Pareto Frontier with Vision Transformers
Figure 7: Pareto frontier on ScENEOBJECT. We see clear trade-offs between BACKGROUND-INVARIANCE and OBJECT-DISAMBIGUATION across different training sizes (4k, 8k, 16k) and for vision transformers (Swin-tiny) [30].
Performances Across Different Levels of OOD. We present the results of baseline models (ERM, IRM, VREx, GroupDRO, Fish, and MLDG) across varying degrees of OOD settings in Fig. 8. For BACKGROUND-INVARIANCE, we run tests on varying levels of  $p_{co} = 0.6$ , 0.45, 0.3, 0.15, 0.0. Here, 0.0 is the setting that we report in all other sections. Importantly, all these settings are considered OOD as the training environment  $p_{co}$  is always at least 0.7. For OBJECT-DISAMBIGUATION, we present results on five distinct levels of corruption. The level of corruption here refers to the severity of the deviation from the original distribution, where a higher level signifies a more extreme corruption. We report the mean performance across these five levels in all other sections of this study. Across these diverse OOD settings, we observe that the performance of each model decreases as the settings become increasingly OOD. Consistent across different levels of OOD, other baselines can improve over ERM in BACKGROUND-INVARIANCE, but generally hurts the performance in OBJECT-DISAMBIGUATION, highlighting a need to design systems that generalize across both OOD settings, similar to biological vision.
C.2 Regression Analysis
Full Regression Results. We use 9 factorization metrics and 4 feature weighting metrics in total for our regression analysis. We use all metrics, together with the ID accuracy and model objectives, to predict OOD generalization. To visualize our regression analysis results, as shown in Fig. 9, we combine all metrics into one single metric that correlates strongly with the average OOD performance. This single metric is obtained by combining all metrics with weights from the linear regression that predicts the average OOD accuracy. The Pearson correlation between the average OOD accuracy and the combined metrics has  $r$  values of 0.926, 0.986, 0.952 for the synthetic dataset, COLOROBJECT, and SCENEOBJECT respectively. The regression weight and  $p$  value for each individual metric are shown in Table 5. Note that different metrics have different scales, so the absolute values of the coefficients are not comparable to each other. The bold numbers are ones with  $p$ -values smaller than 0.05. ID accuracy, as well as our feature weighting metrics FBPS, is important in all three datasets for predicting OOD generalization. All three kinds of metrics of feature factorization are useful in some cases (the RSA and geometric methods in COLOROBJECT and the probing method in SCENEOBJECT). As shown in Table 4, our factorization and feature weighting metrics significantly improve the ability to predict performances in all three settings: BACKGROUND-INVARIANCE, OBJECT-DISAMBIGUATION, and average OOD.
Feature Weighting Results on COLOROBJECT. We observe the same trend in SCENEOBJECT (in Fig. 10) as in SCENEOBJECT (in Fig. 4). As models weigh foreground features more, the performance increases in BACKGROUND-INVARIANCE and decreases in OBJECT-DISAMBIGUATION, resulting in an initially increasing and subsequently decreasing average OOD performance.
Figure 8: Performances across Different Levels of OOD settings. Confidence intervals are one standard deviation across 10 random seeds. As the test sets become more OOD, the performances for all methods drops (training co-occurrence is 0.7, e.g.). Other baselines sometimes improve in BACKGROUND-INVARIANCE, but consistently hurt the performances in OBJECT-DISAMBIGUATION.
Table 4:  $R^2$  for the regression analysis between metrics and BACKGROUND-INVARIANCE, OBJECT-DISAMBIGUATION, and the average OOD accuracy. Confidence intervals are one standard deviation over 10k bootstrapping. Bold numbers are  $p < 0.05$  with independent t-test.
Metric	COLOROBJECT	SCENEOBJECT
OOD1	OOD2	Avg OOD	OOD1	OOD2	Avg OOD
ID Acc	0.162±0.137	0.067±0.118	0.191±0.150	0.238±0.122	-0.036±0.078	0.691±0.091
+ Obj.	0.505±0.095	0.413±0.103	0.505±0.106	0.271±0.121	0.012±0.104	0.696±0.084
+ Factor.	0.952±0.014	0.900±0.030	0.925±0.023	0.780±0.060	0.798±0.048	0.838±0.044
+ Ft. Wgt.	0.981±0.006	0.856±0.033	0.961±0.013	0.977±0.006	0.905±0.027	0.857±0.043
+ All	0.985±0.004	0.915±0.024	0.963±0.010	0.978±0.006	0.936±0.021	0.868±0.041
C.3 Causal Analysis
Causal Analysis Results on COLOROBJECT. For the causal analysis on factorization in COLOROBJECT, we see a similar trend to SCENEOBJECT in that both the factorization (as measured by the geometric method) and the BACKGROUND-INVARIANCE performance decrease significantly. However, the OBJECT-DISAMBIGUATION accuracies remain the same as opposed to increasing. This is because the decoding accuracies of linear classifiers on backgrounds are near the ceiling  $(100\%)$  both before and after the causal intervention, which is a result of the backgrounds (10 pure colors) being too easy to decode. For the causal analysis on feature weighting in COLOROBJECT, we observe the same trend as in SCENEOBJECT: when we decrease the foreground (or background) features, the BACKGROUND-INVARIANCE performances decrease (or increase) while the OBJECT-DISAMBIGUATION performances increase (or decrease). All results are significant (paired t-test  $p < 1\mathrm{e} - 3$ ).
ERM Other Baselines
Figure 9: Correlation between combined metrics and combine OOD performance. A dot donates a model. The  $x$  axis is the combined metrics, including ID accuracy, objectives, and all factorization and feature weighting metrics. These metrics are combined with weights from a linear regression. The  $y$  axis is the average OOD performance from the two settings. The green lines are fit by linear regressions, and the shaded areas are  $95\%$  confidence intervals. We can observe strong correlations between the combined metrics and the combined OOD performances across the two datasets.
Table 5: Regression Weight and  $p$  Value. We have 9 metrics for measuring factorization and 4 metrics for feature weighting. The  $p$ -values are put in brackets. Confidence intervals are one standard deviation across 10k bootstrapping. Bold numbers are ones with  $p$ -value smaller than 0.05. Note that different metrics have different scales, so the absolute values of the coefficients are not directly comparable.
Regression Coefficients & p-value
Synthetic	COLOROBJECT	SCENEOBJECT
ID Acc	0.044±0.039 (p=0.242)	1.803±0.152 (p=0.000)	0.782±0.059 (p=0.000)
probing_layer1	-0.057±0.019 (p=0.005)	-0.151±0.108 (p=0.160)	-0.027±0.029 (p=0.357)
probing_layer2	0.039±0.030 (p=0.179)	-0.200±0.104 (p=0.060)	0.128±0.038 (p=0.001)
probing_layer3	-0.008±0.026 (p=0.762)	-0.013±0.117 (p=0.907)	0.338±0.053 (p<0.001)
RSA_layer1	0.126±0.025 (p<0.001)	0.172±0.039 (p<0.001)	-0.071±0.049 (p=0.140)
RSA_layer2	-0.010±0.027 (p=0.714)	-0.031±0.033 (p=0.355)	-0.108±0.035 (p=0.003)
RSA_layer3	0.218±0.034 (p<0.001)	-0.021±0.036 (p=0.558)	0.214±0.062 (p=0.001)
geometric_layer1	0.040±0.010 (p<0.001)	-0.487±0.090 (p<0.001)	-0.130±0.149 (p=0.368)
geometric_layer2	0.020±0.007 (p=0.004)	-0.012±0.041 (p=0.769)	-0.310±0.230 (p=0.173)
geometric_layer3	-0.021±0.012 (p=0.075)	0.191±0.084 (p=0.025)	-0.174±0.112 (p=0.120)
FBPS_L2_layer1	0.009±0.008 (p=0.262)	0.001±0.001 (p=0.439)	0.047±0.008 (p<0.001)
FBPS_L2_layer2	0.010±0.007 (p=0.157)	-0.001±0.001 (p=0.156)	-0.009±0.008 (p=0.287)
FBPS_L2_layer3	0.004±0.002 (p=0.070)	-0.099±0.041 (p=0.025)	0.732±0.215 (p=0.002)
FBPS_KL_output	-0.364±0.014 (p<0.001)	0.375±0.019 (p<0.001)	0.055±0.036 (p=0.123)
Feature Weighting Manipulation Across Different Boost Factor. When decreasing the foreground features, as the boost factor gets smaller, BACKGROUND-INVARIANCE performances decrease more while OBJECT-DISAMBIGUATION performances increase more in both datasets. Conversely, when decreasing the background features, as the boost factor gets smaller, BACKGROUND-INVARIANCE performances increase more while OBJECT-DISAMBIGUATION performances decrease more in both datasets. However, when increasing the feature importance in either foreground or background subspaces, the performances never deviate significantly from the control experiments. We suspect that this is because when boosting the subspaces, the resulting weights of the linear classifiers are smaller, and thus the regularization that penalizes larger weights will have a weaker effect.
C.4 Proposed Augmentation Method
Augmentation using pseudo-masks generated by Segment-Anything (SAM). We also experiment with using the pseudo-masks generated by SAM to alleviate the need for additional annotations. However, since SAM over-generates masks, we cross-check the pseudo-masks with ground-truth masks by selecting the highest IoU. This process should be easily automated with methods like Lai