Class-relevant Patch Embedding Selection for Few-Shot Image Classification

Weihao Jiang, Haoyang Cui, Kun HearXiv 2024 · DOI

Abstract

Few-shot learning (FSL) aims to recognize novel classes from a very limited number of labeled examples. A significant challenge in this domain is the presence of background noise, which can lead models to learn non-discriminative features. This paper introduces Class-relevant Patch Embedding Selection (CPES), a method that leverages the global class embedding of a Vision Transformer (ViT) to identify and retain only the most relevant local patches. By discarding background interference and focusing on the foreground object, CPES achieves state-of-the-art results on major benchmarks like miniImageNet and tieredImageNet without requiring complex additional network modules or extra learnable parameters.

Introduction

The core challenge in few-shot learning is the discriminative capacity of features. In a typical image, the actual object of interest (the foreground) often occupies only a small fraction of the total pixels. When a model is trained on only one or five images, it lacks the statistical perspective to distinguish essential features from incidental background scenery. Existing methods often attempt to address this through complex attention mechanisms or "collect-and-select" strategies. However, these approaches frequently allow background interference to leak into the final representation and often introduce numerous learnable parameters, increasing the risk of overfitting in data-scarce scenarios.

Methodology

The authors propose the CPES framework, which utilizes a Vision Transformer (ViT) pre-trained via Masked Image Modeling (MIM). The pipeline follows a structured four-step process:

  1. Extraction: The input image is split into patches and processed by the ViT to produce a global class embedding ($[CLS]$ token) and several local patch embeddings.
  2. Selection: This stage calculates the cosine similarity between the global class embedding and every individual patch embedding. The patches are sorted, and only the top $m$ most "class-relevant" patches are retained.
  3. Fusion: The selected patch embeddings are fused with the global class embedding via linear addition, ensuring each local feature is enriched with global semantic context.
  4. Classification: To compare a query image to a support image, the model computes a dense similarity matrix between their selected patches. This matrix is flattened and passed through a simple Multi-Layer Perceptron (MLP) to generate a final similarity score.
The CPES pipeline illustrating the extraction, selection, fusion, and similarity measurement stages.

Crucially, the selection process requires no extra learnable parameters, making it both lightweight and robust against overfitting.

Experimental Evaluation

The CPES method was evaluated on four widely recognized few-shot classification benchmarks:

  • miniImageNet: 100 classes with 600 images each.
  • tieredImageNet: A large-scale version of ImageNet with 608 classes organized into broader categories.
  • CIFAR-FS: A few-shot version of the CIFAR-100 dataset.
  • FC100: A CIFAR-derived dataset with a challenging "super-category" split to test generalization.

Key Insights and Results

The research highlights several critical findings:

  • The $[CLS]$ Token as a Filter: The global class embedding in a pre-trained ViT possesses a strong inherent sense of the primary object. Using it as a query to find relevant patches effectively masks out irrelevant backgrounds like grass, sky, or water.
  • Optimal Patch Selection: Ablation studies identified a "Goldilocks" effect in patch selection. While using all 196 patches introduced noise, selecting exactly 96 patches provided the best balance—capturing the object while excluding environmental noise.
  • Dense Comparison: By comparing patches directly rather than averaging them into a single prototype, the model can find local correspondences even when objects are positioned differently across images.
Visualization of class-relevant patch selection, demonstrating the model's ability to focus on the foreground object while masking background noise.

CPES consistently outperformed state-of-the-art (SOTA) baselines. On miniImageNet, it achieved 73.62% (1-shot) and 88.61% (5-shot). On tieredImageNet, it reached 78.25% (1-shot) and 91.25% (5-shot).

Conclusion and Limitations

CPES demonstrates that intelligent feature selection is often superior to increasing model complexity. However, the authors note some limitations: the number of selected patches ($m=96$) is currently a fixed hyperparameter, and the method's success is closely tied to the quality of the pre-trained ViT backbone. Additionally, the use of dense similarity matrices and MLPs for every pair increases computational costs compared to simpler distance metrics. Future work may focus on adaptive selection mechanisms to further refine the efficiency and accuracy of few-shot classification.

Summary updated

BibTeX
@misc{jiang2024class,
  author = {Weihao Jiang and Haoyang Cui and Kun He},
  title = {{Class-relevant Patch Embedding Selection for Few-Shot Image Classification}},
  year = {2024},
  eprint = {2405.03722},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2405.03722},
}
Figure