Exploring Visual Prompts for Adapting Large-Scale Models

Hyojin Bahng, Ali Jahanian, Swami Sankaranarayanan, Phillip IsolaarXiv 2022

TL;DR

Visual prompting adapts large-scale frozen vision models to new tasks by learning a single, task-specific pixel perturbation added to input images. This method is remarkably effective for CLIP, often rivaling or exceeding the performance of standard linear probes while requiring zero modifications to the model's weights or internal activations at test time.

What Problem Does This Paper Address?

As machine learning models grow in scale, adapting them to specific downstream tasks becomes increasingly difficult. The standard "de facto" methods—fine-tuning (updating all model parameters) and linear probing (training a new classification head on internal activations)—both have drawbacks. Fine-tuning is computationally expensive and can destroy a model's general knowledge, while linear probing requires access to the model's internal features, which isn't always possible if a model is served via a restricted API.

Inspired by the success of "prompting" in Natural Language Processing (NLP), where models like GPT-3 are steered by text templates, the authors ask: Can we adapt frozen visual models to new tasks simply by modifying the input pixels?

Methods

The authors propose Visual Prompting, a technique that learns a single image perturbation (a "soft prompt") through backpropagation while keeping the entire pre-trained model frozen.

Key components include:

  • Input Transformation: They add a learned perturbation $v_{\phi}$ to the input image $x$. While they experimented with various designs, they found that padding (learning a colored "frame" around the image) worked best, likely because it avoids obscuring the central object of interest.
  • Output Transformation:
    • For CLIP (a vision-language model), they use a fixed text prompt (e.g., "a photo of a [label]") to map visual features back to classes.
  • For standard vision models (like ResNet), they use a hard-coded mapping, arbitrarily assigning downstream classes to pre-existing ImageNet indices.
  • Optimization: Only the prompt pixels are updated to maximize the likelihood of the correct label. Once learned, this single prompt is added to every image in the test set.
Comparison of adaptation methods: Fine-tuning vs. Linear Probe vs. Prompting

Datasets

The researchers evaluated their method across a diverse suite of 12 image classification datasets, including:

  • General/Natural: CIFAR10/100, Food101, OxfordPets, SUN397.
  • Specialized: EuroSAT (satellite), Resisc45 (remote sensing), DTD (textures), Flowers102.
  • Synthetic/Abstract: CLEVR (counting), SVHN (house numbers).

To test robustness to distribution shift, they used the WILDS benchmark, specifically the Camelyon17 (medical tissue patches), FMoW (satellite imagery over years/regions), and iWildCAM (camera trap photos) datasets.

Key Insights and Ideas

  • The CLIP Advantage: Visual prompting is significantly more effective for CLIP than for traditional vision-only models like ResNet-50 or BiT. The authors suggest this is because CLIP’s text-based output head is semantically flexible, whereas vision models are hampered by the "hard-coded mapping" bottleneck.
  • Bridging the Distribution Gap: Visual prompts act as a bridge. They are most effective when the downstream dataset is "out-of-distribution" compared to the model's pre-training data. For example, the performance gain on SVHN (numbers) was a massive +83.2% compared to zero-shot CLIP.
  • Diversity and Complexity: The method works best on datasets with low perceptual diversity (where images look relatively similar, like satellite tiles) and high FID scores (meaning they look very different from ImageNet).
  • Compensating for Bad Text: In CLIP, if you choose a poor text prompt, a learned visual prompt can actually compensate for that deficiency, bringing performance back up to high levels.
Figure 4: Accuracy gain from learning a visual prompt. The bars indicate the gain (or loss) in ac- curacy obtained by learning a single visual prompt compared to text-prompted (i.e., zero-shot) CLIP.

Key Results

  • Competitive with Linear Probes: On average across 12 datasets, CLIP with visual prompting achieved 78.2% accuracy, coming close to the 83.1% achieved by linear probes.
  • Outperforming the Baseline: On specific datasets like EuroSAT, SVHN, and CLEVR, visual prompting actually outperformed linear probes by 1.1%, 23%, and 15.4%, respectively.
  • Superior Robustness: In distribution shift scenarios (WILDS), visual prompting proved remarkably stable. On the Camelyon17 medical dataset, it outperformed both linear probes and fine-tuning, suggesting that keeping the model frozen prevents it from overfitting to spurious correlations in the training data.
Figure 3: Prompting with vision models vs. CLIP. Prompting with vision models shows sig- nificant performance gap to linear probe. In con- trast, prompting with CLIP achieves competitive performance.

Limitations and Future Work

  • The Mapping Bottleneck: For non-language vision models, the arbitrary mapping of labels to ImageNet indices remains a major hurdle. Future work could explore more intelligent ways to initialize these mappings.
  • Input-Agnostic Prompts: This paper focuses on a single prompt for an entire dataset. The authors suggest that input-conditional prompts (where the perturbation changes based on the specific image) could unlock even higher performance.
  • Task Scope: The study focused primarily on image classification. Exploring visual prompts for more complex tasks like object detection or image-to-image translation is a promising next step.

Summary updated

BibTeX
@misc{bahng2022exploring,
  author = {Hyojin Bahng and Ali Jahanian and Swami Sankaranarayanan and Phillip Isola},
  title = {{Exploring Visual Prompts for Adapting Large-Scale Models}},
  year = {2022},
  eprint = {2203.17274},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2203.17274},
}
Figure