Awesome Open Source
Awesome Open Source

Prototypical Networks for Few-shot Learning

Code for the NIPS 2017 paper Prototypical Networks for Few-shot Learning.

If you use this code, please cite our paper:

  title={Prototypical Networks for Few-shot Learning},
  author={Snell, Jake and Swersky, Kevin and Zemel, Richard},
  booktitle={Advances in Neural Information Processing Systems},

Training a prototypical network

Install dependencies

  • This code has been tested on Ubuntu 16.04 with Python 3.6 and PyTorch 0.4.
  • Install PyTorch and torchvision.
  • Install torchnet by running pip install git+[email protected].
  • Install the protonets package by running python install or python develop.

Set up the Omniglot dataset

  • Run sh

Train the model

  • Run python scripts/train/few_shot/ This will run training and place the results into results.
    • You can specify a different output directory by passing in the option --log.exp_dir EXP_DIR, where EXP_DIR is your desired output directory.
    • If you are running on a GPU you can pass in the option --data.cuda.
  • Re-run in trainval mode python scripts/train/few_shot/ This will save your model into results/trainval by default.


  • Run evaluation as: python scripts/predict/few_shot/ --model.model_path results/trainval/

Get A Weekly Email With Trending Projects For These Topics
No Spam. Unsubscribe easily at any time.
python (50,856
deep-learning (3,761
pytorch (2,198
metric-learning (30
nips-2017 (18

Find Open Source By Browsing 7,000 Topics Across 59 Categories