Understanding Few-Shot Learning in Computer Vision: What You Need to Know

简介: Few-Shot Learning is a sub-area of machine learning. It’s about classifying new data when you have only a few training samples with supervised information.FSL is a rather young area that needs more research and refinement. As of today, you can use it in CV tasks. A computer vision model can work

Since the first convolutional neural network (CNN) algorithms were created, they have drastically improved deep learning performance on computer vision (CV) tasks. 

In 2015, Microsoft reported that their model was actually better than humans at classifying images from the ImageNet dataset.[1]

Nowadays, computers have no match when it comes to using billions of images to solve a specific task. Still, in the real world, you can rarely build or find a dataset with that many samples.

How do we overcome this problem? If we’re talking about a CV task, we can use data augmentation (DA), or collect and label additional data. 

DA is a powerful tool and might be a big part of the solution. Labeling additional samples is a time-consuming and expensive task, but it does deliver better results.

If the dataset is really small, both of these techniques might not help us. Imagine a task where we need to build a classification with only one or two samples per class, and each sample is super difficult to find. 

This would call for innovative approaches. Few-Shot Learning (FSL) is one of them.

In this article we’ll cover:

  • What Few-Shot Learning is – definition, purpose, and FSL problem example
  • Few-Shot Learning variations – N-Shot Learning, Few-Shot Learning, One-Shot Learning, Zero-Shot Learning
  • Few-Shot Learning approaches – Meta-Learning, Data-level, Parameter-level 
  • Meta-Learning algorithm – definition, Metric-Learning, Gradient-Based Meta-Learning
  • Algorithms for Few-Shot image classification – Model-Agnostic Meta-Learning, Matching, Prototypical and Relation Networks
  • Few-Shot Object Detection – YOLOMAML

What is Few-Shot learning?

Few-Shot Learning is a sub-area of machine learning. It’s about classifying new data when you have only a few training samples with supervised information.

FSL is a rather young area that needs more research and refinement. As of today, you can use it in CV tasks. A computer vision model can work quite well with relatively few training samples. Throughout this article, we’ll be focusing on FSL in computer vision.

For example: say we work in healthcare and have a problem with categorizing bone illnesses via x-ray photos. 

Some rare pathologies might lack enough images to be used in the training set. This is exactly the type of problem that can be solved by building an FSL classifier.

Few-Shot variations

Let’s take a look at different variations and extreme cases of FSL. In general, researchers identify four types:

  1. N-Shot Learning (NSL)
  2. Few-Shot Learning
  3. One-Shot Learning (OSL)
  4. Less than one or Zero-Shot Learning (ZSL)

When we’re talking about FSL, we usually mean N-way-K-Shot-classification.

N stands for the number of classes, and K for the number of samples from each class to train on.

N-Shot Learning is seen as a more broad concept than all the others. It means that Few-Shot, One-Shot, and Zero-Shot Learning are sub-fields of NSL.

Zero-Shot

To me, ZSL is the most interesting. The goal of Zero-Shot Learning is to classify unseen classes without any training examples.

It may seem a little crazy, but think about it this way: can you classify an object without even seeing it? If you have the general idea of an object, its appearance, properties, and functionality, it shouldn’t be a problem.

This is the approach that you use when doing ZSL and, according to current trends, Zero-Shot Learning will soon become more effective.

One-Shot and Few-Shot

By this point, you probably see a general concept, so it’ll be no surprise that in One-Shot Learning, we only have a single sample of each class. Few-Shot has two to five samples per each class, making it just a more flexible version of OSL.

When we talk about the overall concept, we use the Few-Shot Learning term. But this area is quite young, so people will use these terms differently. Keep that in mind when you’re reading articles.

Few-Shot learning approaches

All right, time to move to a more practical field and talk about different Few-Shot Learning problem approaches.

First of all, let’s define an N-way-K-Shot-classification problem. Imagine that we have:

  1. A training (support) set that consists of:

    1. N class labels
    2. K labeled images for each class (a small amount, less than ten samples per class)
  2. Q query images

We want to classify Q query images among the N classes. The N * K samples in the training set are the only examples that we have. The main problem here is not enough training data. [1]

few-shot-classification-problem

Few-Shot Image Classification with Meta-Learning

The first and most obvious step in an FSL task is to gain experience from other, similar problems. This is why Few-Shot Learning is characterized as a Meta-Learning problem.

Let’s make this clear: in a traditional classification problem, we try to learn how to classify from the training data, and evaluate using test data. 

In Meta-Learning, we learn how to learn to classify given a set of training data. We use one set of classification problems for other, unrelated sets.

Generally, there are two approaches that you should consider when solving FSL problems:

  • Data-level approach (DLA)
  • Parameter-level approach (PLA)

Data-level approach

This approach is really simple. It’s based on the concept that if you don’t have enough data to build a reliable model and avoid overfitting and underfitting, you should simply add more data.

That is why many FSL problems are solved by using additional information from a large base-dataset. The key feature of the base-dataset is that it doesn’t have classes that we have in our support-set for the Few-Shot task. For example, if we want to classify a specific bird species, the base-dataset can have images of many other birds.

We can also produce more data ourselves. To reach this goal, we can use data augmentation, or even generative adversarial networks (GANs). 

Parameter-level approach

From the parameter-level point of view, it’s quite easy to overfit on Few-Shot Learning samples, as they have extensive and high-dimensional spaces quite often.

To overcome this problem we should limit the parameter space and use regularization and proper loss functions. The model will generalize the limited number of training samples.

On the other hand, we can enhance model performance by directing it to the extensive parameter space. If we use a standard optimization algorithm, it might not give reliable results because of the small amount of training data.

That is why on the parameter-level we train our model to find the best route in the parameter space to give optimal prediction results. As we have already mentioned above, this technique is called Meta-Learning.

Meta-Learning algorithm

In the classic paradigm, when we have a specific task, an algorithm is learning if its task performance improves with experience. In the Meta-Learning paradigm, we have a set of tasks. An algorithm is learning to learn if its performance at each task improves with experience and with the number of tasks. This algorithm is called a Meta-Learning algorithm.

Imagine that we have a test task TEST. We will train our Meta-Learning algorithm on a batch of training tasks TRAIN. Training experience gained from attempting to solve TRAIN tasks will be used to solve the TEST task.

Solving an FSL task has a set sequence of steps. Imagine we have a classification problem as we mentioned before. To start, we need to choose a base-dataset. Choosing a base-dataset is crucial. You want to pick a good one, so be careful.

Right now we have the N-way-K-Shot-classification problem (let’s name it TEST) and a large base-dataset that we’ll use as a Meta-Learning training set (TRAIN). 

The whole Meta-Training process will have a finite number of episodes. We form an episode like this:

From the TRAIN, we sample N classes and K support-set images per each class, along with Q query images. This way, we form a classification task that’s similar to our ultimate TEST task. 

At the end of each episode, the parameters of the model are trained to maximize the accuracy of Q images from the query set. This is where our model learns the ability to solve an unseen classification problem. [1]

The overall efficiency of the model is measured by its accuracy on the TEST classification task.

meta-learning

Few-Shot Image Classification with Meta-Learning

In recent years, researchers published many Meta-Learning algorithms for solving FSL classification problems. All of them can be divided into two large groups: Metric-Learning and Gradient-Based Meta-Learning algorithms.

Metric-Learning

When we talk about Metric-Learning, we usually refer to the technique of learning a distance function over objects. 

In general, Metric-Learning algorithms learn to compare data samples. In the case of a Few-Shot classification problem, they classify query samples based on their similarity to the support samples. 

As you might have already guessed, if we’re working with images, we basically train a convolutional neural network to output an image embedding vector, which is later compared to other embeddings to predict the class.

Gradient-Based Meta-Learning

For the Gradient-Based approach, you need to build a meta-learner and a base-learner.

Meta-learner is a model that learns across episodes, whereas a base-learner is a model that is initialized and trained inside each episode by the meta-learner.

Imagine an episode of Meta-training with some classification task defined by a N * K images support-set and a Q query set:

  1. We choose a meta-learner model,
  2. Episode is started,
  3. We initialize the base-learner (typically a CNN classifier),
  4. We train it on the support-set (the exact algorithm used to train the base-learner is defined by the meta-learner),
  5. Base-learner predicts the classes on the query set,
  6. Meta-learner parameters are trained on the loss resulting from the classification error,
  7. From this point, the pipeline may differ based on your choice of meta-learner. [1]

Algorithms for Few-Shot image classification

This section comes from “Few-Shot Image Classification with Meta-Learning“, written by Etienne Bennequin.

From the general picture, let’s move on to the specific Meta-Learning algorithms that are used to solve Few-Shot Learning image classification problems.

In this section we’ll cover:

  1. Model-Agnostic Meta-Learning (MAML)
  2. Matching Networks
  3. Prototypical Networks
  4. Relation Network

Model-Agnostic Meta-Learning

MAML is based on the Gradient-Based Meta-Learning (GBML) concept. As we’ve already figured out, GBML is about the meta-learner acquiring prior experience from training the base-model and learning the common features representations of all tasks.

Whenever there is a new task to learn, the meta-learner with its prior experience will be fine-tuned a little bit using the small amount of new training data brought by the new task. 

Still, we don’t want to start from a random parameter initialization. If we do so, our algorithm will not converge to good performance after a few updates.

MAML aims to solve this problem.

MAML provides a good initialization of a meta-learner’s parameters to achieve optimal fast learning on a new task with only a small number of gradient steps while avoiding overfitting that may happen when using a small dataset.

Here is how it’s done:

  1. The meta-learner creates a copy of itself (C) at the beginning of each episode,
  2. C is trained on the episode (just as we have previously discussed, with the help of base-model),
  3. C makes predictions on the query set,
  4. The loss computed from these predictions is used to update C,
  5. This continues until you’ve trained on all episodes.

maml-algorithm

The greatest advantage of this technique is that it’s conceived to be agnostic of the meta-learner algorithm choice. Thus, the MAML method is widely used with many machine learning algorithms that need fast adaptation, especially Deep Neural Networks.

Matching Networks

Matching Networks (MN) was the first Metric-Learning algorithm designed to solve FSL problems.

For the Matching Networks algorithm, you need to use a large base-dataset to solve a Few-Shot Learning task. As shown above, this dataset is split into episodes. After that, for each episode, Matching Networks apply the following procedure:

  1. Each image from the support and the query set is fed to a CNN that outputs embeddings for them,
  2. Each query image is classified using the softmax of the cosine distance from its embeddings to the support-set embeddings,
  3. The Cross-Entropy Loss on the resulting classification is backpropagated through the CNN.

This way, Matching Networks learn to compute image embeddings. This approach allows MN to classify images with no specific prior knowledge of classes. Everything is done simply by comparing different instances of the classes.

Since the classes are different in every episode, Matching Networks compute features of the images that are relevant to discriminate between classes. On the contrary, in the case of a standard classification, the algorithm learns the features that are specific to each class. 

It’s worth mentioning that the authors actually proposed some improvements to the initial algorithms. For example, they augmented their algorithm with bidirectional LSTM. The embedding of each image started depending on the embeddings of the others.

All improvement proposals may be found in their initial article. Still, you must remember that improving the performance of the algorithm might make the computational time longer.

Prototypical Networks

Prototypical Networks (PN) are similar to Matching Networks. Still, there are small differences that help to enhance the algorithm’s performance. PN actually obtains better results than MN.

The PN process is essentially the same, but the query image embeddings are not compared to every image embedding from the support set. Instead, Prototypical Networks propose an alternative approach.

In PN, you need to form class prototypes. They are basically class embeddings formed by averaging the embeddings of images from this class. The query image embeddings are then compared only to these class prototypes.

It’s worth mentioning that in the case of a One-Shot Learning problem, the algorithm is similar to Matching Networks.

Also, PN uses Euclidean distance instead of cosine distance. It’s seen as a major part of the algorithm’s improvements.

Relation Network

All experiments carried out to build Matching and Prototypical Networks actually led to the creation of the Relation Network (RN). RN was built on the PN concept but added big changes to the algorithm.

The distance function was not defined in advance but learned by the algorithm. RN has its own relation module that does this. If you want to learn more, check out the initial article.

The overall structure is as follows. The relation module is put on the top of the embedding module, which is the part that computes embeddings and class prototypes from input images.

The relation module is fed with the concatenation of the embedding of a query image with each class prototype, and it outputs a relation score for each couple. Applying a Softmax to the relation scores, we get a prediction.

relation-network

Source

Few-Shot Object Detection

This section comes from “Meta-learning algorithms for Few-Shot Computer Vision“, written by Etienne Bennequin.

It’s quite obvious that we may encounter FSL problems in all Computer Vision tasks. We have considered Few-Shot image classification, now it’s time to tackle the Few-Shot Object Detection problem.

Let’s define an Object Detection task. Imagine that we have a list of object types and an image, and the goal is to detect all objects from the list on the image. We’ll say that the object is detected if:

  1. we localized it by drawing the smallest bounding box possible that contains it,
  2. we classified the object.

Let’s move on and define the N-way-K-Shot Object Detection task. Imagine:

  1. A support-set composed of:

    1. N class labels,
    2. For each class, K labeled images containing at least one object belonging to this class,
  2. Q query images.

Our goal is to detect objects belonging to one of the N given classes in the query images.

Note that there is a key difference with the Few-Shot image classification problem, as one image can contain multiple objects belonging to one or several of the N classes. We might face a class imbalance problem, as our algorithm trains on at least K example objects of each class.

YOLOMAML

The Few-Shot Object Detection sphere is quickly developing, but there aren’t many efficient solutions. The most stable solution to this problem is the YOLOMAML algorithm.

YOLOMAML has two blended pieces: YOLOv3 Object Detection architecture, and the MAML algorithm. 

As mentioned earlier, MAML can be applied to a wide variety of Deep Neural Networks, which is why it was easy for developers to combine these two pieces.

YOLOMAML is a straightforward application of the MAML algorithm to the YOLO detector. If you want to learn more, check out the official Github repository.

Final thoughts

In this article, we have figured out what Few-Shot Learning is, what FSL variations and problem approaches there are, and what algorithms you can use to solve image classification and Object Detection FSL tasks.

To my knowledge, Few-Shot Learning is a quickly developing and promising field, but still quite challenging and unresearched. There is a lot more to be done, researched, and developed.

Hopefully, with this information, you will have no problems starting to experiment in the Few-Shot Learning field.

目录
相关文章
|
传感器 编解码 IDE
ESP32开发板引脚介绍【附有引脚使用实例】
ESP32开发板引脚介绍👨‍🏫内容1:背景👨‍⚖️内容2:限制类引脚👨‍💻内容3:ESP32 周边设备🍉文末备注 👨‍🏫。
ESP32开发板引脚介绍【附有引脚使用实例】
|
API
Element UI Loading 加载组件动态变更 text 值(加载文案)
有这样的一个需求,我在上传文件的时候,上传阶段耗时较长,所以利用加载动画作为友好提示用户等待。
2119 0
Element UI Loading 加载组件动态变更 text 值(加载文案)
|
6月前
|
运维 开发者
同样标注为 Claude,为何效果差异明显:中转链路模型一致性排查实录
同样标注为 Claude,为什么线上效果会出现明显差异?本文基于一次真实排查,给出“总览体检—来源下钻—隔离对照—复检恢复”的工程化方法,重点解决中转链路中的模型一致性与路由漂移问题。适合正在做大模型应用稳定性治理、可观测性建设与故障复盘的团队参考。
294 2
同样标注为 Claude,为何效果差异明显:中转链路模型一致性排查实录
|
9月前
|
安全 Java API
Java 8+ 核心高阶特性全解:Lambda、Stream、CompletableFuture 从底层原理到生产最佳实践
本文深入解析Java8至17版本中Lambda表达式、Stream流和CompletableFuture三大核心特性的底层原理与生产实践。Lambda表达式基于invokedynamic指令实现,性能优于匿名内部类;Stream流通过惰性求值机制实现高效集合操作,支持并行处理;CompletableFuture提供完善的异步编程能力,支持任务组合与超时控制。
825 2
|
人工智能 小程序 vr&ar
AR体感游戏,拓宽AI运动小程序的应用边界
AR体感游戏融合AI与AR技术,通过摄像头捕捉动作,将运动变为趣味互动。无需穿戴设备,手机即可畅玩,适合全年龄段,尤其激发低龄儿童运动兴趣。沉浸式体验让锻炼如游戏般上瘾,广泛应用于赛事、团建、校园及康复场景,借助AI运动识别插件,开发更高效便捷。
|
11月前
|
存储 缓存 NoSQL
阿里云数据库KVStore兼容Redis亚毫秒级的稳定时延,Tair数据库企业版
阿里云KVStore(兼容Redis®)提供亚毫秒级时延、99.99%高可用,支持多存储介质降本30%~70%,兼具高性能、高可靠与易运维,助力米哈游、雪球等企业实现架构升级,Tair企业版更以丰富特性重新定义云原生键值数据库。
485 2
|
9月前
|
人工智能 弹性计算 数据中心
2026年购买阿里云产品省钱代金券,个人360元单笔最高减150元,企业1728元,单笔最高减800元
2026年,阿里云推出多种代金券,其中AI焕新季活动力度最大,个人用户可领360元、企业用户可领1728元代金券,单笔订单最高分别减150元和800元。此外,还有学生无门槛300元优惠券、企业迁云5亿补贴及出海最高10万元扶持。代金券需在指定云产品新购或升级时使用,且订单时长为1年及以内。阿里云通过多层次优惠体系,助力用户降低上云成本,建议用户根据自身需求领取并使用优惠券。
641 5
|
11月前
|
人工智能 缓存 调度
深度解析:AI Agent 指挥官如何通过调度策略降低算力成本
2026年,算力成本成AI落地最大瓶颈。本文提出“AI Agent指挥官”范式,聚焦成本感知调度:通过异构模型路由、语义缓存增强、异步并行批处理与动态提示精简四大策略,实现智能与经济的最优平衡,实测降本达83%。(239字)
859 0
|
弹性计算 自然语言处理 测试技术
30分钟私有部署Deepseek-R1和V3,轻松拥有企业专属超大模型
阿里云计算巢推出了基于 ECS镜像、Vllm和Ray集群的超大模型一键部署方案。该方案通过预置标准化环境的ECS镜像,结合自动化云资源编排模板(如Ros模板),将Deepseek-R1和Deepseek-V3的私有化部署流程简化为一键操作。用户无需深入理解底层技术细节,即可在 30分钟内 快速完成模型环境搭建与服务启动,真正实现“开箱即用”的企业级超大模型服务。
|
12月前
|
供应链 监控 搜索推荐
一文读懂 SRM 系统:数字化采购的核心引擎,功能全解析
SRM系统是企业采购数字化转型的核心工具,通过供应商管理、智慧寻源、合同订单、财务协同、库存管控及数据分析等全链路功能,实现采购全流程线上化、智能化。系统提升采购效率与透明度,降低风险与成本,助力企业构建高效、合规、可追溯的供应链体系,已成为零售、制造、医疗、IT等多行业降本提效的“必选项”。

热门文章

最新文章