Skip to content
Implementation of prototypical networks
Jupyter Notebook Python
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.
Data exploration.ipynb

Prototypical networks for few-shot learning

This repository contains an implementation of the paper "Prototypical Networks for Few-shot Learning". The code is heavily based on / in part copies from All copied parts are clearly marked.

Dataset used is the Fashion Product Images dataset from Kaggle.


For simplicity, I commited results from five runs in this repo.

Run pip install git+

Then see Evaluation.ipynb to compare the runs.

Getting started


  • python>=3.6
  • pip install -r requirements.txt
  • for image resizing (see "Getting the data") you need ImageMagick installed

Getting the data

The data exploration notebook uses the small as well as the full dataset. For everything else, only the full dataset is needed; i.e. skip downloading the small dataset if you are not interested in the data exploration notebook.

  1. mkdir data
  2. Download the small dataset from kaggle to data.
  3. Download the full dataset from kaggle to data.
cd data
unzip -d small
unzip -d full

# decrease image size in the full dataset
cd full
cp -r full/images full/images_225x300     # this step might take a while
mogrify -resize 225x300 *.jpg             # this will take even longer



Per default, the config assumes data to be located in the directories used in "Getting the data". If you used different directories -> change the config. If you do not have a GPU -> change the config.

Running an experiment

Very short experiment to check that everything works

python --num-episodes=10 --num_epochs=10

Experiment with default settings


Check out python --help to learn what other parameters you can provide.


Image size

The images in the full dataset are fairly large (1800x2400 pixels). Due to GPU limitations (and general dataset limitations, as mentioned in Evaluation.ipynb), I decided to decreased them in size.

To make image loading faster, I decreased the files themselves to 225x300 pixels. During image loading, they are further decreased to 112x150 pixels (solely due to GPU limitations this time).

I want to use larger image files

No problem, just adapt the IMAGE_FOLDER variable

I want to use larger images during training

No problem, simple change IMAGE_SIZE in You might have to re-calculate the image means and standard deviations (but to be honest, they don't differ all that much when resizing the image). But, anyway, here is how to do that:

  1. Change IMAGE_SIZE in
  2. python
  3. Manually copy the outputs of previous command to IMAGE_STATISTICS in
You can’t perform that action at this time.