The general framework for few-shot learning by kernel HyperNetworks

Marcin Sendera, Marcin Przewiezlikowski, Jan Miksa, Mateusz Rajski, Konrad Karanowski, Maciej Zieba, Jacek Tabor, Przemyslaw SpurekMach. Vis. Appl 2023

Abstract

Few-shot models aim at making predictions using a minimal number of labeled examples from a given task. The main challenge in this area is the one-shot setting, where only one element represents each class. We propose the general framework for few-shot learning via kernel HyperNetworks—the fusion of kernels and hypernetwork paradigm. Firstly, we introduce the classical realization of this framework, dubbed HyperShot. Compared to reference approaches that apply a gradient-based adjustment of the parameters, our models aim to switch the classification module parameters depending on the task’s embedding. In practice, we utilize a hypernetwork, which takes the aggregated information from support data and returns the classifier’s parameters handcrafted for the considered problem. Moreover, we introduce the kernel-based representation of the support examples delivered to hypernetwork to create the parameters of the classification module. Consequently, we rely on relations between the support examples’ embeddings instead of the backbone models’ direct feature values. Thanks to this approach, our model can adapt to highly different tasks. While such a method obtains very good results, it is limited by typical problems such as poorly quantified uncertainty due to limited data size. We further show that incorporating Bayesian neural networks into our general framework, an approach we call BayesHyperShot, solves this issue.

Introduction

Deep learning typically requires massive datasets to generalize effectively. Humans, however, possess the remarkable ability to learn new concepts from just one or two examples—a capability known as few-shot learning (FSL). The core challenge in FSL research is the "one-shot" setting: building a reliable classifier when only a single labeled image per category is available.

Existing FSL methods often rely on meta-learning, where a model learns how to adapt quickly to new tasks. However, many of these approaches face significant hurdles. Gradient-based fine-tuning during inference can be slow, and many models struggle with cross-domain adaptation—generalizing when the new task differs significantly from the training data. Furthermore, most FSL models are "overconfident," lacking a mechanism to quantify their uncertainty, which is critical for safety-sensitive applications.

Methodology: HyperShot and BayesHyperShot

The proposed framework addresses these challenges by combining kernel methods with the HyperNetwork paradigm. The architecture is divided into three main stages: conditioning, weight generation, and classification.

The general framework of HyperShot and BayesHyperShot, illustrating the conditioning, weight generation, and classification modules.

HyperShot (The Classical Approach)

In the Conditioning Module, an image encoder (backbone $E$) extracts features $\mathbf{z}_S$ from the "support set" $S$. Instead of passing these raw features directly to the next stage, the model calculates a kernel matrix $\mathbf{K}_{S,S}$ (e.g., using cosine similarity). This matrix captures the internal relationships and similarities between all examples in the support set.

The Weight Generation stage employs a HyperNetwork $H$. This secondary network takes the kernel matrix as input and directly "handcrafts" the weights $\theta_{\mathcal{T}}$ for a target classification module $T$. Unlike methods that require multiple steps of gradient descent to adapt, HyperShot "switches" its parameters instantly based on the task embedding.

Finally, in the Classification Module, a new "query" image $\mathbf{x}_q$ is encoded, and its similarity to the support examples $\mathbf{k}_{q,S}$ is passed through the generated classifier $T$ to produce a probability distribution $p(y|\mathbf{x}_q, S)$.

BayesHyperShot (The Bayesian Extension)

To address the uncertainty problem, the authors incorporate Bayesian Neural Networks. In BayesHyperShot, the HyperNetwork predicts the parameters (mean $\mu_{\tau}$ and variance $\sigma_{\tau}$) of a probability distribution rather than fixed weights. Weights are then sampled from this distribution, allowing the model to express doubt and provide a measure of predictive variance.

Key Insights: Relations over Features

A fundamental innovation of this framework is the shift from raw feature values to relational representations. By using a kernel matrix, the HyperNetwork learns to generate weights based on how classes relate to each other geometrically in the feature space.

Geometric interpretation of the kernel-based representation using cosine similarities between support and query examples.

As shown in the geometric interpretation, the model relies on the angles ($\alpha$) between feature vectors. This relational approach makes the model significantly more robust during cross-domain adaptation (e.g., moving from general objects to specific bird species), as the relative structure of classes often remains more consistent than absolute feature magnitudes across domains.

Experimental Results

The framework was evaluated on standard benchmarks including CUB (Caltech-UCSD Birds) and mini-ImageNet, as well as challenging cross-domain tasks like mini-ImageNet $\to$ CUB.

  • State-of-the-Art Performance: HyperShot achieved 66.13% accuracy on 1-shot CUB and 53.18% on 1-shot mini-ImageNet, performing comparably to or better than established SOTA methods like FEAT.
  • Superior Generalization: In the mini-ImageNet $\to$ CUB cross-domain task, HyperShot outperformed competitors by a wide margin, reaching 40.03% in 1-shot settings where other methods typically achieved 35-37%.
  • Reliable Uncertainty: BayesHyperShot demonstrated its utility by showing a clear spike in activation variance when processing "out-of-distribution" samples—images from classes not present in the support set.

Conclusion

The kernel HyperNetwork framework provides a powerful and flexible approach to few-shot learning. By focusing on the relationships between examples and utilizing direct weight generation, HyperShot achieves high accuracy and exceptional cross-domain robustness. The Bayesian extension further enhances the model by providing reliable uncertainty quantification. Future work may explore more complex HyperNetwork architectures, such as Transformer-based models, to achieve true permutation invariance and extend the framework to other domains like regression and reinforcement learning.

Summary updated

BibTeX
@inproceedings{sendera2023general,
  author = {Marcin Sendera and Marcin Przewiezlikowski and Jan Miksa and Mateusz Rajski and Konrad Karanowski and Maciej Zieba and Jacek Tabor and Przemyslaw Spurek},
  title = {{The general framework for few-shot learning by kernel HyperNetworks}},
  booktitle = {Mach. Vis. Appl},
  year = {2023},
  url = {https://openreview.net/forum?id=GphxOVEi6Q},
}
Figure