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

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

simple_shot's Issues

The idea of SimpleShot is almost the same as that of ProtoNet

ProtoNet also uses the mean of each support class as its center and then implement Euclidean distance to train the network. The difference between SimpleShot and ProtoNet is that SimpleShot just added normalization and centering to the feature vectors before computing the Euclidean distance, is that correct?

Nice work and some questions

Congratulations, very effective work. I have some questions about your work, hope you can give some advice for your convenience.

  1. Why only subtruct mean of gallery, do you have a try on subtructing the mean of query or gallery+query ?
  2. Why on meta-iNat, CL2N not perform well than L2N?Have you tried to analyze the essential reasons?

Thanks!

inconsistency of enlarge between validation and test

For tiered imagenet, I noticed that in the validation step during training, the args.enlarge is set to False/None because there's no '--enlarge' in the training configs. However, in the evaluation/testing command lines shown in readme, there's a '--enlarge'. Just wondering is this a typo or something else?

Thanks!

The introduction part is so weird

First of all, thanks for the interesting work. The experimental results are still competitive to the current SOTA works.
However, the introduction makes me confused and doubt the results. For example, in paragraph 3, you mentioned 'Prior studies suggest that using meta-learning outperformes "vanilla" nearest neighbor classification [26, 30]'. In fact, references 26 and 30 were exactly the methods that used meta-learning, as they tackled the FSL problem within a meta-learning setting. Also, in paragraph 4, you mentioned that your method achieve SOTA performance without using meta-learning, which is the weirdest part because you were already using meta-learning when you used N-way K-shot setting.

Performance discrepancy when training from scratch w/ PyTorch 1.4

Hi,
Thanks for the nice work and for sharing the code.

I have tried replicating the results of the paper (training from scratch) but with no luck.
I have followed the instructions of the readme and tried both pytorch/cuda-toolkit 1.4/10.0.
For ResNet-10 and ResNet-18, on miniImageNet I am getting a discrepancy between 2% and 3% (absolute).

Thanks in advance for the help!

ResNet 50 performance

Thank you for your great work!

I am trying to rerun the models and see their performances. However, I realized that the performance of models with the ResNet50 backbone is significantly low. Below you may find the code output. Do you think this result is expected?

Best

Meta Test: LAST
feature UN L2N CL2N
GVP 1Shot 0.5127(0.0020) 0.5303(0.0020) 0.5161(0.0020)
GVP_5Shot 0.7143(0.0018) 0.7467(0.0016) 0.7165(0.0018)

Meta Test: LAST
feature UN L2N CL2N
GVP 1Shot 0.5127(0.0020) 0.5303(0.0020) 0.5161(0.0020)
GVP_5Shot 0.7143(0.0018) 0.7467(0.0016) 0.7165(0.0018)

Some questions about ResNet.

It is a really nice job! We tried to use resnet as a backbone just like what you did in our own experiment. However, it didn't improve performance as we expected and even performed worse than 4-conv. I wonder if there are some tricks when you trained your model with a resnet. Thank you very much.

is it possible to use simple_shot with CPU only?

Unfortunately on my MacBook, the evaluation command is failing:

python ./src/train.py -c ./configs/mini/softmax/conv4.config --evaluate --enlarge

Traceback (most recent call last):
  File "./src/train.py", line 554, in <module>
    main()
  File "./src/train.py", line 51, in main
    model = torch.nn.DataParallel(model).cuda()
  File "/Users/seb/.virtualenvs/kiss/lib/python3.7/site-packages/torch/nn/modules/module.py", line 305, in cuda
[...]
  File "/Users/seb/.virtualenvs/kiss/lib/python3.7/site-packages/torch/cuda/__init__.py", line 95, in _check_driver
    raise AssertionError("Torch not compiled with CUDA enabled")
AssertionError: Torch not compiled with CUDA enabled

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.