Learning a Few-shot Embedding Model with Contrastive Learning

Chen Liu, Yanwei Fu, Chengming Xu, Siqian Yang, Jilin Li, Chengjie Wang, Li Zhang

Abstract

Few-shot learning (FSL) remains a significant challenge in computer vision, requiring models to generalize to novel categories from extremely limited data. This paper introduces infoPatch, a framework that leverages supervised contrastive learning and a novel data augmentation technique, PatchMix, to build robust embedding models. By shifting the focus from global image classification to local patch-based matching, the proposed method effectively reduces reliance on spurious correlations and improves generalization to unseen classes.

Introduction

The primary goal of few-shot learning is to achieve human-like recognition capabilities, where a new object can be identified after seeing only a few examples. Standard deep learning models often struggle in this regime because they tend to memorize specific correlations within the training data—such as background features—rather than learning generalizable object representations. This "inductive bias" leads to failure when the model encounters the same object in a different context. To address this, the authors propose an embedding space where categories are naturally clustered based on essential features rather than non-essential scene details.

Methodology

The proposed framework consists of two core components designed to enhance the robustness of the learned embeddings within an episodic training setup.

infoPatch: Supervised Contrastive Learning

Instead of traditional cross-entropy loss, the authors adapt the infoNCE (Noise Contrastive Estimation) loss for FSL. To increase the difficulty of the task and encourage the learning of granular features, they implement a "hard sample mining" strategy. Support images undergo "random blocking," while query images are divided into a grid of patches. The model is then tasked with matching individual query patches to the corresponding support images. This forces the network to recognize objects even when only partial information is available.

PatchMix Augmentation

Inspired by CutMix, PatchMix is specifically tailored for the few-shot setting. During training, a patch from one query image is randomly replaced with a patch from a different image within the same episode. Crucially, each patch maintains its original label. This process prevents the model from relying on global image correlations (e.g., background color) and forces it to disentangle object-specific information from its surroundings.

Overview of the infoPatch framework and PatchMix augmentation strategy.

Experiments and Key Insights

The model was evaluated on three benchmark datasets: miniImageNet, tieredImageNet, and Fewshot-CIFAR100 (FC-100). Several key insights emerged from these experiments:

  • Contrastive Learning Superiority: Contrastive objectives are inherently better for FSL than static classification because they emphasize the relationships and similarities between images.
  • Granular Feature Extraction: Training on patches allows the model to identify objects based on local parts (e.g., a bird's beak), leading to a deeper understanding of the category.
  • Regularization via PatchMix: By breaking consistent backgrounds, PatchMix acts as a powerful regularizer, forcing the model to focus on the object of interest.

Key Results

The proposed method achieved state-of-the-art or highly competitive performance across all benchmarks. On miniImageNet, the model reached 67.67% accuracy on 1-shot tasks. On tieredImageNet, it achieved 85.44% on 5-shot tasks. Ablation studies confirmed that the combination of infoNCE, patch-based matching, and PatchMix significantly improved the baseline performance by approximately 6%.

t-SNE visualization comparing the baseline embedding space with the proposed model.

Visual analysis using t-SNE plots demonstrates that the infoPatch framework produces much tighter and more distinct clusters for novel classes compared to standard baseline models, confirming the improved quality of the embedding space.

Conclusion and Future Work

While highly effective, the infoPatch framework is sensitive to the chosen grid size for patches; patches that are too small may contain only noise, while those that are too large reduce the effectiveness of the hard sample mining. Additionally, patch-wise contrastive loss increases training complexity. Future research may explore optimized episode sampling or the application of these patch-wise techniques to other few-shot tasks, such as semantic segmentation.

Summary updated

BibTeX
@inproceedings{liu2021learning,
  author = {Chen Liu and Yanwei Fu and Chengming Xu and Siqian Yang and Jilin Li and Chengjie Wang and Li Zhang},
  title = {{Learning a Few-shot Embedding Model with Contrastive Learning}},
  booktitle = {AAAI Conference on Artificial Intelligence},
  year = {2021},
  doi = {10.1609/aaai.v35i10.17047},
}
Figure