Git Product home page Git Product logo

classifier-balancing's Introduction

Classifier-Balancing

This repository contains code for the paper:

Decoupling Representation and Classifier for Long-Tailed Recognition
Bingyi Kang, Saining Xie,Marcus Rohrbach, Zhicheng Yan, Albert Gordo, Jiashi Feng, Yannis Kalantidis
[OpenReview] [Arxiv] [PDF] [Slides] [@ICLR]
Facebook AI Research, National University of Singapore
International Conference on Learning Representations (ICLR), 2020

Abstract

The long-tail distribution of the visual world poses great challenges for deep learning based classification models on how to handle the class imbalance problem. Existing solutions usually involve class-balancing strategies, e.g., by loss re-weighting, data re-sampling, or transfer learning from head- to tail-classes, but all of them adhere to the scheme of jointly learning representations and classifiers. In this work, we decouple the learning procedure into representation learning and classification, and systematically explore how different balancing strategies affect them for long-tailed recognition. The findings are surprising: (1) data imbalance might not be an issue in learning high-quality representations; (2) with representations learned with the simplest instance-balanced (natural) sampling, it is also possible to achieve strong long-tailed recognition ability with relative ease by adjusting only the classifier. We conduct extensive experiments and set new state-of-the-art performance on common long-tailed benchmarks like ImageNet-LT, Places-LT and iNaturalist, showing that it is possible to outperform carefully designed losses, sampling strategies, even complex modules with memory, by using a straightforward approach that decouples representation and classification.

 

 

If you find this code useful, consider citing our work:

@inproceedings{kang2019decoupling,
  title={Decoupling representation and classifier for long-tailed recognition},
  author={Kang, Bingyi and Xie, Saining and Rohrbach, Marcus and Yan, Zhicheng
          and Gordo, Albert and Feng, Jiashi and Kalantidis, Yannis},
  booktitle={Eighth International Conference on Learning Representations (ICLR)},
  year={2020}
}

Requirements

The code is based on https://github.com/zhmiao/OpenLongTailRecognition-OLTR.

Dataset

  • ImageNet_LT and Places_LT

    Download the ImageNet_2014 and Places_365.

  • iNaturalist 2018

    • Download the dataset following here.
    • cd data/iNaturalist18, Generate image name files with this script or use the existing ones [here].

Change the data_root in main.py accordingly.

Representation Learning

  1. Instance-balanced Sampling
python main.py --cfg ./config/ImageNet_LT/feat_uniform.yaml
  1. Class-balanced Sampling
python main.py --cfg ./config/ImageNet_LT/feat_balance.yaml
  1. Square-root Sampling
python main.py --cfg ./config/ImageNet_LT/feat_squareroot.yaml
  1. Progressively-balancing Sampling
python main.py --cfg ./config/ImageNet_LT/feat_shift.yaml

Test the joint learned classifier with representation learning

python main.py --cfg ./config/ImageNet_LT/feat_uniform.yaml --test 

Classifier Learning

  1. Nearest Class Mean classifier (NCM).
python main.py --cfg ./config/ImageNet_LT/feat_uniform.yaml --test --knn
  1. Classifier Re-training (cRT)
python main.py --cfg ./config/ImageNet_LT/cls_crt.yaml --model_dir ./logs/ImageNet_LT/models/resnext50_uniform_e90
python main.py --cfg ./config/ImageNet_LT/cls_crt.yaml --test
  1. Tau-normalization

Extract fatures

for split in train_split val test
do
  python main.py --cfg ./config/ImageNet_LT/feat_uniform.yaml --test --save_feat $split
done

Evaluation

for split in train val test
do
  python tau_norm.py --root ./logs/ImageNet_LT/models/resnext50_uniform_e90/ --type $split
done
  1. Learnable weight scaling (LWS)
python main.py --cfg ./config/ImageNet_LT/cls_lws.yaml --model_dir ./logs/ImageNet_LT/models/resnext50_uniform_e90
python main.py --cfg ./config/ImageNet_LT/cls_lws.yaml --test

Results and Models

ImageNet_LT

  • Representation learning

    Sampling Many Medium Few All Model
    Instance-Balanced 65.9 37.5 7.7 44.4 ResNeXt50
    Class-Balanced 61.8 40.1 15.5 45.1 ResNeXt50
    Square-Root 64.3 41.2 17.0 46.8 ResNeXt50
    Progressively-Balanced 61.9 43.2 19.4 47.2 ResNeXt50

    For other models trained with instance-balanced (natural) sampling:
    [ResNet50] [ResNet101] [ResNet152] [ResNeXt101] [ResNeXt152]

  • Classifier learning

    Classifier Many Medium Few All Model
    Joint 65.9 37.5 7.7 44.4 ResNeXt50
    NCM 56.6 45.3 28.1 47.3 ResNeXt50
    cRT 61.8 46.2 27.4 49.6 ResNeXt50
    Tau-normalization 59.1 46.9 30.7 49.4 ResNeXt50
    LWS 60.2 47.2 30.3 49.9 ResNeXt50

iNaturalist 2018

Places_LT

  • Representaion learning
    We provide a pretrained ResNet152 with instance-balanced (natural) sampling: [link]
  • Classifier learning
    We provide the cRT and LWS models based on above pretrained ResNet152 model as follows:
    [ResNet152(cRT)] [ResNet152(LWS)]

To test a pretrained model:
python main.py --cfg /path/to/config/file --model_dir /path/to/model/file --test

License

This project is licensed under the license found in the LICENSE file in the root directory of this source tree (here). Portions of the source code are from the OLTR project.

classifier-balancing's People

Contributors

bingykang 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

classifier-balancing's Issues

tau norm doesn't require --model_dir option?

Hi

thanks for your work. Not to mention that your code is also brilliant :)

I'm curios with the shell script you shared on Readme
From what I read, tau norm also needs to start from a trained network with instance sampling.
However, it seems like the part on "saving feature" doesn't require any pretrained model.

Is there something I am missing?

Huge thanks in advance!

Resnet10

Thanks for the excellent work!

I'm currently trying to reproduce the result of ResNet10. However, I find it hard to reproduce the same accuracy in the paper under the cRT setting using a similar config file of ResNext50.

Would you mind sharing the pre-trained model or config file? thx.

Question about weight norm

Dear experts or scholars:

Thanks for your excellent work on long tail recognition.Your paper is now inevitable to read and I have read many times.

I have a question about weight norm.
In figure 2 left, you have show us weights are closely related to class index or numbers of images of classes.
My question is how can you find the relationship between classes and weight norm?Or how can you get the weight norm of one class?

Regarding the Places_LT

Hi,
Thanks for the awesome paper and implementation.

The following are the versions of files that can be downloaded from the official website of Places365 dataset (http://places2.csail.mit.edu/download.html):

  • Data of Places365-Standard
    • High-resolution images
    • Small images (256 * 256)
    • Small images (256 * 256) with easy directory structure
  • Data of Places365-Challenge 2016
    • High-resolution images
    • Small images (256 * 256)
  • Data of Places-Extra69
    • High-resolution images
    • Small images (256 * 256)

Can you let us know which one you are using in your experiments?

ImageNet2014 dataset does not correspond to the ImageNet_train.txt

The ImageNet2014 dataset I downloaded from https://image-net.org/challenges/LSVRC/2014/2014-downloads.php does not have the same file structure as listed in ImageNet_train.txt and ImageNet_val.txt.
Part of the data downloaded from the link above even have different names that look like ILSVRC2014_train_0000/ILSVRC2014_train_00006666.JPEG instead of something like n01729322/n01729322_5530.JPEG
Where do you actually download the dataset? I'm really confused with the weird dataset I downloaded which has three different file structures...

What is the parameter "num_samples_cls"?

Hi, thanks for your work and sharing!
I have a question about the setting for ClassAwareSampler: num_samples_cls.
Why you set it to 4 in all config.yaml? What does it mean?

question about accuracy

Thanks for the great work!

I have a question. Is the accuracy reported in your paper on the validation set or the test set? If it is on the validation set, but I use the resnet50 pretrainmodel of the first stage you provided on github, and the second stage using crt and lws can reach 48.0%, which is slightly higher than the results in the paper. But if it is on the test set, the results of using crt and lws in the second stage are 46.3% and 46.6%, respectively, which is little far from the results reported in the paper. I am very confused about this question.

More details regarding Places-LT

Hi @bingykang , I have a few questions regarding the project. Since you haven't yet released the stage 1 config for Places-LT, I would like to know the following details:

  1. How many epochs did you train Places-LT for in the first stage?
  2. What is frozen and what is unfrozen in that stage?
  3. What learning rate scheduler do you use, and what about the parameters?
  4. Are there any changes that needs to be done in your code before fine-tuning from the ImageNet pretrain?

Thanks for answering my Qs, and have a nice day!

Suit for detection?

Firstly, thank you very much for your excellent research. I wonder if this work if suitable for detection? The weight norm of classify layer is propotional to the category weights, so does the weight norm of detection layer have same phemomenon?

tau-norm code problems

Hi there,
I think models/TauNormClassifier.py is missing since I see only the class DotProduct_Classifier inside it. could you kindly provide it?
I have problem with tau_norm.py as well since I can not compute the gradients wrt weights.

Thanks for your clarifications

Cannot get the same acc?

I appreciate the work you guys done and the contribution is remarkable!

I'm trying to rebuild a stage-1 model from the script named as feat_uniform.yaml that you provided. The only change that I made is changing the batchsize from 512 to 256. After I trained the stage-1 model, I got the accs on ImagetNet_LT as follows:

 Evaluation_accuracy_micro_top1: 0.417 
 Averaged F-measure: 0.376 
 Many_shot_accuracy_top1: 0.650 Median_shot_accuracy_top1: 0.333 Low_shot_accuracy_top1: 0.052 

Then, I trained the stage-2 model using the script cls_crt.yaml, trying to get the accuracies recorded in the paper. I got the following results:

 Evaluation_accuracy_micro_top1: 0.476 
 Averaged F-measure: 0.461 
 Many_shot_accuracy_top1: 0.601 Median_shot_accuracy_top1: 0.438 Low_shot_accuracy_top1: 0.258 

I also used the pretrained model you provided as the base model for stage-2 training, then I got results approximately same as the paper mentioned. I realise that maybe the stage-1 training configuration is not the optimal one that you guys used to train the pretrained model. If so, could you please update the training script to the version that may reproduce the final accs?

Thanks

How to determine tau?

Hi! You said you sampled a balanced testing distribution from the training set in order to determine tau. Could you point me to the code which does this? In addition, I'm curious about how you obtained tau with learning. If possible, could you also point me to the code?

Thanks.

Learning tau on validation set ?

Hi, I see that you have tried to learn tau parameter on training set or apply grid search for tau on validation set and training set in the paper. So have you tried learn tau parameter and LWS parameter on validation set or on train+val set ? and Further there seems only test set for iNaturalist 2018, So the val set is splited from training set by yourself ?

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.