Abstract
Image recognition has recently witnessed a paradigm shift, where vision-language models are now used to perform few-shot classification based on textual prompts. Among these, the CLIP model has shown remarkable capabilities for zero-shot transfer by matching an image and a custom textual prompt in its latent space. This has paved the way for several works that focus on engineering or learning textual contexts for maximizing CLIP’s classification capabilities. In this paper, we follow this trend by learning an ensemble of prompts for image classification. We show that learning diverse and possibly shorter contexts improves considerably and consistently the results rather than relying on a single trainable prompt. In particular, we report better few-shot capabilities with no additional cost at inference time. We demonstrate the capabilities of our approach on 11 different benchmarks.
Introduction
Vision-Language Models (VLMs) like CLIP have revolutionized image recognition by aligning images and text in a shared latent space. However, their performance is highly sensitive to the "prompt" used (e.g., "a photo of a [CLASS]"). Manually crafting these prompts is tedious and often suboptimal. To address this, researchers developed Context Optimization (CoOp), which replaces manual words with "learnable context tokens"—vectors optimized during training. While effective, CoOp typically relies on a single, often long, learned prompt.
ECO (Ensembling Context Optimization) addresses this limitation by drawing inspiration from prompt ensembling. Instead of a single long prompt, ECO learns an ensemble of multiple shorter textual prompts. By keeping the total number of trainable parameters constant, ECO consistently outperforms previous state-of-the-art methods across various benchmarks with zero additional computational cost at inference time.
Methods: Divide and Conquer
The core innovation of ECO is a "divide and conquer" strategy for prompt learning. Instead of learning one prompt with $M$ context tokens (the CoOp approach), ECO learns $D$ different prompts, each with $N$ context tokens, such that the total number of parameters remains the same ($M = D \times N$).
The process involves three key steps:
- Multi-Prompt Learning: During training, the model optimizes $D$ independent sets of context vectors.
- Prompt-Wise Averaging: For a given class, the text encoder processes each of the $D$ prompts. The resulting feature vectors are averaged into a single representative vector for that class.
- Zero Inference Overhead: Because the text features for each class can be precomputed and averaged before the model is deployed, ECO performs classification just as fast as a single-prompt model. It simply compares the image feature to the pre-averaged "ensemble" text feature.
Experimental Setup
The authors evaluated ECO on a diverse suite of 11 image classification benchmarks, covering general objects (ImageNet, Caltech101), specialized domains (OxfordPets, StanfordCars, Flowers102, FGVCAircraft), scenes and textures (SUN397, DTD), satellite and action data (EuroSAT, UCF101), and noisy data (Food101).
Key Results
ECO demonstrated consistent gains across all 11 datasets. The $D=4, N=4$ configuration emerged as the "sweet spot," providing the best balance between diversity and prompt length. This version achieved an absolute average improvement of +3.47% in 1-shot scenarios and +0.85% in 16-shot scenarios compared to the CoOp baseline.
The performance gap between ECO and CoOp is widest at 1-shot and 2-shot levels, making ECO particularly valuable for "cold-start" scenarios where labeled data is extremely scarce. Furthermore, ECO showed significant gains on Food101, suggesting that ensembling learned contexts helps the model ignore outliers and focus on more generalizable features.
Discussion and Future Work
The results suggest that having several diverse, shorter perspectives (prompts) is more valuable to the model than one long, complex description. Despite the performance boost, the method requires no extra parameters compared to a standard CoOp setup with 16 tokens and adds no latency to the final image classification step.
While ECO demonstrates clear advantages on top of the basic CoOp framework, future work could explore its integration with more advanced prompt learning methods like CoCoOp (image-conditional prompts) or MaPLe (multi-modal prompts). Additionally, exploring dynamic allocation of prompts per class or scaling these gains with larger Vision Transformer (ViT) backbones remains an open area for research.
Summary updated