This repository contains code for the paper "Decoupling Representation and Classifier for Long-Tailed Recognition", published at ICLR 2020

Overview

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.

Comments
  • Cannot get the same acc?

    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

    opened by getterk96 8
  • Resnet10

    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.

    opened by Majiker 3
  • Learning tau on validation set ?

    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 ?

    opened by jiequancui 2
  • More details regarding Places-LT

    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!

    opened by TonyLianLong 2
  • Shouldn't the Stage1 weights be true in config setting?

    Shouldn't the Stage1 weights be true in config setting?

    https://github.com/facebookresearch/classifier-balancing/blob/master/config/ImageNet_LT/cls_crt.yaml#L23

    Here for cRT, shouldn't the stage1 weights be true for classifier learning stage?

    opened by abdullahjamal 1
  • ImageNet2014 dataset does not correspond to the ImageNet_train.txt

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

    opened by 18445864529 0
  • Balfeat is not found?

    Balfeat is not found?

    hi,you published this article EXPLORING BALANCED FEATURE SPACES FOR REP￾RESENTATION LEARNING. It says that Code is available at https://github.com/bingykang/BalFeat. But I try to open this link, I find it is 404.

    opened by cyx2016 0
  • tau norm doesn't require --model_dir option?

    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!

    opened by ooodragon94 0
  • tau-norm code problems

    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

    opened by rugrag 0
  • Question about weight norm

    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?

    opened by Liudzz 1
  • Suit for detection?

    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?

    opened by zfli-xdu 0
Owner
Facebook Research
Facebook Research
Provided is code that demonstrates the training and evaluation of the work presented in the paper: "On the Detection of Digital Face Manipulation" published in CVPR 2020.

FFD Source Code Provided is code that demonstrates the training and evaluation of the work presented in the paper: "On the Detection of Digital Face M

null 88 Nov 22, 2022
This repository contains the code for the CVPR 2020 paper "Differentiable Volumetric Rendering: Learning Implicit 3D Representations without 3D Supervision"

Differentiable Volumetric Rendering Paper | Supplementary | Spotlight Video | Blog Entry | Presentation | Interactive Slides | Project Page This repos

null 697 Jan 6, 2023
The implementation of the algorithm in the paper "Safe Deep Semi-Supervised Learning for Unseen-Class Unlabeled Data" published in ICML 2020.

DS3L This is the code for paper "Safe Deep Semi-Supervised Learning for Unseen-Class Unlabeled Data" published in ICML 2020. Setups The code is implem

Guolz 36 Oct 19, 2022
Codes accompanying the paper "Learning Nearly Decomposable Value Functions with Communication Minimization" (ICLR 2020)

NDQ: Learning Nearly Decomposable Value Functions with Communication Minimization Note This codebase accompanies paper Learning Nearly Decomposable Va

Tonghan Wang 69 Nov 26, 2022
Pytorch code for "State-only Imitation with Transition Dynamics Mismatch" (ICLR 2020)

This repo contains code for our paper State-only Imitation with Transition Dynamics Mismatch published at ICLR 2020. The code heavily uses the RL mach

null 20 Sep 8, 2022
A supplementary code for Editable Neural Networks, an ICLR 2020 submission.

Editable neural networks A supplementary code for Editable Neural Networks, an ICLR 2020 submission by Anton Sinitsin, Vsevolod Plokhotnyuk, Dmitry Py

Anton Sinitsin 32 Nov 29, 2022
Implementation of "Selection via Proxy: Efficient Data Selection for Deep Learning" from ICLR 2020.

Selection via Proxy: Efficient Data Selection for Deep Learning This repository contains a refactored implementation of "Selection via Proxy: Efficien

Stanford Future Data Systems 70 Nov 16, 2022
This repo contains the pytorch implementation for Dynamic Concept Learner (accepted by ICLR 2021).

DCL-PyTorch Pytorch implementation for the Dynamic Concept Learner (DCL). More details can be found at the project page. Framework Grounding Physical

Zhenfang Chen 31 Jan 6, 2023
Official repository for the ICLR 2021 paper Evaluating the Disentanglement of Deep Generative Models with Manifold Topology

Official repository for the ICLR 2021 paper Evaluating the Disentanglement of Deep Generative Models with Manifold Topology Sharon Zhou, Eric Zelikman

Stanford Machine Learning Group 34 Nov 16, 2022
BMW TechOffice MUNICH 148 Dec 21, 2022
Repository for "Improving evidential deep learning via multi-task learning," published in AAAI2022

Improving evidential deep learning via multi task learning It is a repository of AAAI2022 paper, “Improving evidential deep learning via multi-task le

deargen 11 Nov 19, 2022
A code repository associated with the paper A Benchmark for Rough Sketch Cleanup by Chuan Yan, David Vanderhaeghe, and Yotam Gingold from SIGGRAPH Asia 2020.

A Benchmark for Rough Sketch Cleanup This is the code repository associated with the paper A Benchmark for Rough Sketch Cleanup by Chuan Yan, David Va

null 33 Dec 18, 2022
This repository contains the code for the paper "Hierarchical Motion Understanding via Motion Programs"

Hierarchical Motion Understanding via Motion Programs (CVPR 2021) This repository contains the official implementation of: Hierarchical Motion Underst

Sumith Kulal 40 Dec 5, 2022
This repository contains the source code and data for reproducing results of Deep Continuous Clustering paper

Deep Continuous Clustering Introduction This is a Pytorch implementation of the DCC algorithms presented in the following paper (paper): Sohil Atul Sh

Sohil Shah 197 Nov 29, 2022
This repository contains a re-implementation of the code for the CVPR 2021 paper "Omnimatte: Associating Objects and Their Effects in Video."

Omnimatte in PyTorch This repository contains a re-implementation of the code for the CVPR 2021 paper "Omnimatte: Associating Objects and Their Effect

Erika Lu 728 Dec 28, 2022
This repository contains the source code for the paper "DONeRF: Towards Real-Time Rendering of Compact Neural Radiance Fields using Depth Oracle Networks",

DONeRF: Towards Real-Time Rendering of Compact Neural Radiance Fields using Depth Oracle Networks Project Page | Video | Presentation | Paper | Data L

Facebook Research 281 Dec 22, 2022
This repository contains the code and models for the following paper.

DC-ShadowNet Introduction This is an implementation of the following paper DC-ShadowNet: Single-Image Hard and Soft Shadow Removal Using Unsupervised

AuAgCu 65 Dec 27, 2022
This repository contains the official implementation code of the paper Improving Multimodal Fusion with Hierarchical Mutual Information Maximization for Multimodal Sentiment Analysis, accepted at EMNLP 2021.

MultiModal-InfoMax This repository contains the official implementation code of the paper Improving Multimodal Fusion with Hierarchical Mutual Informa

Deep Cognition and Language Research (DeCLaRe) Lab 89 Dec 26, 2022
This repository contains the code for the CVPR 2021 paper "GIRAFFE: Representing Scenes as Compositional Generative Neural Feature Fields"

GIRAFFE: Representing Scenes as Compositional Generative Neural Feature Fields Project Page | Paper | Supplementary | Video | Slides | Blog | Talk If

null 1.1k Dec 30, 2022