Code Monkey home page Code Monkey logo

negative-margin.few-shot's Introduction

Negative Margin Matters: Understanding Margin in Few-shot Classification

By Bin Liu, Yue Cao, Yutong Lin, Qi Li, Zheng Zhang, Mingsheng Long, Han Hu.

This repo is an official implementation of "Negative Margin Matters: Understanding Margin in Few-shot Classification" on PyTorch.

Introduction

This paper is initially described in arxiv, which introduces a negative margin loss to metric learning based few-shot learning methods. The negative margin loss significantly outperforms regular softmax loss, and achieves state-of-the-art accuracy on three standard few-shot classification benchmarks with few bells and whistles. These results are contrary to the common practice in the metric learning field, that the margin is zero or positive. To understand why the negative margin loss performs well for the few-shot classification, the authors analyze the discriminability of learned features w.r.t different margins for training and novel classes, both empirically and theoretically. They find that although negative margin reduces the feature discriminability for training classes, it may also avoid falsely mapping samples of the same novel class to multiple peaks or clusters, and thus benefit the discrimination of novel classes.

Citation

@article{liu2020negative,
  title={Negative Margin Matters: Understanding Margin in Few-shot Classification},
  author={Liu, Bin and Cao, Yue and Lin, Yutong and Li, Qi and Zhang, Zheng and Long, Mingsheng and Hu, Han},
  journal={arXiv preprint arXiv:2003.12060},
  year={2020}
}

Main Results

The few-shot classification accuracy on the novel classes with ResNet-18 as the backbone is listed bellowing:.

Method Mini-ImageNet
1 - shot
Mini-ImageNet
5 - shot
CUB
1 - shot
CUB
5 - shot
Mini-ImageNet -> CUB
5-shot
Softmax 51.75+-0.80 74.27+-0.63 65.51+-0.87 82.85+-0.55 65.57+-0.70
Cosine 51.87+-0.77 75.68+-0.63 67.02+-0.90 83.58+-0.54 62.04+-0.76
Neg-Sofmax 59.02+-0.81 78.80+-0.61 71.48+-0.83 87.30+-0.48 69.30+-0.73
Neg-Cosine 62.33+-0.82 80.94+-0.59 72.66+-0.85 89.40+-0.43 67.03+-0.76

You can download the pre-trained model checkpoints of resnet18 from OneDrive.

Getting started

Environment

  • Anaconda with python >= 3.6
  • pytorch=1.2.0, torchvison, cuda=9.2
  • others: pip install yacs

Datasets

CUB

  • Change directory to ./data/CUB
  • run bash ./download_CUB.sh

mini-ImageNet

  • Change directory to ./data/miniImagenet
  • run bash ./download_miniImagenet.sh

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

mini-ImageNet->CUB

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

Train and eval

Run the following commands to train and evaluate:

python main.py --config [CONFIGFILENAME] \
    --supp [SUPPLEMENTSTRING] \
    method.backbone [BACKBONE] \
    method.image_size [IMAGESIZE] \
    method.metric_params.margin [MARGIN] \
    [OPTIONARG]

For additional options, please refer to ./lib/config.py.

We have also provided the train scripts to reproduce the results of resnet18. Pleas check ./script for details.

References

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

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.