Diagnosing and Remedying Shot Sensitivity with Cosine Few-Shot Learners

Davis Wertheimer, Luming Tang, Bharath HariharanarXiv 2022

Abstract

Few-shot recognition involves training an image classifier to distinguish novel concepts at test time using few examples (shot). Existing approaches generally assume that the shot number at test time is known in advance. This is not realistic, and the performance of a popular and foundational method has been shown to suffer when train and test shots do not match. We conduct a systematic empirical study of this phenomenon. In line with prior work, we find that shot sensitivity is broadly present across metric-based few-shot learners, but in contrast to prior work, larger neural architectures provide a degree of built-in robustness to varying test shot. More importantly, a simple, previously known but greatly overlooked class of approaches based on cosine distance consistently and greatly improves robustness to shot variation, by removing sensitivity to sample noise. We derive cosine alternatives to popular and recent few-shot classifiers, broadening their applicability to realistic settings. These cosine models consistently improve shot-robustness, outperform prior shot-robust state of the art, and provide competitive accuracy on a range of benchmarks and architectures, including notable gains in the very-low-shot regime.

Introduction: The Problem of Shot Sensitivity

In few-shot learning, models are trained to recognize new categories using only a handful of examples (e.g., 1 or 5 "shots"). The standard approach, known as episodic training, typically assumes the model will encounter the same number of shots at test time as it did during training. However, in real-world applications, the number of available images for a new category is unpredictable.

When the training shot and test shot do not match, the performance of many popular learners degrades significantly. This "shot sensitivity" occurs because Euclidean-based models learn different clustering behaviors depending on the shot count: low-shot training forces rigid clusters to combat noise, while high-shot training allows for more diffuse clusters that are easily distracted by noise when data is scarce at test time.

Methodology: The Shift to Cosine Distance

To address this, the researchers conducted a systematic study across different architectures and algorithms. Their primary intervention is replacing Euclidean distance with Cosine similarity. This change was implemented across three major few-shot frameworks: ProtoNet, FEAT, and Feature map Reconstruction Networks (FRN). For FRN specifically, the authors reformulated the reconstruction logic from a mean-squared error approach to a dot product of flattened, normalized covariance matrices.

Geometric intuition: Euclidean decision boundaries (top) can wobble wildly based on sample noise, while Cosine boundaries (bottom) are anchored at the origin, providing greater stability.

The geometric advantage of cosine similarity lies in its "origin anchor." Unlike Euclidean decision boundaries that can shift drastically based on sample noise, cosine boundaries are constrained to pass through the origin. This constraint makes the model more robust to the "jitter" inherent in low-data regimes.

Key Results and Analysis

The approach was evaluated on standard benchmarks including CUB, meta-iNat, mini-ImageNet, and tiered-ImageNet using Conv-4 and ResNet-12 backbones.

  • Massive Sensitivity Reduction: Cosine-based models reduced the spread of accuracy scores (sensitivity) by an average factor of 4.5 compared to Euclidean versions.
  • The 1-Shot Boost: The most dramatic gains were seen in the "very-low-shot" regime. In 1-shot tasks, cosine models frequently outperformed Euclidean models by double-digit accuracy gains.
  • Architecture as a Buffer: Larger backbones (like ResNet-12) provide some built-in robustness compared to smaller ones, though they still benefit significantly from the cosine swap.
Performance summary: Cosine accuracy gains are most prominent in low-shot settings, with model offsets showing improved stability across training shots compared to Euclidean baselines.

Conclusion

By removing sensitivity to sample noise through angular relationships, cosine-based few-shot learners provide a more reliable solution for real-world applications where data availability is uncertain. While this solves the shot mismatch problem, future work remains to address challenges like class imbalance within episodes and performance on long-tailed data distributions.

Summary updated

BibTeX
@misc{wertheimer2022diagnosing,
  author = {Davis Wertheimer and Luming Tang and Bharath Hariharan},
  title = {{Diagnosing and Remedying Shot Sensitivity with Cosine Few-Shot Learners}},
  year = {2022},
  eprint = {2207.03398},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2207.03398},
}
Figure