Classifier on Mini-Imagenet dataset using Learn2Learn and MAML
Model Agnostic Meta-Learning (MAML) is a popular gradient-based meta-learning algorithm that learns a weight initialization that maximizes…
Classifier on Mini-Imagenet dataset using Learn2Learn and MAML

Model Agnostic Meta-Learning (MAML) is a popular gradient-based meta-learning algorithm that learns a weight initialization that maximizes task adaptation with a few training samples. The paper introducing MAML can be found ***here***, with links to the author’s open-source implementation. Some familiarity with the algorithm will certainly help in understanding the nuances behind the interface, though this should not be a barrier to understanding how to use the interface.
The following is an example of using the high-level MAML implementation from learn2learn on the popular mini-imagenet dataset. mini-Imagenet is proposed by Matching Networks for One Shot Learning. In NeurIPS, 2016. This dataset consists of 50000 training images and 10000 testing images, evenly distributed across 100 classes.
So let’s start with the code step by step, we will be using google collab for this.
- Connecting google drive:
[embed]
- Installing the Learn2Learn library:
Applying meta-learning to your existing or new projects can be a great way of improving performance or solving new problems. However, this can be a difficult task due to the high computational costs and hyperparameters of algorithms that are unstable and brittle. Also, since meta-learning is relatively new, most supervised datasets are not properly formatted for inserting into a meta-learning algorithm. Learn2learn alleviates these issues by providing a simple user interface for loading datasets and training using fast, robust implementations of common meta-learning algorithms.
[embed]
- Downloading the dataset:
The dataset can be downloaded from this link. Upload the dataset on google drive.
- Extracting the dataset in the session:
[embed]
- Defining a task generator:
Here first we import some useful functions. Then we define our dataset and wrap it in the learn2learn meta dataset class. Then we define a task generator using the TaskDataset function. The input for the TaskDataset functions are
a) NWays: Number of classes that have to be selected at random to make a task
b) KShots: Number of images to be included in a task per class
c) num_tasks: Number of unique tasks to be generated. You can consider a task as a batch of data.
[embed]
- Defining the training pipeline:
First, we define a PyTorch model. I’ve taken a built-in model but you can define any PyTorch model using PyTorch.nn module. Then we go on to define our MAML algorithm, optimizer, and the loss function.
After that in the for loop, we train the internal loop of the model using learner.adapt function. After that, we obtain the evaluation loss and meta-update the model parameters.
[embed]
By changing the hyperparameters and num_iterations you can train the model and analyze the loss.
Thank you for reading my blog post and hopefully you found it helpful.
Talk to me directly : https://x.com/chhinna00
메타데이터
- post_id
- a074e3d8a57b
- slug
- classifier-on-mini-imagenet-dataset-using-learn2learn-and-maml-a074e3d8a57b
- url
- https://medium.com/@chinmaybharti/classifier-on-mini-imagenet-dataset-using-learn2learn-and-maml-a074e3d8a57b
- canonical_url
- https://medium.com/@chinmaybharti/classifier-on-mini-imagenet-dataset-using-learn2learn-and-maml-a074e3d8a57b
- author_url
- https://medium.com/@chinmaybharti
- status
- ok
- fetched_at
- 2026-06-20 20:29:01