• Stars
    star
    715
  • Rank 62,893 (Top 2 %)
  • Language
    Python
  • License
    MIT License
  • Created almost 4 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Official Pytorch Implementation of: "Asymmetric Loss For Multi-Label Classification"(ICCV, 2021) paper

Asymmetric Loss For Multi-Label Classification

PWC
PWC
PWC

Paper | Pretrained models | Datasets

Official PyTorch Implementation

Emanuel Ben-Baruch, Tal Ridnik, Nadav Zamir, Asaf Noy, Itamar Friedman, Matan Protter, Lihi Zelnik-Manor
DAMO Academy, Alibaba Group

Abstract

In a typical multi-label setting, a picture contains on average few positive labels, and many negative ones. This positive-negative imbalance dominates the optimization process, and can lead to under-emphasizing gradients from positive labels during training, resulting in poor accuracy. In this paper, we introduce a novel asymmetric loss ("ASL"), which operates differently on positive and negative samples. The loss enables to dynamically down-weights and hard-thresholds easy negative samples, while also discarding possibly mislabeled samples. We demonstrate how ASL can balance the probabilities of different samples, and how this balancing is translated to better mAP scores. With ASL, we reach state-of-the-art results on multiple popular multi-label datasets: MS-COCO, Pascal-VOC, NUS-WIDE and Open Images. We also demonstrate ASL applicability for other tasks, such as single-label classification and object detection. ASL is effective, easy to implement, and does not increase the training time or complexity.

9/1/2023 Update

Added tests auto-generated by CodiumAI tool

29/11/2021 Update - New article released, offering new classification head with state-of-the-art results

Checkout our new project, Ml-Decoder, which presents a unified classification head for multi-label, single-label and zero-shot tasks. Backbones with ML-Decoder reach SOTA results, while also improving speed-accuracy tradeoff.

24/7/2021 Update - ASL article was accepeted to ICCV 2021

A final version of the paper, with updated results for ImageNet-21K pretraining, is released to arxiv.
Note that ASL is becoming the de-facto 'default' loss for high performance multi-label classification, and all the top results in papers-with-code are currently using it.

Training Code Now Available !

With great collaboration by @GhostWnd, we now provide a script for fully reproducing the article results, and finally a modern multi-label training code is available for the community.

Frequently Asked Questions

Some questions are repeatedly asked in the issues section. make sure to review them before starting a new issue:

  • Regarding combining ASL with other techniques, see link
  • Regarding implementation of asymmetric clipping, see link
  • Regarding disable_torch_grad_focal_loss option, see link
  • Regarding squish Vs crop resizing, see link
  • Regarding training tricks, see link
  • How to apply ASL to your own dataset, see link

Asymmetric Loss (ASL) Implementation

In this PyTorch file, we provide implementations of our new loss function, ASL, that can serve as a drop-in replacement for standard loss functions (Cross-Entropy and Focal-Loss)

For the multi-label case (sigmoids), the two implementations are:

  • class AsymmetricLoss(nn.Module)
  • class AsymmetricLossOptimized(nn.Module)

The two losses are bit-accurate. However, AsymmetricLossOptimized() contains a more optimized (and complicated) way of implementing ASL, which minimizes memory allocations, gpu uploading, and favors inplace operations.

For the single-label case (softmax), the implementations is called:

  • class ASLSingleLabel(nn.Module)

Pretrained Models

In this link, we provide pre-trained models on various dataset.

Validation Code

Thanks to external contribution of @hellbell, we now provide a validation code that repdroduces the article results on MS-COCO:

python validate.py  \
--model_name=tresnet_l \
--model_path=./models_local/MS_COCO_TRresNet_L_448_86.6.pth

Inference Code

We provide inference code, that demonstrate how to load our model, pre-process an image and do actuall inference. Example run of MS-COCO model (after downloading the relevant model):

python infer.py  \
--dataset_type=MS-COCO \
--model_name=tresnet_l \
--model_path=./models_local/MS_COCO_TRresNet_L_448_86.6.pth \
--pic_path=./pics/000000000885.jpg \
--input_size=448

which will result in:

Example run of OpenImages model:

python infer.py  \
--dataset_type=OpenImages \
--model_name=tresnet_l \
--model_path=./models_local/Open_ImagesV6_TRresNet_L_448.pth \
--pic_path=./pics/000000000885.jpg \
--input_size=448

Citation

 @misc{benbaruch2020asymmetric, 
        title={Asymmetric Loss For Multi-Label Classification}, 
        author={Emanuel Ben-Baruch and Tal Ridnik and Nadav Zamir and Asaf Noy and Itamar Friedman and Matan Protter and Lihi Zelnik-Manor}, 
        year={2020}, 
        eprint={2009.14119},
        archivePrefix={arXiv}, 
        primaryClass={cs.CV} }

Contact

Feel free to contact if there are any questions or issues - Emanuel Ben-Baruch ([email protected]) or Tal Ridnik ([email protected]).

More Repositories

1

ImageNet21K

Official Pytorch Implementation of: "ImageNet-21K Pretraining for the Masses"(NeurIPS, 2021) paper
Python
713
star
2

TResNet

Official Pytorch Implementation of "TResNet: High-Performance GPU-Dedicated Architecture" (WACV 2021)
Python
465
star
3

ML_Decoder

Official PyTorch implementation of "ML-Decoder: Scalable and Versatile Classification Head" (2021)
Python
314
star
4

STAM

Official implementation of "An Image is Worth 16x16 Words, What is a Video Worth?" (2021 paper)
Python
219
star
5

Solving_ImageNet

Official PyTorch implementation of the paper: "Solving ImageNet: a Unified Scheme for Training any Backbone to Top Results" (2022)
Python
190
star
6

PartialLabelingCSL

Official implementation for the paper: "Multi-label Classification with Partial Annotations using Class-aware Selective Loss"
Python
127
star
7

AudioClassfication

Python
71
star
8

HardCoReNAS

Python
34
star
9

HeadSharingKD

Implementation of the paper "It's All in the Head: Representation Knowledge Distillation through Classifier Sharing"
Python
34
star
10

ZS_SDL

Official Pytorch Implementation of: "Semantic Diversity Learning for Zero-Shot Multi-label Classification"(ICCV, 2021) paper
Python
28
star
11

PETA

Official Pytorch Implementation of "PETA: Photo Albums Event Recognition using Transformers Attention" (2021)
Python
18
star
12

CobBO

Coordinate Backoff Bayesian Optimization
Python
8
star
13

alibaba-miil.github.io

Curated list of miil papers
7
star
14

knapsack_pruning

Python
3
star
15

BINAS

Constructing interpretable bilinear accuracy predictors to serve as an objective function for an IQCQP problem that represents NAS under latency constraints and solve it with efficient algorithms.
Python
3
star