{"id":13738194,"url":"https://github.com/Alibaba-MIIL/ASL","last_synced_at":"2025-05-08T16:32:39.840Z","repository":{"id":41575685,"uuid":"299613439","full_name":"Alibaba-MIIL/ASL","owner":"Alibaba-MIIL","description":"Official Pytorch Implementation of: \"Asymmetric Loss For Multi-Label Classification\"(ICCV, 2021) paper","archived":false,"fork":false,"pushed_at":"2023-08-04T19:49:20.000Z","size":1530,"stargazers_count":733,"open_issues_count":20,"forks_count":102,"subscribers_count":11,"default_branch":"main","last_synced_at":"2024-11-15T07:33:55.724Z","etag":null,"topics":["classification","detection","loss","multi-label-classification"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Alibaba-MIIL.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2020-09-29T12:40:13.000Z","updated_at":"2024-11-14T12:09:04.000Z","dependencies_parsed_at":"2023-02-09T02:46:16.560Z","dependency_job_id":"4c863aae-730c-42dd-9bc1-79e304227aaf","html_url":"https://github.com/Alibaba-MIIL/ASL","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Alibaba-MIIL%2FASL","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Alibaba-MIIL%2FASL/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Alibaba-MIIL%2FASL/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Alibaba-MIIL%2FASL/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Alibaba-MIIL","download_url":"https://codeload.github.com/Alibaba-MIIL/ASL/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253105357,"owners_count":21855009,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["classification","detection","loss","multi-label-classification"],"created_at":"2024-08-03T03:02:13.968Z","updated_at":"2025-05-08T16:32:39.500Z","avatar_url":"https://github.com/Alibaba-MIIL.png","language":"Python","funding_links":[],"categories":["Python","Classification"],"sub_categories":[],"readme":"# Asymmetric Loss For Multi-Label Classification\n\n[![PWC](https://img.shields.io/endpoint.svg?url=https://paperswithcode.com/badge/imagenet-21k-pretraining-for-the-masses/multi-label-classification-on-ms-coco)](https://paperswithcode.com/sota/multi-label-classification-on-ms-coco?p=imagenet-21k-pretraining-for-the-masses)\u003cbr\u003e\n[![PWC](https://img.shields.io/endpoint.svg?url=https://paperswithcode.com/badge/asymmetric-loss-for-multi-label/multi-label-classification-on-nus-wide)](https://paperswithcode.com/sota/multi-label-classification-on-nus-wide?p=asymmetric-loss-for-multi-label)\u003cbr\u003e\n[![PWC](https://img.shields.io/endpoint.svg?url=https://paperswithcode.com/badge/imagenet-21k-pretraining-for-the-masses/multi-label-classification-on-pascal-voc-2007)](https://paperswithcode.com/sota/multi-label-classification-on-pascal-voc-2007?p=imagenet-21k-pretraining-for-the-masses)\u003cbr\u003e\n\u003cbr\u003e [Paper](https://arxiv.org/abs/2009.14119) |\n[Pretrained models](MODEL_ZOO.md)  |\n[Datasets](Datasets.md)\n\nOfficial PyTorch Implementation\n\n\u003e Emanuel Ben-Baruch, Tal Ridnik, Nadav Zamir, Asaf Noy, Itamar\n\u003e Friedman, Matan Protter, Lihi Zelnik-Manor\u003cbr/\u003e DAMO Academy, Alibaba\n\u003e Group\n\n**Abstract**\n\nIn 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.\n\n\u003c!--\u003cp align=\"center\"\u003e--\u003e\n\u003c!-- \u003ctable class=\"tg\"\u003e--\u003e\n\u003c!--  \u003ctr\u003e--\u003e\n\u003c!--    \u003ctd class=\"tg-c3ow\"\u003e\u003cimg src=\"./pics/loss_graph.png\" align=\"center\" width=\"400\" \u003e\u003c/td\u003e--\u003e\n\u003c!--    \u003ctd class=\"tg-c3ow\"\u003e\u003cimg src=\"./pics/backbones.png\" align=\"center\" width=\"400\" \u003e\u003c/td\u003e--\u003e\n\u003c!--  \u003c/tr\u003e--\u003e\n\u003c!--\u003c/table\u003e--\u003e\n\u003c!--\u003c/p\u003e--\u003e\n\n## 9/1/2023 Update\nAdded [tests](https://github.com/Alibaba-MIIL/ASL/blob/main/tests/test_asl.py) auto-generated by [CodiumAI](https://www.codium.ai/) tool\n\n## 29/11/2021 Update - New article released, offering new classification head with state-of-the-art results\nCheckout our new project, [Ml-Decoder](https://github.com/Alibaba-MIIL/ML_Decoder), which presents a unified classification head for multi-label, single-label and\nzero-shot tasks. Backbones with ML-Decoder reach SOTA results, while also improving speed-accuracy tradeoff.\n\n\u003cp align=\"center\"\u003e\n \u003ctable class=\"tg\"\u003e\n  \u003ctr\u003e\n    \u003ctd class=\"tg-c3ow\"\u003e\u003cimg src=\"./pics/main_pic.png\" align=\"center\" width=\"300\"\"\u003e\u003c/td\u003e\n    \u003ctd class=\"tg-c3ow\"\u003e\u003cimg src=\"./pics/ms_coco_scores.png\" align=\"center\" width=\"300\" \u003e\u003c/td\u003e\n\n  \u003c/tr\u003e\n\u003c/table\u003e\n\u003c/p\u003e\n\n## 24/7/2021 Update - ASL article was accepeted to ICCV 2021\nA final version of the paper, with updated results for ImageNet-21K pretraining, is released to arxiv.  \nNote 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.\n\n\u003c!--## 23/4/2021 Update - ImageNet21K Pretraining--\u003e\n\u003c!--In a new [article](https://github.com/Alibaba-MIIL/ImageNet21K) we released, we share pretrain weights for different models, that dramatically outperfrom standard pretraining on downstream tasks, including multi-label ones.  --\u003e\n\u003c!--We also compare in the article multi-label pretrianing with ASL on ImageNet21K to pretraining with standard loss functions (cross-entropy and focal loss).--\u003e\n\n## Training Code Now Available !\n\nWith great collaboration by [@GhostWnd](https://github.com/GhostWnd), we\nnow provide a [script](train.py) for fully reproducing the article\nresults, and finally a \u003cu\u003emodern\u003c/u\u003e multi-label training code is\navailable for the community.\n## Frequently Asked Questions\nSome questions are repeatedly asked in the issues section. make sure to\nreview them before starting a new issue:\n- Regarding combining ASL with other techniques, see\n  [link](https://github.com/Alibaba-MIIL/ASL/issues/35)\n- Regarding implementation of asymmetric clipping, see [link](https://github.com/Alibaba-MIIL/ASL/issues/10)\n- Regarding disable_torch_grad_focal_loss option, see\n  [link](https://github.com/Alibaba-MIIL/ASL/issues/31)\n- Regarding squish Vs crop resizing, see\n  [link](https://github.com/Alibaba-MIIL/ASL/issues/30#issuecomment-754005570)\n- Regarding training tricks, see\n  [link](https://github.com/Alibaba-MIIL/ASL/issues/30#issuecomment-750780576)\n- How to apply ASL to your own dataset, see\n  [link](https://github.com/Alibaba-MIIL/ASL/issues/22#issuecomment-736721770)\n\n\n\n## Asymmetric Loss (ASL) Implementation\nIn this PyTorch [file](\\src\\loss_functions\\losses.py), we provide \nimplementations of our new loss function, ASL, that can serve as a\ndrop-in replacement for standard loss functions (Cross-Entropy and\nFocal-Loss)\n\nFor the multi-label case (sigmoids), the two implementations are: \n- ```class AsymmetricLoss(nn.Module)```\n- ```class AsymmetricLossOptimized(nn.Module)``` \u003cbr\u003e\n\nThe two losses are bit-accurate. However, AsymmetricLossOptimized()\ncontains a more optimized (and complicated) way of implementing ASL,\nwhich minimizes memory allocations, gpu uploading, and favors inplace\noperations.\n\nFor the single-label case (softmax), the implementations is called:\n- ```class ASLSingleLabel(nn.Module)```\n\n\n\n## Pretrained Models\nIn this [link](MODEL_ZOO.md), we provide pre-trained models on various\ndataset. \n\n## Validation Code\nThanks to external contribution of @hellbell, we now provide a\nvalidation code that repdroduces the article results on MS-COCO:\n\n```\npython validate.py  \\\n--model_name=tresnet_l \\\n--model_path=./models_local/MS_COCO_TRresNet_L_448_86.6.pth\n```\n\n## Inference Code\nWe provide [inference code](infer.py), that demonstrate how to load our\nmodel, pre-process an image and do actuall inference. Example run of\nMS-COCO model (after downloading the relevant model):\n```\npython infer.py  \\\n--dataset_type=MS-COCO \\\n--model_name=tresnet_l \\\n--model_path=./models_local/MS_COCO_TRresNet_L_448_86.6.pth \\\n--pic_path=./pics/000000000885.jpg \\\n--input_size=448\n```\nwhich will result in:\n\u003cp align=\"center\"\u003e\n \u003ctable class=\"tg\"\u003e\n  \u003ctr\u003e\n    \u003ctd class=\"tg-c3ow\"\u003e\u003cimg src=\"./pics/example_inference.jpeg\" align=\"center\" width=\"600\" \u003e\u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\u003c/p\u003e\n\nExample run of OpenImages model:\n```\npython infer.py  \\\n--dataset_type=OpenImages \\\n--model_name=tresnet_l \\\n--model_path=./models_local/Open_ImagesV6_TRresNet_L_448.pth \\\n--pic_path=./pics/000000000885.jpg \\\n--input_size=448\n```\n\u003cp align=\"center\"\u003e\n \u003ctable class=\"tg\"\u003e\n  \u003ctr\u003e\n    \u003ctd class=\"tg-c3ow\"\u003e\u003cimg src=\"./pics/example_inference_open_images.jpeg\" align=\"center\" width=\"600\" \u003e\u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\u003c/p\u003e\n\n\n## Citation\n```\n @misc{benbaruch2020asymmetric, \n        title={Asymmetric Loss For Multi-Label Classification}, \n        author={Emanuel Ben-Baruch and Tal Ridnik and Nadav Zamir and Asaf Noy and Itamar Friedman and Matan Protter and Lihi Zelnik-Manor}, \n        year={2020}, \n        eprint={2009.14119},\n        archivePrefix={arXiv}, \n        primaryClass={cs.CV} }\n```\n\n## Contact\nFeel free to contact if there are any questions or issues - Emanuel\nBen-Baruch (emanuel.benbaruch@alibaba-inc.com) or Tal Ridnik (tal.ridnik@alibaba-inc.com).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FAlibaba-MIIL%2FASL","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FAlibaba-MIIL%2FASL","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FAlibaba-MIIL%2FASL/lists"}