Home

Awesome

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.

Update on 2020/07/01

Our paper was accepted by ECCV 2020 as spotlight!

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:.

MethodMini-ImageNet<br/>1 - shotMini-ImageNet<br/>5 - shotCUB<br/>1 - shotCUB<br/>5 - shotMini-ImageNet -> CUB<br/>5-shot
Softmax51.75+-0.8074.27+-0.6365.51+-0.8782.85+-0.5565.57+-0.70
Cosine51.87+-0.7775.68+-0.6367.02+-0.9083.58+-0.5462.04+-0.76
Neg-Sofmax59.02+-0.8178.80+-0.6171.48+-0.8387.30+-0.4869.30+-0.73
Neg-Cosine62.33+-0.8280.94+-0.5972.66+-0.8589.40+-0.4367.03+-0.76

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

Getting started

Environment

Datasets

CUB

mini-ImageNet

(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

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 some scripts to reproduce the results in the paper. 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: