Home

Awesome

Few-shot learning

The aim for this repository is to contain clean, readable and tested code to reproduce few-shot learning research.

This project is written in python 3.6 and Pytorch and assumes you have a GPU.

See these Medium articles for some more information

  1. Theory and concepts
  2. Discussion of implementation details

Setup

Requirements

Listed in requirements.txt. Install with pip install -r requirements.txt preferably in a virtualenv.

Data

Edit the DATA_PATH variable in config.py to the location where you store the Omniglot and miniImagenet datasets.

After acquiring the data and running the setup scripts your folder structure should look like

DATA_PATH/
    Omniglot/
        images_background/
        images_evaluation/
    miniImageNet/
        images_background/
        images_evaluation/

Omniglot dataset. Download from https://github.com/brendenlake/omniglot/tree/master/python, place the extracted files into DATA_PATH/Omniglot_Raw and run scripts/prepare_omniglot.py

miniImageNet dataset. Download files from https://drive.google.com/file/d/0B3Irx3uQNoBMQ1FlNXJsZUdYWEE/view, place in data/miniImageNet/images and run scripts/prepare_mini_imagenet.py

Tests (optional)

After adding the datasets run pytest in the root directory to run all tests.

Results

The file experiments/experiments.txt contains the hyperparameters I used to obtain the results given below.

Prototypical Networks

Prototypical Networks

Run experiments/proto_nets.py to reproduce results from Prototpyical Networks for Few-shot Learning (Snell et al).

Arguments

Omniglot
k-way552020
n-shot1515
Published98.899.796.098.9
This Repo98.299.495.898.6
miniImageNet
k-way55
n-shot15
Published49.468.2
This Repo48.066.2

Matching Networks

A differentiable nearest neighbours classifier.

Matching Networks

Run experiments/matching_nets.py to reproduce results from Matching Networks for One Shot Learning (Vinyals et al).

Arguments

I had trouble reproducing the results of this paper using the cosine distance metric as I found the converge to be slow and final performance dependent on the random initialisation. However I was able to reproduce (and slightly exceed) the results of this paper using the l2 distance metric.

Omniglot
k-way552020
n-shot1515
Published (cosine)98.198.993.898.5
This Repo (cosine)92.093.275.677.8
This Repo (l2)98.399.892.897.8
miniImageNet
k-way55
n-shot15
Published (cosine, FCE)44.257.0
This Repo (cosine, FCE)42.853.6
This Repo (l2)46.058.4

Model-Agnostic Meta-Learning (MAML)

MAML

I used max pooling instead of strided convolutions in order to be consistent with the other papers. The miniImageNet experiments using 2nd order MAML took me over a day to run.

Run experiments/maml.py to reproduce results from Model-Agnostic Meta-Learning (Finn et al).

Arguments

NB: For MAML n, k and q are fixed between train and test. You may need to adjust meta-batch-size to fit your GPU. 2nd order MAML uses a lot more memory.

Omniglot
k-way552020
n-shot1515
Published98.799.995.898.9
This Repo (1)95.599.592.297.7
This Repo (2)98.199.891.695.9
miniImageNet
k-way55
n-shot15
Published48.163.2
This Repo (1)46.463.3
This Repo (2)47.564.7

Number in brackets indicates 1st or 2nd order MAML.