Few-Shot Learning
Few-shot learning (FSL) recognizes new classes from a handful of labeled examples via metric learning, meta-learning, fine-tuning, or prompting.
Few-shot learning (FSL) is the problem of learning a new task, most often recognizing new classes, from only a few labeled examples per class, typically between 1 and 10. Standard supervised learning needs hundreds or thousands of labeled images per class, which are expensive or impossible to collect for rare defects, rare diseases, or a product that launched yesterday. Few-shot methods close the gap with prior knowledge: a model pretrained on large, related data already produces features that separate new classes well, so a handful of examples is enough to define them. The same idea appears in language models, where a few worked examples in the prompt steer the model to a new task without any training.
N-Way K-Shot Tasks#
Few-shot problems are described as N-way K-shot: N new classes, each with K labeled examples. These labeled examples form the support set, and the model is scored on how well it labels a separate query set of examples from the same N classes. A 5-way 1-shot task therefore gives the model one example each of five classes it has never seen and asks it to sort new images among them. One-shot learning is the K = 1 case, and zero-shot learning is K = 0, where classes are described by text or attributes instead of examples. Research benchmarks evaluate on classes held out from training, such as Omniglot, with 1,623 handwritten characters from 50 alphabets, and miniImageNet, with 100 ImageNet classes of 600 images each.
Approaches to Few-Shot Learning#
Metric-learning methods train a network to map images to embeddings in which examples of the same class sit close together, so a query takes the label of the most similar support examples. Prototypical networks average each class's support embeddings into a prototype and assign the query to the nearest one, which needs no retraining when a new class arrives.
Other approaches adapt the model's weights or its input:
- Meta-learning: Trains on thousands of small simulated tasks drawn from base classes, so the model learns how to adapt. Model-agnostic meta-learning (MAML) learns an initialization from which a few gradient steps on a new task's support set give good weights.
- Transfer and fine-tuning: Pretrain a backbone on a large dataset, then train only a new classifier head, or the whole network with a small learning rate, on the support set. This simple baseline is competitive with dedicated meta-learning methods on standard few-shot benchmarks, and linear probing of large pretrained models remains a strong few-shot baseline.
- Prompting foundation models: Large language models perform new tasks from a few examples placed in the prompt, with no weight updates, an ability GPT-3 demonstrated on more than two dozen language benchmarks. Vision models take visual prompts such as example boxes in the same way.
Few-Shot Object Detection with Visual Prompts#
Detection adds localization to the few-shot problem: the model must find every instance of a class it was not trained on. YOLO26 also powers YOLOE-26, an open-vocabulary variant whose visual prompt encoder turns example boxes into a class embedding and then detects and segments matching objects in new images, with no training. Boxes that share a class ID merge into one prompt, so two examples of a class act as a 2-shot support set. This example takes two people in one image as the support set and searches a different image:
import numpy as np
from ultralytics import YOLOE
from ultralytics.models.yolo.yoloe import YOLOEVPSegPredictor
# YOLOE-26 checkpoint that accepts visual prompts
model = YOLOE("yoloe-26s-seg.pt")
# Support set: two example boxes of one class (people) in the reference image
boxes = np.array([[221.52, 405.8, 344.98, 857.54], [669.47, 392.19, 809.72, 877.04]])
support = {"bboxes": boxes, "cls": np.array([0, 0])}
# Query: find objects like the examples in a different image, with no training
results = model.predict(
"https://ultralytics.com/images/zidane.jpg",
refer_image="https://ultralytics.com/images/bus.jpg",
visual_prompts=support,
predictor=YOLOEVPSegPredictor,
)
result = results[0]
result.save(filename="few_shot_result.jpg")Visual prompts group examples without naming them, so matches in the results are labeled object0, object1, and so on, one name per class ID.
Real-World Applications#
- Manufacturing inspection: A new defect type, such as a crack in a recently introduced part, may appear only a few times before inspectors want it flagged, and few-shot detection or anomaly detection adds it without a large new dataset.
- Medical imaging: Rare conditions have few annotated scans, so medical image analysis models adapt pretrained features to new findings from a small set of expert-labeled cases.
- Retail and robotics: Stores add new products and robots meet new objects constantly, and a few reference photos let a system recognize each one on the shelf or in the gripper.
Few-Shot Learning vs. Related Concepts#
- Transfer learning: The broader practice of reusing knowledge from one task for another. Few-shot learning is the extreme low-data case, and transfer is its most common tool.
- Meta-learning: A training strategy, learning how to learn, and one of several ways to solve few-shot problems. Few-shot learning names the problem setting itself.
- Few-shot prompting: Adapts a frozen model through examples in its input at inference time, while few-shot fine-tuning changes the model's weights using the same handful of examples.










