ProCo

September 30, 2024 ยท View on GitHub

This repository contains the Pytorch implementation of the T-PAMI 2024 paper Probabilistic Contrastive Learning for Long-Tailed Visual Recognition.

Authors: Chaoqun Du, Yulin Wang, Shiji Song, Gao Huang.

TPAMI arXiv

PWC PWC

Introduction

ProCo

We proposed a novel probabilistic contrastive (ProCo) learning algorithm for long-tailed distribution. Specifically, we employed a reasonable and straight-forward von Mises-Fisher distribution to model the normalized feature space of samples in the context of contrastive learning. This choice offers two key advantages. First, it is efficient to estimate the distribution parameters across different batches by maximum likelihood estimation. Second, we derived a closed form of expected supervised contrastive loss for optimization by sampling infinity samples from the estimated distribution. This eliminates the inherent limitation of supervised contrastive learning that requires a large number of samples to achieve satisfactory performance.

Results

Supervised Image Classification

MethodDatasetImbalance FactorEpochsTop-1 Acc.(%)Model
ProCoCIFAR100-LT10020052.8Tsinghua Cloud/Google Drive
ProCoCIFAR100-LT10040054.2Tsinghua Cloud/Google Drive
ProCoCIFAR100-LT5020057.1Tsinghua Cloud/Google Drive
ProCoCIFAR100-LT1020065.5Tsinghua Cloud/Google Drive
ProCoCIFAR10-LT10020085.9Tsinghua Cloud/Google Drive
ProCoCIFAR10-LT5020088.2Tsinghua Cloud/Google Drive
ProCoCIFAR10-LT1020091.9Tsinghua Cloud/Google Drive

We also provide the tensorboard logs for the CIFAR experiments in the logs folder.

MethodBackboneDatasetEpochsTop-1 Acc.(%)Model
ProCoResNet-50ImageNet-LT9057.3Tsinghua Cloud/Google Drive
ProCoResNeXt-50ImageNet-LT9058.0Tsinghua Cloud/Google Drive
ProCoResNet-50iNaturalist 20189073.5Tsinghua Cloud/Google Drive
ProCoResNet-50ImageNet-LT18057.8Tsinghua Cloud/Google Drive

Get Started

Requirements

  • python 3.9
  • numpy 1.23.3
  • Pillow 8.2.0
  • Requests 2.25.1
  • scipy 1.9.3
  • tensorboardX 2.5.1
  • torch 1.12.1
  • torchvision 0.13.1

The above environment is recommended, but not necessary. You can also use other versions of the packages.

Training

By default, we use 1 RTX3090 GPU for CIFAR, 4 RTX3090 GPUs for ImageNet training, and 8 A100 (40G) GPUs for iNaturalist2018 training. You can adjust the batch size according to your GPU memory.

bash sh/ProCo_CIFAR.sh ${dataset} ${imbalance_factor} ${epochs}
bash sh/ProCo_CIFAR.sh cifar100 0.01 200
bash sh/ProCo_CIFAR.sh cifar100 0.01 400
bash sh/ProCo_CIFAR.sh cifar100 0.02 200
bash sh/ProCo_CIFAR.sh cifar100 0.1  200
bash sh/ProCo_CIFAR.sh cifar10  0.01 200
bash sh/ProCo_CIFAR.sh cifar10  0.02 200
bash sh/ProCo_CIFAR.sh cifar10  0.1  200

bash sh/ProCo_ImageNetLT_R50_90epochs.sh
bash sh/ProCo_ImageNetLT_R50_180epochs.sh
bash sh/ProCo_ImageNetLT_X50_90epochs.sh
bash sh/ProCo_inat_R50_90epochs.sh

Evaluation

For evaluation, you can run the following command:

bash sh/ProCo_CIFAR.sh cifar100 0.01 200 ${checkpoint_path}
bash sh/ProCo_ImageNetLT_R50_90epochs.sh ${checkpoint_path}

ToDo

  • Long-tailed Semi-Supervised Learning.

Citation

If you find this code useful, please consider citing our paper:

@article{du2024probabilistic,
  title={Probabilistic Contrastive Learning for Long-Tailed Visual Recognition},
  author={Du, Chaoqun and Wang, Yulin and Song, Shiji and Huang, Gao},
  journal={IEEE Transactions on Pattern Analysis and Machine Intelligence},
  year={2024},
  publisher={IEEE}
}

Contact

If you have any questions, please feel free to contact the authors. Chaoqun Du: dcq20@mails.tsinghua.edu.cn.

Acknowledgement

Our code is based on the BCL (Balanced Contrastive Learning for Long-Tailed Visual Recognition) repository.