Abstract: Real-world applications of machine learning models often confront data distribution shifts, wherein discrepancies exist between the training and test data distributions. In the common multi-domain multi-class setup, as the number of classes and domains scales up, it becomes infeasible to gather training data for every domain-class combination. This challenge naturally leads the quest for models with Compositional Generalization (CG) ability, where models can generalize to unseen domain-class combinations. To delve into the CG challenge, we develop CG-Bench, a suite of CG benchmarks derived from existing real-world image datasets, and observe that the prevalent pretraining-finetuning paradigm on foundational models, such as CLIP and DINOv2, struggles with the challenge. To address this challenge, we propose Compositional Feature Alignment (CFA), a simple two-stage finetuning technique that i) learns two orthogonal linear heads on a pretrained encoder with respect to class and domain labels, and ii) fine-tunes the encoder with the newly learned head frozen. We theoretically and empirically justify that CFA encourages compositional feature learning of pretrained models. We further conduct extensive experiments on CG-Bench for CLIP and DINOv2, two powerful pretrained vision foundation models. Experiment results show that CFA outperforms common finetuning techniques in compositional generalization, corroborating CFA's efficacy in compositional feature learning.
TL;DR
The paper introduces Compositional Feature Alignment (CFA), a two-stage fine-tuning strategy designed to help vision models generalize to unseen combinations of classes and domains. By forcing class-related and domain-related features into orthogonal subspaces, CFA allows models to successfully recognize objects in environments or styles they never encountered together during training.
What Problem Does This Paper Address?
In an ideal world, machine learning models would be trained on every possible combination of an object (class) and its environment (domain). In reality, data is sparse. You might have photos of cats and sketches of dogs, but no sketches of cats.
This is the challenge of Compositional Generalization (CG). While standard Domain Generalization (DG) focuses on moving to an entirely new domain (e.g., training on photos/sketches and testing on cartoons), CG asks if a model can fill in the "missing cells" of a domain-class matrix.
The authors found that even powerful foundation models like CLIP and DINOv2 struggle with this, often failing to recognize familiar objects when they appear in a domain that wasn't paired with that specific class during training.
Methods
The authors propose Compositional Feature Alignment (CFA), which moves away from the standard "fine-tune everything at once" approach. It consists of two distinct stages:
- Stage 1: Multi-Head Linear Probing. The pre-trained image encoder is frozen. Two separate linear "heads" are added: one to predict the class and one to predict the domain. Crucially, the authors impose an orthogonality constraint ($W_1 W_2^T = 0$), forcing the weights of these two heads to span completely different mathematical subspaces. This creates a geometric "blueprint" for how features should be organized.
- Stage 2: Fine-tuning with Frozen Heads. The two heads from Stage 1 are now frozen, and the image encoder is unfrozen. The model is trained to map images into the orthogonal subspaces defined in the first stage.
By separating class and domain information into non-interfering channels, the model learns to treat "what the object is" and "what the environment looks like" as independent, composable factors.
Datasets
The authors introduced CG-Bench, a suite of benchmarks specifically designed to test compositional generalization. They adapted four well-known real-world datasets by creating "hard" splits where specific domain-class combinations are held out for testing:
- OfficeHome: 65 classes across 4 domains (Art, Clipart, Product, Real).
- DomainNet: A massive dataset with 345 classes across 6 domains (e.g., Sketch, Infograph, Painting).
- iWildCam: Wildlife recognition from camera traps.
- FMoW: Satellite imagery for land use classification.
Key Insights and Ideas
- Orthogonality as a Prior: Instead of trying to "ignore" the domain (as in adversarial training), CFA embraces it. By giving the domain its own dedicated, orthogonal space, the model can learn domain-specific features without them "bleeding" into and corrupting the class features.
- Geometric Alignment: The method is inspired by "Neural Collapse," the observation that deep networks naturally want to map classes to simple geometric structures. CFA guides this collapse into a compositional structure.
- The "Blueprint" Effect: Training the heads first (Stage 1) is vital. It sets a fixed target for the encoder. The authors show that if you try to learn the heads and the encoder simultaneously, the features don't align as cleanly.
- Zero-Shot Domain Labeling: Interestingly, CFA works even if you don't have perfect domain labels. You can use a zero-shot model (like CLIP) to guess the domain labels for your training data, and CFA will still improve generalization.
Key Results
CFA consistently outperformed standard fine-tuning and other popular Out-of-Distribution (OOD) techniques (like LP-FT or Reweighting) across all benchmarks:
- CLIP on OfficeHome: CFA reached 56.9% OOD accuracy, significantly higher than standard fine-tuning (51.0%).
- DINOv2 on iWildCam: CFA achieved 22.8% OOD accuracy, a massive jump over standard fine-tuning (14.4%).
- Feature Visualization: Analysis of the learned feature space shows that after CFA, features for different classes and domains form a clear, grid-like structure, whereas the original pre-trained features are much more clustered and entangled.
Limitations and Future Work
- Model Architecture: The study focused primarily on base-sized Vision Transformer (ViT-B) models. It remains to be seen how these results scale to much larger models (ViT-L/H).
- Dataset Diversity: While CG-Bench covers several domains, the authors acknowledge the need to test on even more diverse data sources beyond standard computer vision benchmarks.
- The ID-OOD Gap: Despite the improvements, there is still a significant performance gap between In-Distribution (known combinations) and OOD (unseen combinations) data, indicating that compositional generalization is far from a "solved" problem.
- Future Directions: The authors suggest exploring alternative data sources and larger foundation models to further bridge the generalization gap.
Summary updated