Giter Club home page Giter Club logo

simple_shot's Introduction

SimpleShot: Revisiting Nearest-Neighbor Classification for Few-Shot Learning

This repository contains the code for SimpleShot introduced in the following paper

SimpleShot: Revisiting Nearest-Neighbor Classification for Few-Shot Learning

by Yan Wang, Wei-Lun Chao, Kilian Q. Weinberger, Laurens van der Maaten

Citation

If you find Simple Shot useful in your research, please consider citing:

@article{wang2019simpleshot,
  title={SimpleShot: Revisiting Nearest-Neighbor Classification for Few-Shot Learning},
  author={Wang, Yan and Chao, Wei-Lun and Weinberger, Kilian Q.  and van der Maaten, Laurens},
  journal={arXiv preprint arXiv:1911.04623},
  year={2019}
}

Introduction

Few-shot learners aim to recognize new object classes based on a small number of labeled training examples. To prevent overfitting, state-of-the-art few-shot learners use meta-learning on convolutional-network features and perform classification using a nearest-neighbor classifier. This paper studies the accuracy of nearest-neighbor baselines without meta-learning. Surprisingly, we find simple feature transformations suffice to obtain competitive few-shot learning accuracies. For example, we find that a nearest-neighbor classifier used in combination with mean-subtraction and L2-normalization outperforms prior results in three out of five settings on the miniImageNet dataset.

Update:

  • Dec. 17th. Add configuration and pretrained models of prototypical network with conv4 backbone.

Usage

1. Dependencies

  • Python 3.5+
  • Pytorch 1.0+

2. Download Datasets

2.1 Mini-ImageNet

You can download the dataset from https://drive.google.com/open?id=0B3Irx3uQNoBMQ1FlNXJsZUdYWEE

2.2 Tiered-ImageNet

You can download the dataset from https://drive.google.com/file/d/1g1aIDy2Ar_MViF2gDXFYDBTR-HYecV07/view. After downloading and unziping this dataset, you have to run the follow script to generate split files.

python src/utils/tieredImagenet.py --data path-to-tiered --split split/tiered/

2.3 iNat2017

Please follow the instruction from https://github.com/daviswer/fewshotlocal to download the dataset. And run the following script to generate split files.

python ./src/inatural_split.py --data path-to-inat/setup --split ./split/inatural/

3 Train and Test

You can manually download the pretrained models. Then copy all the files to the corresponding folder.

Google Drives: https://drive.google.com/open?id=14ZCz3l11ehCl8_E1P0YSbF__PK4SwcBZ

BaiduYun: https://pan.baidu.com/s/1tC2IU1JBL5vPNmnxXMu2sA code:d3j5

Or, you can run the follwing command to download them:

cd ./src
python download_models.py

This repo includes Resnet-10/18/34/50, Densenet-121, Conv-4, WRN, MobileNet models.

For instance, to train a Conv-4 on Mini-ImageNet or Tiered-ImageNet,

python ./src/train.py -c ./configs/mini/softmax/conv4.config --data path-to-mini-imagenet/
python ./src/train.py -c ./configs/tiered/softmax/conv4.config --data path-to-tiered-imagenet/data/

To evaluate the models on Mini/Tiered-ImageNet

python ./src/train.py -c ./configs/mini/softmax/conv4.config --evaluate --enlarge --data path-to-mini-imagenet/
python ./src/train.py -c ./configs/tiered/softmax/conv4.config --evaluate --enlarge --data  path-to-tiered-imagenet/data/

To evaluate INat models,

python ./src/test_inatural.py -c ./configs/inatural/softmax/conv4.config --evaluate --enlarge --data path-to-inatural/setup/

New: To train and evaluate the Conv-4 model on Mini-ImageNet with prototypical training:

python ./src/train.py -c ./configs/mini/protonet/{conv4_shot1 | conv4_shot5}.config --data path-to-mini-imagenet/
python ./src/train.py -c ./configs/mini/protonet/{conv4_shot1 | conv4_shot5}.config --data path-to-mini-imagenet/ --evaluate

Contact

If you have any question, please feel free to email us.

Yan Wang ([email protected])

simple_shot's People

Contributors

mileyan avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.