NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Sample-specific Masks for Visual Reprogramming-based Prompting

Chengyi Cai, Zesheng Ye, Lei Feng, Jianzhong Qi, Feng Liu

Introduction

Visual Reprogramming (VR) has emerged as a powerful paradigm for adapting large-scale pre-trained models to downstream tasks without the need for extensive fine-tuning. By keeping the backbone model frozen and learning a small, additive "prompt" pattern in the input space, VR significantly reduces computational overhead. However, traditional VR methods typically employ a shared mask—a fixed spatial configuration (e.g., a border or grid) where the learnable pattern is applied to every input image.

This "one-size-fits-all" approach is suboptimal. Different images contain critical features in different spatial locations. A static mask may inadvertently obscure essential information in some samples while failing to provide sufficient "reprogramming" signal in others. This limitation increases the approximation error between the source and target tasks.

Methodology: Sample-specific Multi-channel Masks (SMM)

To address the rigidity of shared masks, we introduce Sample-specific Multi-channel Masks (SMM). Instead of a hard-coded binary mask, SMM utilizes a lightweight generator to tailor a unique mask for every input image.

Lightweight Mask Generator

The core of SMM is a tiny Convolutional Neural Network (CNN) that processes a resized version of the input image. This generator outputs a three-channel mask, allowing for channel-wise modulation of the reprogramming noise. By leveraging the spatial awareness of CNNs, the generator identifies regions where the reprogramming pattern is most beneficial or least intrusive.

Patch-wise Interpolation and Efficiency

To maintain high efficiency, the generator produces a low-resolution mask which is subsequently upscaled using a patch-wise interpolation method. This approach ensures that the mask aligns with the underlying image structure while avoiding the high computational cost of generating full-resolution masks. The final input to the frozen backbone is defined as the original image plus a shared learnable pattern that has been filtered through the sample-specific mask. This formulation allows the system to learn a global task-specific "language" while adapting its application locally for each sample.

Figure 1: Comparison of different fixed mask densities (Full, Medium, Narrow) across different samples. SMM automates this selection process to optimize prediction accuracy for each specific image.

Experimental Results

The SMM framework was evaluated across 11 diverse datasets, including general objects (CIFAR), specialized domains (SVHN, EuroSAT), and fine-grained categories (OxfordPets, Flowers102).

Performance Gains

SMM consistently outperformed standard VR baselines across various backbones:

  • ResNet-50: SMM achieved an average accuracy of 56.35%, surpassing the best fixed-mask baseline (52.10%).
  • Vision Transformer (ViT): The improvements were particularly pronounced. On the Flowers102 dataset, SMM reached 79.1% accuracy, compared to just 57.3% for standard padding. Across all 11 datasets, ViT accuracy improved from 64.7% to 72.4%.

Theoretical and Qualitative Insights

Theoretically, SMM is guaranteed to have a lower or equal approximation error than shared-mask methods, as its hypothesis space is a superset of the latter. Qualitatively, visualizations indicate that SMM learns to "protect" critical image features by masking out noise in those regions, concentrating the reprogramming signal in the background or less relevant areas.

Conclusion and Future Work

SMM offers a highly efficient (adding less than 0.23% extra parameters) and effective method for visual prompting. While it shows remarkable success on diverse datasets, it still faces challenges in extremely fine-grained tasks like StanfordCars, where class differences are minimal. Future research may explore hybrid approaches combining input-space prompting with weight-space adaptations to further bridge the gap to full fine-tuning.

Summary updated

BibTeX
@inproceedings{cai2024sample,
  author = {Chengyi Cai and Zesheng Ye and Lei Feng and Jianzhong Qi and Feng Liu},
  title = {{Sample-specific Masks for Visual Reprogramming-based Prompting}},
  booktitle = {International Conference on Machine Learning},
  year = {2024},
  url = {https://openreview.net/forum?id=4sikyurTLX},
}
Figure