Context-Aware Robust Fine-Tuning

Xiaofeng Mao, Yufeng Chen, Xiaojun Jia, Rong Zhang, Hui Xue, Zhao Li

TL;DR

Fine-tuning CLIP models often boosts performance on specific tasks but destroys their inherent robustness to new environments. This paper introduces Context-Aware Robust Fine-tuning (CAR-FT), a method that preserves a model's ability to recognize image context (like style or background), leading to state-of-the-art performance on both standard and out-of-distribution (OOD) benchmarks.

What Problem Does This Paper Address?

Contrastive Language-Image Pre-trained (CLIP) models are celebrated for their "zero-shot" robustness. Because they are trained on diverse image-text pairs, they don't just learn to recognize an object; they learn to recognize it across different contexts—such as a "sketch of a dog" versus a "photo of a dog."

However, when researchers fine-tune CLIP on a specific downstream dataset to squeeze out more accuracy, a "robustness gap" appears. The model becomes highly accurate on that specific data (In-Distribution) but loses its ability to generalize to new styles or backgrounds (Out-Of-Distribution). The authors empirically show that standard fine-tuning causes the model to "forget" context information catastrophically, essentially turning a context-aware model into a context-blind one.

Figure 1: Standard fine-tuning causes context recognition accuracy to plummet from 82.5% to near-random levels (26.7%).

Methods

The authors propose CAR-FT, which adds a simple but effective regularization term to the fine-tuning process.

  1. Context Distribution: They use the original, pre-trained CLIP model to generate a "reference context distribution" for an image using a set of context prompts (e.g., "a [photo/sketch/cartoon] of [CLASS]").
  2. KL Divergence Regularization: During fine-tuning, the model is optimized not just to predict the correct class (using standard Cross-Entropy loss, $\mathcal{L}_{CE}$), but also to ensure its predicted context distribution remains close to the original model's distribution.
  3. Consistency: This is achieved by minimizing the Kullback-Leibler Divergence ($\mathcal{L}_{KL}$) between the context predictions of the original and the fine-tuned model.

By forcing the model to remember how it perceived the context originally, it retains the robust features learned during pre-training while still adapting to the new task.

Figure 2: The CAR-FT procedure (right) adds a KL Divergence loss to maintain context-awareness, unlike standard fine-tuning (bottom left).

Datasets

The authors evaluated CAR-FT across a wide array of benchmarks:

  • ImageNet & OOD Variants: Evaluated on ImageNet (ID) and five OOD versions: ImageNet-V2, ImageNet-R (renditions), ImageNet-Sketch, ObjectNet (objects in unusual poses/backgrounds), and ImageNet-A (adversarial).
  • DomainBed: A standard benchmark for Domain Generalization, including datasets like PACS, VLCS, OfficeHome, TerraIncognita, and DomainNet.
  • Downstream Tasks: Nine diverse classification tasks including CIFAR-10/100, OxfordPets, StanfordCars, and Flowers102.

Key Insights and Ideas

  • Catastrophic Forgetting of Context: The most striking insight is that fine-tuning doesn't just shift the model's focus; it actively erases its ability to distinguish between styles (like "photo" vs "sketch"), which is a primary source of CLIP's original robustness.
  • Context as a Regularizer: Instead of just regularizing the weights (like weight averaging), CAR-FT regularizes the behavior of the model regarding image context.
  • Prompt Efficiency: You don't need an exhaustive list of prompts. The authors found that even a small subset of 7 well-organized context templates is sufficient to guide the model effectively.
  • Interpretability: Visualization of attention maps shows that CAR-FT models maintain focus on the actual object even in "uncommon" contexts, whereas standard fine-tuned models often get distracted by background shifts.

Key Results

CAR-FT consistently outperforms standard fine-tuning and other robust fine-tuning methods like LP-FT and WiSE-FT.

  • ImageNet: Achieved 83.3% ID accuracy (2.1% higher than baseline) and 56.9% average OOD accuracy (a massive 8.2% improvement over standard fine-tuning).
  • Domain Generalization: On the DomainBed benchmark, CAR-FT reached an average accuracy of 78.5%, setting a new state-of-the-art and surpassing previous methods like MIRO and DPL.
  • Versatility: The method works across various backbones, including ResNet-50 and different scales of Vision Transformers (ViT-B, ViT-L, ViT-H).
Table 1: Quantitative comparison showing CAR-FT's superior performance across all ImageNet distribution shifts.

Limitations and Future Work

The primary limitation of CAR-FT is its reliance on text prompts. The method requires a pre-trained vision-language model (like CLIP) and a set of descriptive context prompts for the task. This makes it difficult to apply to "vision-only" pre-trained models (like MAE) or tasks where defining "context" in text is non-trivial.

The authors suggest that future work could focus on removing this prerequisite, perhaps by automatically discovering context clusters in a purely visual way.

Summary updated

BibTeX
@article{mao2024context,
  author = {Xiaofeng Mao and Yufeng Chen and Xiaojun Jia and Rong Zhang and Hui Xue and Zhao Li},
  title = {{Context-Aware Robust Fine-Tuning}},
  journal = {Int. J. Comput. Vis.},
  year = {2024},
  url = {https://openreview.net/forum?id=1FooKWhX0j},
}
Figure