Abstract
Vision-Language Models (VLMs) like CLIP have set new standards for zero-shot image classification, yet their performance is highly sensitive to the quality of text prompts. While Test-Time Adaptation (TTA) methods like TPT have been developed to optimize these prompts for unseen data, they are computationally expensive, requiring optimization for every test image. We present Self-TPT, a framework that shifts the adaptation process from individual images to predefined class names. By utilizing self-supervised learning on the target class vocabulary, Self-TPT achieves a 25x speedup and 30x memory reduction compared to state-of-the-art methods, while simultaneously improving classification accuracy across 11 core benchmarks.
Introduction
The effectiveness of VLMs often hinges on "soft prompts"—learnable vectors that replace manual prompt engineering. To adapt to distribution shifts at inference time, researchers introduced Test-Time Prompt Tuning (TPT). However, TPT's requirement for multiple forward and backward passes per image creates a significant bottleneck for real-time deployment, rendering it impractical for edge devices.
Self-TPT addresses this by decoupling the adaptation process from the image prediction process. Instead of adapting to each image, it adapts prompts to the set of candidate class names in the test dataset. This class-centric approach recognizes that the primary challenge in new domains is often the model's understanding of the specific class vocabulary rather than individual image variations.
Methods
The Self-TPT framework operates in three distinct stages:
- Source Training: The model is trained on a source dataset using standard classification loss and a novel Contrastive Prompt Learning (CPT) loss. A Gradient Matching (GM) loss is introduced to ensure that gradients from the self-supervised CPT task align with the supervised classification task, effectively "teaching" the prompts that self-supervision is a reliable signal for classification.
- Test-Time Adaptation: Before processing test images, the model uses the CPT task to adapt prompts to the target class names. This is a one-time preprocessing step for the entire dataset.
- Direct Prediction: Adapted prompts are frozen, and test images are classified in a single forward pass, similar to standard zero-shot CLIP but with dataset-tailored prompts.
The core of the self-supervised task is Contrastive Prompt Learning (CPT). CPT generates multiple "views" of a prompt by varying the insertion point of the [CLASS] token (beginning, middle, or end of the learnable sequence). Contrastive learning then pulls embeddings of the same class together while pushing different classes apart, refining the model's domain-specific class representations.
Results
Self-TPT was evaluated across a massive battery of benchmarks, including 11 core datasets (e.g., ImageNet, OxfordPets, EuroSAT), domain generalization tasks (ImageNet-V2/S/A/R), and video recognition.
- Efficiency: On an A100 GPU using CLIP-B/16, Self-TPT achieves 146.7 FPS, a massive improvement over the original TPT (7.1 FPS) and the previous state-of-the-art, PromptAlign (5.3 FPS). Memory usage is reduced to just 0.32 GB VRAM, a staggering reduction from PromptAlign’s 11.2 GB.
- Accuracy: Self-TPT consistently outperforms competitors, with a 0.93% improvement in cross-dataset generalization and a 1.37% gain in base-to-new class generalization over previous best methods.
- Robustness: The method maintains its advantages across different backbones (ResNet, ViT) and model scales (CLIP-B/16 to CLIP-L/14).
Conclusion
Self-TPT represents a significant advancement in making test-time adaptation practical for real-world VLMs. By amortizing the cost of adaptation over the entire test set and focusing on class-level adaptation, it provides a highly efficient and effective solution. Future work will explore dynamic class sets and extending this text-oriented adaptation to more complex multi-modal tasks like visual question answering and image captioning.
Summary updated