Ultralytics YOLO27: Join the waitlist.
License YOLO
Back to Ultralytics Glossary

Meta Learning

Meta-learning trains a model across many tasks so it adapts to a new task from a few examples. How episodes, MAML, and prototypical networks work.

Meta-learning, often called "learning to learn", is a machine learning (ML) approach that trains a model across many related tasks so that it can adapt to a new task quickly, usually from a handful of labeled examples. Where supervised learning fits one dataset, meta-learning optimizes the learning process itself: the starting weights, the embedding space used to compare examples, or a network that learns from examples in a single forward pass. Its main application is few-shot learning, recognizing new classes from one to a few examples each, along with robots and other agents that must adjust to new conditions on the fly.

How Meta-Learning Works#

Meta-learning trains in episodes that imitate the situation the model will face at test time. Each episode samples a task, for example a 5-way 1-shot classification problem built from five classes with one labeled image each. The labeled examples form the support set, and held-out examples of the same classes form the query set. In an inner loop, the model adapts to the support set; in an outer loop, the meta-parameters are updated according to how well the adapted model does on the query set, so the model is rewarded for adapting well rather than for memorizing any one task. Classes used for meta-testing never appear during meta-training.

Main Approaches#

  • Optimization-based: Model-Agnostic Meta-Learning (MAML) learns an initialization from which one or a few gradient descent steps on a new task's support set give good performance. The outer loop differentiates through the inner update, which requires second-order gradients; first-order variants such as OpenAI's Reptile avoid that cost by moving the initialization toward weights adapted on each task.
  • Metric-based: These methods learn an embedding space where examples can be classified by distance. Prototypical Networks average the support embeddings of each class into a prototype and assign each query to the nearest prototype, so adding a class at test time needs no training at all.
  • Model-based: A network such as a recurrent neural network (RNN) with external memory reads the support set and predicts labels for queries directly, learning the adaptation procedure in its activations. The GPT-3 paper described in-context learning in large language models (LLMs), solving a task from examples in the prompt, as the inner loop of this kind of meta-learning, with pretraining as the outer loop.

MAML's own regression benchmark asks a small network to fit sine waves of random amplitude and phase from 10 points each. The following PyTorch example meta-trains the initialization with both loops, then tests one adaptation step on new sine waves:

import torch
import torch.nn.functional as F
from torch import nn
from torch.func import functional_call

torch.manual_seed(0)
net = nn.Sequential(nn.Linear(1, 40), nn.ReLU(), nn.Linear(40, 40), nn.ReLU(), nn.Linear(40, 1))
meta_optimizer = torch.optim.Adam(net.parameters(), lr=0.001)


def sine_task_losses():
    """Sample a sine-wave task, adapt on 10 points with one gradient step, and return query losses before and after."""
    amplitude, phase = torch.empty(1).uniform_(0.1, 5), torch.empty(1).uniform_(0, 3.14)
    x = torch.empty(20, 1).uniform_(-5, 5)
    y = amplitude * torch.sin(x + phase)
    params = dict(net.named_parameters())
    support_loss = F.mse_loss(functional_call(net, params, x[:10]), y[:10])
    grads = torch.autograd.grad(support_loss, list(params.values()), create_graph=True)  # inner loop
    adapted = {name: p - 0.01 * g for (name, p), g in zip(params.items(), grads)}
    before = F.mse_loss(functional_call(net, params, x[10:]), y[10:])
    after = F.mse_loss(functional_call(net, adapted, x[10:]), y[10:])
    return before, after


# Outer loop: update the shared initialization so that one inner step fits each new task
for step in range(10000):
    meta_loss = sum(sine_task_losses()[1] for _ in range(4))
    meta_optimizer.zero_grad()
    meta_loss.backward()
    meta_optimizer.step()

# On 500 unseen sine waves, compare query error before and after the one-step adaptation
losses = torch.tensor([[loss.item() for loss in sine_task_losses()] for _ in range(500)])
print(f"query MSE before adaptation: {losses[:, 0].mean():.2f}, after one step: {losses[:, 1].mean():.2f}")

It prints query MSE before adaptation: 3.10, after one step: 0.70. The meta-learned initialization fits no particular sine wave, yet a single gradient step on 10 points cuts the error on new points of an unseen wave by more than four times.

  • Transfer learning: Reuses weights trained on one large task as the starting point for another, without optimizing them for adaptability. Fine-tuning a COCO-pretrained Ultralytics YOLO26 detector on a custom dataset is transfer learning: its starting weights come from ordinary training on COCO, and adapting them uses a labeled dataset and many training epochs rather than a few examples and a few gradient steps.
  • Few-shot learning: The problem of learning from very few examples. Meta-learning is one family of solutions; pretrained embeddings with a simple classifier are another.
  • Automated machine learning (AutoML): Searches for architectures and hyperparameters, usually for one dataset at a time. Some surveys count hyperparameter learning across tasks as meta-learning.
  • Continual learning: Learns a sequence of tasks without forgetting earlier ones, while meta-learning prepares a model to learn new tasks fast.

Benchmarks and Findings#

Few-shot image benchmarks drove most meta-learning research: Omniglot contains 1,623 handwritten characters from 50 alphabets, and miniImageNet uses 100 ImageNet classes with 600 images each, split into separate classes for meta-training, validation, and testing. Two later studies questioned how much the meta-learning itself contributes. "Rapid Learning or Feature Reuse?" showed that MAML's success comes mainly from reusing features learned in the outer loop, and its simplified ANIL variant, which adapts only the final layer in the inner loop, matched MAML. "Rethinking Few-Shot Image Classification" then found that a linear classifier on a good embedding, learned with ordinary supervised or self-supervised training on the meta-training classes, outperformed the leading few-shot meta-learning methods of the time.

Explore solutions

Computer vision in sports

Computer vision in sports

Discover how Ultralytics YOLO powers sports vision with player and ball tracking, performance analytics, coaching insights, and athlete rehabilitation.
Learn more
Computer vision for aerial imagery

Computer vision for aerial imagery

Turn drone and aerial imagery into real-time insights for agriculture, aquaculture, conservation, and geospatial analysis with Ultralytics YOLO.
Learn more
Computer vision in aerospace

Computer vision in aerospace

Apply computer vision in aerospace with Ultralytics YOLO for aircraft inspection, runway FOD detection, airport ground operations, and composite defect detection.
Learn more
Computer vision in security

Computer vision in security

Protect every site with Ultralytics YOLO models. Vision AI powers perimeter monitoring, threat detection, license-plate recognition, and workplace safety.
Learn more
Computer vision in robotics

Computer vision in robotics

Power smarter machines with Ultralytics YOLO models. Vision AI in robotics drives autonomous navigation, perception, object tracking, and real-time control.
Learn more
Computer vision in logistics

Computer vision in logistics

Streamline logistics with Ultralytics YOLO models. Vision AI enables package inspection, sorting, vehicle tracking, and real-time warehouse safety monitoring.
Learn more
Computer vision in retail

Computer vision in retail

Reimagine retail with Ultralytics YOLO models. Vision AI powers inventory tracking, shelf monitoring, queue management, and smarter customer insights.
Learn more
Computer vision in healthcare

Computer vision in healthcare

Build healthcare solutions with Ultralytics YOLO models. Vision AI in healthcare powers faster medical imaging, smarter diagnostics, and patient monitoring.
Learn more
Computer vision in manufacturing

Computer vision in manufacturing

Optimize manufacturing with Ultralytics YOLO models. Vision AI drives quality control, defect detection, PPE compliance, and assembly line automation.
Learn more
Computer vision in automotive

Computer vision in automotive

Apply computer vision in automotive with Ultralytics YOLO models. Vision AI elevates road safety, driver assistance, and vehicle automation for smarter roads.
Learn more
Computer vision in agriculture

Computer vision in agriculture

Bring vision AI to smart agriculture with Ultralytics YOLO models. Power crop monitoring, livestock tracking, and precision farming for higher, smarter yields.
Learn more

Let's build the future of AI together!

Begin your journey with the future of machine learning