Visual-Semantic Contrastive Alignment for Few-Shot Image Classification

Mohamed Afham, Ranga RodrigoarXiv 2022 · DOI

Abstract

Few-shot learning (FSL) remains a significant challenge for machine learning models due to the extreme scarcity of visual data. This paper introduces VS-Alignment, a framework that leverages semantic information from class descriptions to enhance visual feature learning. By aligning visual prototypes with semantic embeddings through a contrastive loss, the model incorporates linguistic priors into the visual representation space. Evaluated on the CUB and mini-ImageNet benchmarks, VS-Alignment demonstrates significant performance gains over standard episodic FSL baselines, particularly in fine-grained classification tasks.

Introduction

Few-shot learning aims to recognize new objects after seeing only a handful of examples—a task humans excel at but machines find notoriously difficult. Most current FSL methods rely exclusively on visual data. However, when only one or two pictures of a "Toucan" are available, visual features alone might not be enough to generalize effectively.

The authors argue that standard models ignore a massive source of information: semantics. In the real world, humans don't just see a bird; they know it has a "massive bill" and "brightly colored plumage." By treating class labels as mere numerical IDs, standard models fail to leverage the rich contextual knowledge embedded in language.

Methodology

The authors propose a framework called VS-Alignment (Visual-Semantic Alignment). It is designed as a "plug-and-play" module that can be added to existing episodic FSL methods.

The VS-Alignment architecture aligns visual prototypes from the support set with semantic prototypes derived from class descriptions using a contrastive objective.

Dual Prototypes

For every class in a training episode, the model generates two representative vectors:

  • Visual Prototype ($p_c$): Created by averaging the visual features of the support set images using a standard visual encoder ($f_\theta$).
  • Semantic Prototype ($p_s$): Created by passing textual descriptions of the class through a pre-trained semantic feature extractor ($g_\theta$), such as a CLIP-style Transformer encoder.

Contrastive Alignment

The core innovation is the use of an auxiliary NT-Xent (Normalized Temperature-scaled Cross Entropy) loss. This loss functions like a magnet: it pulls the visual prototype and its corresponding semantic prototype closer together in a shared embedding space, while pushing them away from prototypes of different classes.

Hybrid Learning

The final training objective is a weighted sum of the standard classification loss and this new visual-semantic contrastive loss. During inference, the "multimodal branch" is discarded, meaning the model does not require text descriptions to classify new images—it has already "learned" the semantic context during training.

Experiments and Key Results

The researchers evaluated their approach on two gold-standard FSL benchmarks: CUB (Caltech-UCSD Birds-200-2011) and mini-ImageNet.

Performance comparison on the CUB dataset using a Conv-4 backbone. VS-Alignment significantly outperforms standard baselines.

As shown in the results, the addition of VS-Alignment consistently outperformed the baselines:

  • CUB Dataset: VS-Alignment achieved 66.73% accuracy (5-way 1-shot), a significant jump over the Meta-Baseline (59.30%) and even outperforming recent specialized methods like RS-FSL (65.66%).
  • mini-ImageNet: The model reached 65.89% accuracy. While the improvement here was smaller than on CUB, it still provided a steady boost over the baseline (63.17%).

Discussion

Language as a Prior

The paper demonstrates that pre-trained language models contain a "contextual prior" that can guide visual learning. Even if a model only sees one image of a rare bird, the semantic embedding provides a "map" of where that bird should exist in the feature space relative to others. This synergy is most effective in episodic learning (meta-learning), where the model learns to quickly adapt its visual extractor using semantic cues.

Limitations and Future Work

While effective, the method relies on high-quality categorical descriptions; vague text could potentially mislead the visual encoder. Additionally, ablation studies found that while the method boosts episodic learners (like ProtoNet), it slightly decreased performance for non-episodic methods (like RFS). Future work may investigate bridging this gap and expanding the contrastive logic to other modalities, such as audio.

Summary updated

BibTeX
@misc{afham2022visual,
  author = {Mohamed Afham and Ranga Rodrigo},
  title = {{Visual-Semantic Contrastive Alignment for Few-Shot Image Classification}},
  year = {2022},
  eprint = {2210.11000},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2210.11000},
}
Figure