ECO: Ensembling Context Optimization for Vision-Language Models

Lorenzo Agnolucci, Alberto Baldrati, Francesco Todino, Federico Becattini, Marco Bertini, Alberto Del Bimbo

TL;DR

ECO (Ensembling Context Optimization) improves few-shot image classification in vision-language models by learning an ensemble of multiple diverse, shorter prompts instead of a single long one. By redistributing the same parameter budget, ECO delivers consistent accuracy boosts across 11 benchmarks with absolutely zero added computational cost at inference time.

What Problem Does This Paper Address?

Foundational vision-language models like CLIP have revolutionized image recognition by enabling zero-shot classification via textual prompts (e.g., "a photo of a [CLASS]"). However, performance is highly sensitive to prompt wording; a minor tweak can cause a significant swing in accuracy.

To bypass manual prompt engineering, methods like Context Optimization (CoOp) introduce prompt learning, optimizing continuous context vectors directly from data. While effective, existing methods only learn a single prompt. They miss out on the benefits of prompt ensembling—the practice of averaging predictions from multiple different prompts, which is known to significantly boost the robustness and accuracy of vision-language models.

Methods

The authors introduce ECO (Ensembling Context Optimization), a framework that seamlessly merges prompt learning with prompt ensembling.

Instead of learning a single long prompt with $M$ context tokens (the standard CoOp approach), ECO splits the parameter budget to learn $D$ distinct prompts, each containing $N$ shorter context tokens, such that the total number of trainable parameters remains constant ($M = D \times N$).

Figure 1: Overview of our approach. While CoOp uses a single prompt with M context tokens, ECO trains D prompts with N context tokens each, such that M =D ∗N. Given the same number of trainable parameters, ensembling multiple prompts with a reduced number of context tokens performs better than using a single prompt with a larger number of context tokens.

During training, cross-entropy loss optimizes these $D$ sets of context vectors simultaneously while keeping the base CLIP model frozen. At inference time, the text features generated by each prompt are averaged element-wise before computing similarity scores with the image features.

Crucially, because these textual prompts do not depend on the input image, the ensembled text features can be precomputed and cached. This means ECO provides the benefits of an ensemble with zero additional computational overhead during deployment.

Datasets

The approach was evaluated using a standard few-shot protocol (1, 2, 4, 8, and 16 shots) across 11 diverse image classification benchmarks:

  • General Objects: ImageNet, Caltech101
  • Fine-Grained Categories: OxfordPets, StanfordCars, Flowers102, FGVCAircraft
  • Scenes & Textures: SUN397, DTD
  • Satellite Imagery: EuroSAT
  • Actions: UCF101
  • Specialized/Noisy: Food101 (noted for having noisy annotations)

Key Insights and Ideas

  • The Power of Shorter, Diverse Contexts: Optimization landscapes for shorter prompts appear to yield more diverse and complementary representations. Learning four distinct 4-token prompts captures broader semantic context than a single 16-token prompt, preventing the model from overfitting to a narrow textual subspace.
  • Computational Free Lunch: Ensembling typically incurs a linear cost penalty. ECO circumvents this entirely by exploiting the decoupled architecture of vision-language models, allowing the ensemble's complexity to be completely baked into static text embeddings before inference begins.
  • Enhanced Data Efficiency: The performance gap between ECO and single-prompt methods is widest in ultra-low-data regimes (1 and 2 shots), making it an exceptionally strong few-shot learner.
  • Robustness to Noisy Labels: On datasets like Food101, which suffer from clean-label noise, ECO maintains steady improvements where single-prompt methods often struggle or degrade below zero-shot baselines.

Key Results

The authors found that a configuration of $D=4$ prompts and $N=4$ tokens provided the best overall trade-off.

Figure 2: Quantitative results on the 11 test datasets varying the number of shots, prompts D and context tokens N for each of them. Note that CoOp [21] coincides with ECO when D=1 and N =16.

As summarized in the performance breakdown below, ECO ($D=4, N=4$) consistently outperformed the CoOp baseline across all shot configurations:

  • 1-Shot: Achieved an absolute accuracy gain of +3.47% over CoOp (62.90% vs 59.43%).
  • 2-Shot: Delivered a +2.88% improvement.
  • 16-Shot: Maintained a +0.85% advantage, outperforming both CoOp and strong linear-probe baselines.
Table showing detailed comparison of results averaged over 11 datasets

Limitations and Future Work

While ECO demonstrates clear advantages, this paper focuses exclusively on extending the basic, unconditional text prompt learning method (CoOp). The authors note that ECO is a general framework and intend to apply it to more advanced prompt learning paradigms in future work, such as instance-conditional prompting (e.g., CoCoOp) and multi-modal prompt learning (e.g., MaPLe), where prompts are learned in both the vision and language branches.

Summary updated

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.
BibTeX
@misc{agnolucci2023eco,
  author = {Lorenzo Agnolucci and Alberto Baldrati and Francesco Todino and Federico Becattini and Marco Bertini and Alberto Del Bimbo},
  title = {{ECO: Ensembling Context Optimization for Vision-Language Models}},
  year = {2023},
  eprint = {2307.14063},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2307.14063},
}
Figure