Abstract
Recent advancements in Vision-Language Models (VLMs) like CLIP have demonstrated remarkable zero-shot capabilities. To adapt these models to specific downstream tasks, prompt tuning methods such as Context Optimization (CoOp) have emerged, replacing manual templates with learnable vectors. However, these methods often suffer from a significant performance drop on unseen categories—a phenomenon linked to the loss of general knowledge. This paper introduces Knowledge-guided Context Optimization (KgCoOp), a simple yet effective regularization technique that minimizes the discrepancy between learned prompts and hand-crafted templates. By preserving the essential general knowledge of the pre-trained model, KgCoOp achieves state-of-the-art generalization performance across multiple benchmarks while maintaining high computational efficiency.
Introduction
The emergence of pre-trained Vision-Language Models (VLMs), most notably CLIP, has revolutionized computer vision by enabling open-vocabulary recognition. These models align images and text in a shared embedding space, allowing for "zero-shot" classification using hand-crafted prompts like "a photo of a [Class]." While effective, manual prompt engineering is often suboptimal for specific tasks.
To address this, Context Optimization (CoOp) was introduced to automate prompt engineering by treating prompts as learnable continuous vectors. While CoOp significantly improves performance on the classes seen during training (Base classes), it often fails to generalize to New (unseen) classes, sometimes performing worse than the original zero-shot CLIP. This paper identifies this as a "forgetting" problem, where the optimization process pushes the prompt embeddings too far from the general-purpose knowledge encoded in the original model.
The Challenge: Generalization vs. Specificity
The core issue in prompt tuning is the stability-plasticity tradeoff. As the model learns task-specific features from the training data, the learnable context vectors drift away from the semantic space defined by the original pre-trained text encoder. The authors observe a direct correlation: the greater the Euclidean distance between the learned prompt and the original hand-crafted prompt, the poorer the model's performance on unseen classes.
Existing solutions like CoCoOp attempt to mitigate this by generating prompts conditioned on image features. However, these methods introduce significant computational overhead and increase inference latency, making them less practical for large-scale deployment.
Knowledge-guided Context Optimization (KgCoOp)
KgCoOp proposes a streamlined approach to bridge the gap between task-specific adaptation and general-purpose knowledge. The method builds upon the CoOp framework but introduces a "Knowledge-guided" loss term to regularize the learning process.
Methodology
The training objective in KgCoOp is defined by a composite loss function:
$$\mathcal{L} = \mathcal{L}_{ce} + \lambda \mathcal{L}_{kg}$$
- Cross-Entropy Loss ($\mathcal{L}_{ce}$): This is the standard loss used to optimize the prompt for the specific training classes.
- Knowledge-guided Loss ($\mathcal{L}_{kg}$): This term calculates the squared Euclidean distance between the textual embeddings generated by the learnable prompt and those generated by the original hand-crafted CLIP prompt.
- Regularization Parameter ($\lambda$): This hyperparameter controls the balance between adapting to the new task and staying close to the original knowledge.
By minimizing this combined loss, KgCoOp ensures that the learned prompts remain within a reasonable distance of the original CLIP embeddings, effectively "anchoring" the model to its general-purpose roots.
Experimental Evaluation
The authors evaluated KgCoOp on 11 diverse image classification datasets, including ImageNet, specialized fine-grained datasets (OxfordPets, StanfordCars, FGVCAircraft), and domain generalization benchmarks (ImageNet-V2, Sketch, etc.). The primary evaluation metric was the Base-to-New Generalization setting, where the model is trained on a subset of classes (Base) and tested on both the Base classes and a disjoint set of New classes.
Key Findings
- Superior Generalization: KgCoOp achieved an average accuracy of 73.6% on New classes across 11 datasets, a substantial improvement over CoOp's 67.99% and CoCoOp's 71.69%.
- Balanced Performance: The Harmonic Mean (H), which balances performance on both seen and unseen classes, reached 77.0 for KgCoOp, outperforming CoOp (74.6).
- Efficiency: Unlike instance-conditioned methods, KgCoOp uses a single set of learned prompts. This results in a training speed of 6ms per image, making it roughly 26x faster than CoCoOp (160ms) and nearly 4x faster than ProGrad.
Conclusion
KgCoOp demonstrates that complex architectural changes are not always necessary to improve the generalization of prompt tuning. By simply constraining the learned prompts to remain close to the original hand-crafted templates, KgCoOp effectively preserves the general knowledge of VLMs. This approach provides a highly efficient and effective solution for adapting large-scale pre-trained models to specific tasks without sacrificing their inherent ability to recognize unseen concepts.
Summary updated