/BML

Primary LanguagePython

megvii research

Binocular Mutual Learning for Improving Few-shot Classification (BML)

License: MIT stars GitHub repo size

Installation

This repo contains the PyTorch implementation of our ICCV paper "Binocular Mutual Learning for Improving Few-shot Classification".

BML is a novel and effective solution for few-shot classification. Inspired by the mutual learning paradigm and binocular parallax, we propose this framework, which learn the global relationship between classes and the detailed differences between samples simultaneously. That means, BML has two complementary views, working like human —— they deepen and rectify their perception through two eyes.

BML framework diagram

Setup

1. Dependencies

  • Linux with Python >= 3.6
  • PyTorch >= 1.6 & torchvision that matches the PyTorch version.
  • GCC 7.5
  • CUDA 11.2

2. Build env

virtualenv BML_env --python=python3.6
cd /path/to/venv/BML_env
source ./bin/activate
pip install -r requirements.txt 
  • Install Apex (optional, to enable mixed precision training):
git clone https://github.com/NVIDIA/apex
cd apex
pip install -v --disable-pip-version-check --no-cache-dir --global-option="--cpp_ext" --global-option="--cuda_ext" ./

3. Download Data and Weights

  • Data Preparation
    • we evaluate BML on five commonly used benchmarks, including miniImageNet, tieredImageNet, CUB, CIFAR-FS and FC100. We collated and summarized the data:

      Dataset DownloadPath Split
      miniImageNet path 64/16/20
      tieredImageNet path(code:123z) 351/97/160
      CUB path 100/50/50
      CIFAR-FS path 64/16/20
      FC100 path 60/20/20
    • unzip dataset to /data/few-shot/data/

  • pretraind weights for evaluation
    • we offer our released weights on five benchmarks:

      Dataset GoogleDriver BaiDuYun 5way-5shot 5way-1shot
      miniImageNet path path(code:123z) 83.69 67.21
      tieredImageNet path path(code:123z) 85.15 69.49
      CIFAR-FS path path(code:123z) 88.63 74.99
      CUB path path(code:123z) 89.80 74.42
      FC100 path path(code:123z) 62.62 44.62
    • The training and eval details can be found in log and eval_results.

    • download weights to pretrained_weights.

    • note: We give the latest evaluation results and models which are slightly different from the results reported in the paper.

Usage

1. training

We give a representative training example on miniImageNet, for other dataset, complete the training by specifying --dataset and --transform.

bash train_bml.sh

You need at least one nvidia tesla v100 or two GeForce RTX 2080ti.

If you want to train two baseline models baseline-global and baseline-local, we also provide corresponding training interfaces:

bash train_baseline.sh

2. evaluation

For fairness, we evaluate BML on 2,000 episodes with 10 random seeds.

bash eval_bml.sh miniImageNet A /path/to/weights 5
bash eval_bml.sh miniImageNet A /path/to/weights 1

Acknowlegements

Part of the code refers to rethinking and MCT, Please check them for more details and features.

Citation

When using code within this repository, please refer the following paper in your publications:

@inproceedings{zhou2021binocular,
  title={Binocular Mutual Learning for Improving Few-shot Classification},
  author={Zhou, Ziqi and Qiu, Xi and Xie, Jiangtao and Wu, Jianan and Zhang, Chi},
  booktitle={Proceedings of the IEEE/CVF International Conference on Computer Vision},
  pages={8402--8411},
  year={2021}
}