Focus Your Attention when Few-Shot Classification

Haoqing Wang, Shibo Jie, Zhi-Hong DengNeurIPS 2023

TL;DR

Adapting large, pre-trained Vision Transformers (ViTs) to few-shot tasks is often hindered by the model focusing on irrelevant background noise rather than the actual object of interest. This paper introduces FORT (FOcus youR aTtention), a method that automatically generates "position prompts" to supervise the model's attention mechanism. By forcing the model to lock onto class-relevant entities, FORT significantly boosts classification accuracy in data-scarce environments.

What Problem Does This Paper Address?

Few-shot learning (FSL) aims to recognize new categories from just a handful of labeled examples (the "support set"). While large-scale pre-trained models like ViTs provide excellent starting points, they are notoriously data-hungry.

When fine-tuning a massive ViT on only one or five images, a specific failure mode emerges: attention drift. Because support images often contain multiple entities (e.g., a bird sitting on a specific type of branch), the model might inadvertently focus on the branch or the sky to identify the "bird" class. With so little data, the model struggles to learn to ignore this noise. Standard fine-tuning often fails to correct this, leading to poor generalization when the model encounters a "query" (test) image of the same bird in a different environment.

Methods

The authors propose a two-step framework to steer the model’s focus toward the most discriminative features:

The FORT framework illustrating how position prompts guide attention during fine-tuning.
  1. Automatic Position Prompts: To tell the model where to look without requiring manual bounding boxes, the authors use a "deep explanation" method. They combine attention maps from multiple layers and augment them with gradient information. This ensures the identified "key patches" are not just visually salient, but are actually the parts of the image most responsible for the class prediction. These identified patches serve as "position prompts."
Examples of automatically generated position prompts highlighting key object regions.
  1. Attention Enhancement Loss: During fine-tuning, the authors introduce a new loss term ($\mathcal{R}$) alongside the standard cross-entropy classification loss. This $\mathcal{R}$ term calculates the cross-entropy between the model's current attention logits and the "many-hot" representation of the position prompts.

Essentially, FORT supervises the attention mechanism itself. By forcing the model to attend to the correct patches in the support set, the model learns a more robust feature extraction strategy that generalizes effectively to unseen query images.

Datasets

The researchers evaluated FORT across several challenging benchmarks, focusing on a "20-way" setup (choosing between 20 classes), which is significantly harder than the standard 5-way FSL task:

  • Fine-grained classification: CUB (Birds), Stanford Cars, Aircraft, and Oxford Pets.
  • General classification: Places (scenes) and Plantae.
  • Standard FSL: miniImageNet.

They tested these across various pre-training regimes, including DINO (self-supervised), CLIP (vision-language), and iBOT.

Key Insights and Ideas

  • Attention as a Bottleneck: The pre-trained weights often already contain the necessary information to distinguish classes; the failure in few-shot learning is a failure of selection. FORT acts as a pointer, telling the model which features to prioritize.
  • Gradients are the Secret Sauce: Pure attention maps (like those from DINO) often highlight the entire foreground object. However, for specific tasks, only certain parts might be class-specific. By incorporating gradients into the prompt generation, FORT ensures the model focuses on the most discriminative features.
  • Generalization of "Looking": Supervising attention on the support samples actually improves attention on the query samples. The model doesn't just learn where the bird is in Image A; it learns the type of features that constitute a bird, allowing it to find the bird more effectively in Image B.
  • Information Theory Link: The authors theoretically prove that their attention enhancement loss is equivalent to maximizing the Mutual Information between the input tokens and the key patches, providing a solid mathematical foundation for the "focus" intuition.

Key Results

FORT consistently improved performance across all tested backbones (ViT, Swin) and fine-tuning methods (Full FT, LoRA, SSF):

  • Significant Accuracy Boosts: On the CUB dataset (1-shot), adding FORT to LoRA improved accuracy from 57.9% to 62.5% (a +4.6% jump).
  • State-of-the-Art in New Settings: In the 5-way 1-shot setting on miniImageNet, the method achieved 94.2% accuracy, dwarfing traditional meta-learning results.
  • Qualitative Success: Visualizations of attention maps show that while standard fine-tuning often leaves the model looking at background noise, FORT-enabled models tightly "lock on" to the primary object.

Limitations and Future Work

  • Architecture Specificity: The current method is tailored for Transformers with multi-head attention. It is not directly applicable to older architectures like ResNets or newer non-attention models like MLP-Mixers.
  • Prompt Reliability: In highly specialized domains (e.g., medical or satellite imagery), the automatic "deep explanation" might fail to identify the correct key entities. In these cases, expert-labeled position prompts might still be necessary.
  • Computational Overhead: Generating the position prompts requires an initial pass with gradient calculation, which adds a small amount of computational cost during the start of the fine-tuning phase.

Summary updated

BibTeX
@inproceedings{wang2023focus,
  author = {Haoqing Wang and Shibo Jie and Zhi-Hong Deng},
  title = {{Focus Your Attention when Few-Shot Classification}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2023},
  url = {https://openreview.net/forum?id=uFlE0qgtRO},
}
Figure