Introduction
Contrastive Language-Image Pre-training (CLIP) has significantly advanced zero-shot classification, enabling models to recognize objects without explicit task-specific training. However, fine-tuning CLIP for downstream tasks often compromises its inherent generalization capabilities, particularly on unseen classes. While "test-time prompt tuning" attempts to optimize prompts during inference, it frequently overlooks the vast knowledge embedded in external large-scale image-text datasets and underutilizes the language modality.
To address these limitations, we present X-MoRe (Cross-Modal Retrieval based Inference), a training-free framework that enhances CLIP's zero-shot performance by retrieving and ensembling relevant textual context from external datasets during the inference phase.
The X-MoRe Framework
X-MoRe operates as a two-stage pipeline that requires no additional training or backpropagation, making it highly efficient for real-world deployment. The core idea is to treat an external dataset as an "open-book" library to supplement the model's internal knowledge.
Two-Stage Cross-Modal Retrieval
The retrieval process is divided into two steps to ensure both efficiency and relevance:
- Coarse Retrieval: For a given query image $X$, the system identifies the $N$ most similar images in an external repository (e.g., LAION-400M) using standard K-Nearest Neighbor (KNN) search.
- Fine Retrieval: From the $N$ candidates, the system selects the $K$ captions most similar to the original query image. This step is crucial because image-to-image similarity does not always guarantee that the associated text accurately describes the query.
Modal-Confidence-Based Ensemble
X-MoRe generates two distinct predictions: $P_{img}$ from the original image and $P_{txt}$ aggregated from the $K$ retrieved captions. These are combined using a dynamic weighting scheme based on prediction entropy. High entropy indicates model uncertainty, while low entropy suggests confidence. To account for the differing "natural" entropy levels of image and text modalities, a min-max normalization is applied to these confidence scores over time, ensuring a balanced ensemble.
Key Insights and Results
A critical finding of this work is the "overconfidence" of the text modality. When retrieving only a single caption ($K=1$), the model often exhibits low entropy even for incorrect predictions. By increasing $K$ to 16 and averaging the results, the text-modal probability distribution becomes significantly more reliable and better aligned with the image-modal prediction.
Performance Benchmarks
X-MoRe demonstrates state-of-the-art performance across various settings:
- Superior Accuracy: Using a ResNet-50 CLIP backbone, X-MoRe achieved an average accuracy of 61.04% across 10 diverse datasets (including Caltech101, Food101, and EuroSAT), significantly outperforming the standard CLIP zero-shot baseline of 55.82% and even tuning-based methods like TPT (57.66%).
- Robustness to Distribution Shift: In domain generalization tests on ImageNet variants (Sketch, Adversarial, Rendition), X-MoRe consistently surpassed baselines. The retrieval of external context proves particularly effective for stylized or out-of-distribution images.
- Ablation Success: The two-stage retrieval mechanism is vital; removing the fine-retrieval step resulted in a significant performance drop, such as a nearly 5% decrease on the Flowers102 dataset.
Conclusion
X-MoRe provides a robust, tuning-free approach to improving zero-shot classification by leveraging external cross-modal knowledge. By intelligently ensembling image and retrieved text predictions, it overcomes the limitations of traditional prompt tuning and preserves the generalization power of foundation models like CLIP. While it introduces some computational overhead due to the retrieval step, its feed-forward nature makes it a practical solution for enhancing model performance without the need for expensive re-training.
Summary updated