Self-distilled Vision Transformer for Domain Generalization

Maryam Sultana, Muzammal Naseer, Muhammad Haris Khan, Salman H. Khan, Fahad Shahbaz Khan

Introduction

In the field of machine learning, Domain Generalization (DG) remains a significant challenge. The goal is to train a model on several related source domains (e.g., photographs and sketches of objects) such that it can generalize effectively to a completely unseen target domain (e.g., oil paintings). While Convolutional Neural Networks (CNNs) have been the primary focus of DG research, Vision Transformers (ViTs) have recently emerged as powerful alternatives. However, ViTs are often "lazy learners" in these contexts; they tend to overfit to non-transferable features like specific backgrounds or textures, leading to poor performance in out-of-distribution (OOD) scenarios.

This paper introduces SDViT (Self-Distilled Vision Transformer), a parameter-free, plug-and-play method designed to mitigate this overfitting. By leveraging the "dark knowledge" from the model's final layer to supervise its intermediate blocks, SDViT encourages the model to learn robust, semantic features earlier in the network, significantly boosting its ability to generalize.

The SDViT Framework

Standard ViT training typically relies on "hard" one-hot labels, which provide low-entropy signals that can lead the model toward brittle, domain-specific shortcuts. SDViT addresses this by utilizing the modular architecture of Transformers to create internal supervision.

1. Feature Pathways and Dark Knowledge

In a ViT, the class token passes through a sequence of identical transformer blocks. The authors observed that the output of any intermediate block can be routed through the final classifier head to generate a prediction. SDViT takes the "soft" probability distribution—the dark knowledge—from the final output and uses it as a supervisory signal for these intermediate blocks. This soft signal contains more information than a standard label, making the learning task more nuanced and encouraging the extraction of useful features early in the architecture.

2. Random Sub-model Distillation

To avoid the computational burden of distilling every block at every training step, the authors introduced a "Selector" mechanism. This component randomly selects one intermediate block during each training iteration to receive the distillation loss. This approach ensures the entire network benefits from distillation over time without significant training overhead.

3. Optimization

The total loss function for SDViT is a combination of standard Cross-Entropy (applied to the final output) and Kullback-Leibler (KL) Divergence, which matches the intermediate block's output to the final output. This method adds zero new parameters to the model and maintains a monolithic architecture where feature dimensions remain consistent.

Experimental Evaluation

The researchers evaluated SDViT using the DomainBed benchmark, covering five diverse datasets: PACS, VLCS, OfficeHome, TerraIncognita, and DomainNet. These datasets represent a wide array of challenges, including style shifts (Art vs. Photo), background shifts, and corruption shifts.

Key Results

  • State-of-the-Art Performance: Utilizing a CvT-21 backbone, SDViT achieved an average accuracy of 68.6% across the five datasets, outperforming the previous leading method, SWAD, by 1.8%.
  • Efficiency: The training overhead is remarkably low. Depending on the domain, the relative increase in training time ranged from only 0.35% to 4.88%.
  • Synergy: SDViT is compatible with other DG techniques. When combined with Test-Time Classifier Adjustment (T3A), the CvT backbone reached a peak average accuracy of 70.2%.

Qualitative Insights

Beyond raw metrics, the authors provided several insights into why SDViT improves generalization:

  • Semantic Focus: Saliency map visualizations indicate that while standard ViTs often focus on background elements, SDViT-trained models consistently lock onto the actual object's shape and semantics.
  • Earlier Maturity: Analysis of block-wise accuracy showed that SDViT makes early layers significantly more discriminative and accurate compared to standard training.
  • Domain Invariance: t-SNE visualizations demonstrated that SDViT produces feature clusters where different domains overlap more closely, suggesting the model has successfully learned features that are truly domain-invariant.

Limitations and Future Work

While highly effective, SDViT requires the tuning of two hyperparameters: temperature ($\tau$) and loss weight ($\lambda$). Additionally, while the method is parameter-free for monolithic architectures, non-monolithic designs (where feature dimensions change) require an additional projection layer ($g$) to match dimensions between blocks.

Future research may explore the application of this self-distillation strategy in more extreme domain shift scenarios, such as medical imaging or satellite data analysis, where robust generalization is critical.

Summary updated

BibTeX
@inproceedings{sultana2022self,
  author = {Maryam Sultana and Muzammal Naseer and Muhammad Haris Khan and Salman H. Khan and Fahad Shahbaz Khan},
  title = {{Self-distilled Vision Transformer for Domain Generalization}},
  booktitle = {ACCV},
  year = {2022},
  doi = {10.1007/978-3-031-26284-5\_17},
}
Figure