Loss re-weighting for imbalanced vision, circa TensorFlow 1.14
A CVPR 2019 TensorFlow implementation that re-weights classification loss using the paper’s "effective number of samples" instead of raw class counts.

What it does This repo holds the official TensorFlow code for the CVPR 2019 paper Class-Balanced Loss Based on Effective Number of Samples. It implements re-weighted softmax and focal loss using per-class weights derived from the paper’s “effective number of samples” concept, and includes training and evaluation pipelines for long-tailed CIFAR, iNaturalist, and ImageNet.
The interesting bit The repo goes beyond a minimal loss-function snippet: it bundles full TPU training pipelines forked from Google’s official ResNet-TPU tutorial, plus pre-trained ResNet-50 checkpoints for ImageNet and iNaturalist 2018. That makes it a complete research baseline rather than a toy example.
Key highlights
- Reference TensorFlow implementation of the CVPR 2019 class-balanced loss.
- Training scripts and tfrecords handling for long-tailed CIFAR variants.
- TPU-ready pipelines for iNaturalist 2017/2018 and ImageNet, forked from the official TensorFlow TPU ResNet example.
- Pre-trained ResNet-50 checkpoints provided for ImageNet and iNaturalist 2018.
- Exposes focal loss, class-balanced weighting, and last-layer initialization in the codebase.
Caveats
- Dependencies are pinned to TensorFlow 1.14 and Python 3.6, so the code is showing its age.
- The TPU workflow assumes Google Cloud Storage and Cloud TPU; it is not a self-contained CPU/GPU notebook.
- The README treats the theory lightly—you’ll need the paper to understand what “effective number” actually means.
Verdict Worth cloning if you are reproducing the 2019 baseline or need a long-tailed recognition benchmark to beat. Look elsewhere if you want a modern, drop-in loss layer for PyTorch or newer TensorFlow.
Frequently asked
- What is richardaecn/class-balanced-loss?
- A CVPR 2019 TensorFlow implementation that re-weights classification loss using the paper’s "effective number of samples" instead of raw class counts.
- Is class-balanced-loss open source?
- Yes — richardaecn/class-balanced-loss is open source, released under the MIT license.
- What language is class-balanced-loss written in?
- richardaecn/class-balanced-loss is primarily written in Python.
- How popular is class-balanced-loss?
- richardaecn/class-balanced-loss has 615 stars on GitHub.
- Where can I find class-balanced-loss?
- richardaecn/class-balanced-loss is on GitHub at https://github.com/richardaecn/class-balanced-loss.