Abstract
Few-shot image classification remains a significant challenge in computer vision, requiring models to generalize to new categories from only a handful of examples. Traditional methods often rely on simple feature averaging to create class prototypes, a process that can overlook critical discriminative details. This paper introduces PrototypeFormer, a transformer-based framework designed to extract "relationship-aware" prototypes. By employing a Prototype Extraction Module (PEM) and a novel Prototype Contrastive Loss using sub-prototypes, the model effectively captures both intra-class similarities and inter-class differences. Experimental results demonstrate that PrototypeFormer sets a new state-of-the-art, notably achieving a 6.84% accuracy boost in 1-shot tasks on the miniImageNet benchmark.
Introduction
The goal of few-shot learning (FSL) is to enable models to recognize novel categories after seeing only one or five labeled examples (1-shot or 5-shot). A common approach is the "metric-based" method, exemplified by Prototypical Networks, which represents a class by the mean vector (prototype) of its support samples in a feature space.
However, the authors of PrototypeFormer argue that simple Global Average Pooling (GAP) is insufficient. As illustrated in Figure 1, different tasks require focusing on different features. For instance, distinguishing between two similar bird species might require focusing on specific "discriminative features" like beak shape or plumage patterns, which simple averaging might wash out. Furthermore, the scarcity of data makes these models highly susceptible to overfitting.
Methodology
PrototypeFormer addresses these limitations through three primary architectural innovations: the Prototype Extraction Module, the use of sub-prototypes for contrastive learning, and the integration of a powerful frozen backbone.
Prototype Extraction Module (PEM)
Instead of static averaging, PrototypeFormer utilizes a Transformer-based architecture to dynamically generate prototypes. The system treats the class prototype as a "learnable token" (akin to the [CLS] token in BERT). This token is processed alongside the embeddings of the support set images. Through self-attention mechanisms, the model learns to weigh features based on their relevance to the specific classification task, capturing global relationships among intra-class samples that simple pooling would miss.
Sub-prototypes and Contrastive Learning
To improve robustness and prevent overfitting, the authors introduce a Prototype Contrastive Loss. In a typical few-shot scenario, the number of samples is too small for effective contrastive learning. PrototypeFormer overcomes this by generating "sub-prototypes"—linear combinations of the available support set features. This effectively augments the prototype space, creating enough positive and negative pairs to apply contrastive objectives. This process pulls sub-prototypes of the same class closer together while pushing those from different classes apart, leading to a more discriminative feature space.
Frozen CLIP Backbone
The framework leverages the extensive pre-trained knowledge of CLIP (ViT-Large/14). By keeping the CLIP feature extractor frozen and only training the Prototype Extraction Module, the model retains the broad, zero-shot capabilities of CLIP while specializing it for the few-shot task at hand.
Experiments and Results
The model was rigorously evaluated on three standard few-shot learning benchmarks: miniImageNet, tieredImageNet, and the fine-grained CUB-200 dataset.
PrototypeFormer demonstrated superior performance across all benchmarks, significantly outperforming previous state-of-the-art (SOTA) methods:
| Dataset | 1-shot Accuracy | 5-shot Accuracy |
|---|---|---|
| miniImageNet | 90.88% (+6.84%) | 97.07% |
| tieredImageNet | 87.26% | 95.00% |
| CUB-200 | 89.04% | 94.25% |
The 6.84% improvement on 1-shot miniImageNet is particularly noteworthy, as 1-shot tasks are traditionally the most difficult due to the extreme lack of data. Qualitative analysis using t-SNE visualizations further confirms that PrototypeFormer produces much tighter and more distinct class clusters than traditional averaging methods.
Discussion and Conclusion
PrototypeFormer shifts the focus of few-shot learning from simple feature aggregation to the exploration of complex sample relationships. By using attention mechanisms and contrastive learning on augmented sub-prototypes, it builds more robust and discriminative class representations.
One inherent limitation identified by the authors is the 1-shot scenario for contrastive loss. Since only one sample per class is available, forming natural "positive pairs" within the support set is impossible. While the model still performs exceptionally well due to the PEM and the CLIP backbone, the contrastive loss component is inherently more powerful in 5-shot scenarios. Future research may focus on better synthetic pair generation for 1-shot tasks to further bridge this gap.
Summary updated