Skip to content
source code to ICLR'19, 'A Closer Look at Few-shot Classification'
Python Shell
Branch: master
Clone or download

A Closer Look at Few-shot Classification

This repo contains the reference source code for the paper A Closer Look at Few-shot Classification in International Conference on Learning Representations (ICLR 2019). In this project, we provide a integrated testbed for a detailed empirical study for few-shot classification.


If you find our code useful, please consider citing our work using the bibtex:

title={A Closer Look at Few-shot Classification},
author={Chen, Wei-Yu and Liu, Yen-Cheng and Kira, Zsolt and Wang, Yu-Chiang and  Huang, Jia-Bin},
booktitle={International Conference on Learning Representations},


  • Python3
  • Pytorch before 0.4 (for newer vesion, please see issue #3 )
  • json

Getting started


  • Change directory to ./filelists/CUB
  • run source ./


  • Change directory to ./filelists/miniImagenet
  • run source ./

(WARNING: This would download the 155G ImageNet dataset. You can comment out correponded line 5-6 in if you already have one.)

mini-ImageNet->CUB (cross)

  • Finish preparation for CUB and mini-ImageNet and you are done!


  • Change directory to ./filelists/omniglot
  • run source ./

Omniglot->EMNIST (cross_char)

  • Finish preparation for omniglot first
  • Change directory to ./filelists/emnist
  • run source ./

Self-defined setting

  • Require three data split json file: 'base.json', 'val.json', 'novel.json' for each dataset
  • The format should follow
    {"label_names": ["class0","class1",...], "image_names": ["filepath1","filepath2",...],"image_labels":[l1,l2,l3,...]}
    See test.json for reference
  • Put these file in the same folder and change data_dir['DATASETNAME'] in to the folder path


Run python ./ --dataset [DATASETNAME] --model [BACKBONENAME] --method [METHODNAME] [--OPTIONARG]

For example, run python ./ --dataset miniImagenet --model Conv4 --method baseline --train_aug
Commands below follow this example, and please refer to for additional options.

Save features

Save the extracted feature before the classifaction layer to increase test speed. This is not applicable to MAML, but are required for other methods. Run python ./ --dataset miniImagenet --model Conv4 --method baseline --train_aug


Run python ./ --dataset miniImagenet --model Conv4 --method baseline --train_aug


  • The test results will be recorded in ./record/results.txt
  • For all the pre-computed results, please see ./record/few_shot_exp_figures.xlsx. This will be helpful for including your own results for a fair comparison.


Our testbed builds upon several existing publicly available code. Specifically, we have modified and integrated the following code into this project:

You can’t perform that action at this time.