Abstract
Deep learning models frequently encounter performance degradation when deployed on data that deviates from the training distribution. Traditional Test-Time Adaptation (TTA) methods often suffer from high computational costs and catastrophic forgetting. We present GeneralizeFormer, a novel framework that utilizes a lightweight, meta-learned transformer to generate layer-specific model parameters on the fly. By adaptively producing parameters for each data batch, GeneralizeFormer enables fast, robust generalization across diverse distribution shifts—including input, feature, and output levels—while preserving original source knowledge.
Introduction
Distribution shift remains a critical challenge in deploying deep learning models. When a model trained on one domain (e.g., real photos) is tested on another (e.g., sketches or cartoons), its accuracy typically plummets. Current approaches generally fall into two categories:
- Test-Time Adaptation (TTA): These methods fine-tune models online using unsupervised losses. While effective, they are slow, computationally intensive, and prone to "catastrophic forgetting," where the model loses its original discriminative capabilities.
- Classifier Adjustment: These methods only modify the final classification layer. Although fast, they fail to address shifts occurring during feature extraction in earlier layers.
To bridge this gap, we propose Test-Time Domain Generalization (TTDG) through GeneralizeFormer. This approach aims for rapid adaptation across multiple levels of shift without the drawbacks of iterative fine-tuning.
Methodology: The GeneralizeFormer Framework
The core of our approach is the GeneralizeFormer, a transformer module designed to generate parameters for specific layers of a backbone network (e.g., ResNet).
Selective Parameter Generation
To maintain efficiency, GeneralizeFormer does not generate all model parameters. Instead, it keeps heavy convolutional weights fixed and focuses on generating:
- Batch Normalization (BN) Affine Parameters: To handle style and feature-level shifts.
- Linear Classifier Weights: To handle output-level category shifts.
Informed Parameter Synthesis
The transformer generates these parameters based on a rich set of inputs:
- Source-Trained Parameters: Providing a baseline of knowledge.
- Target Features: Extracted from the current test batch to provide context on the new domain.
- Layer-wise Gradients: Derived from an unsupervised entropy minimization loss. These gradients serve as a signal indicating the "gap" between the current model state and the target data distribution.
Meta-Learning for Generalization
The GeneralizeFormer is trained using a meta-learning strategy. By simulating distribution shifts during training—splitting source domains into "meta-source" and "meta-target" sets—the transformer learns the mapping between data shifts and the necessary parameter adjustments.
Experimental Evaluation
We evaluated GeneralizeFormer across six major domain generalization benchmarks, including PACS, VLCS, Office-Home, TerraIncognita, Living-17, and Rotated/Fashion MNIST.
Key Results
- Accuracy: GeneralizeFormer consistently outperformed standard Empirical Risk Minimization (ERM) and state-of-the-art TTA methods. On the PACS dataset (ResNet-18), it achieved 85.5% accuracy, a significant improvement over the 79.6% baseline.
- Efficiency: By generating parameters in a single forward pass, the method is remarkably fast. It processed the test set in 20 seconds, compared to 3–9 minutes for fine-tuning-based competitors.
- Robustness: Unlike many TTA methods that require large batches, GeneralizeFormer remains stable even with a batch size of 1.
- Multi-Level Adaptation: Visualizations confirm that the model adapts different layers based on the shift type: early layers for style shifts and the classifier for category shifts.
Discussion and Future Work
GeneralizeFormer demonstrates that treating gradients as informative features for a transformer allows for dynamic, feedforward adaptation. This avoids the instability of iterative loops and prevents the forgetting of source knowledge.
However, challenges remain. The current meta-learning strategy requires multiple source domains, and extending parameter generation to more complex layers like convolutions without excessive cost is an open research question. Future work may also explore using generative augmentation to create more diverse synthetic shifts during the meta-training phase.
Summary updated