{"id":13738240,"url":"https://github.com/CoinCheung/pytorch-loss","last_synced_at":"2025-05-08T16:33:00.432Z","repository":{"id":37678058,"uuid":"180529915","full_name":"CoinCheung/pytorch-loss","owner":"CoinCheung","description":"label-smooth, amsoftmax, partial-fc, focal-loss, triplet-loss, lovasz-softmax. Maybe useful ","archived":false,"fork":false,"pushed_at":"2024-10-17T01:41:43.000Z","size":152,"stargazers_count":2230,"open_issues_count":8,"forks_count":374,"subscribers_count":23,"default_branch":"master","last_synced_at":"2025-04-11T02:51:47.092Z","etag":null,"topics":["amsoftmax","cuda","dice-loss","ema","focal-loss","label-smoothing","lovasz-softmax","mish","partial-fc","pytorch","triplet-loss"],"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/CoinCheung.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,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-04-10T07:48:03.000Z","updated_at":"2025-04-05T09:30:16.000Z","dependencies_parsed_at":"2024-10-17T16:26:14.233Z","dependency_job_id":null,"html_url":"https://github.com/CoinCheung/pytorch-loss","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/CoinCheung%2Fpytorch-loss","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CoinCheung%2Fpytorch-loss/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CoinCheung%2Fpytorch-loss/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CoinCheung%2Fpytorch-loss/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/CoinCheung","download_url":"https://codeload.github.com/CoinCheung/pytorch-loss/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253105413,"owners_count":21855019,"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":["amsoftmax","cuda","dice-loss","ema","focal-loss","label-smoothing","lovasz-softmax","mish","partial-fc","pytorch","triplet-loss"],"created_at":"2024-08-03T03:02:15.486Z","updated_at":"2025-05-08T16:33:00.144Z","avatar_url":"https://github.com/CoinCheung.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"# pytorch-loss\n\nMy implementation of label-smooth, amsoftmax, partial-fc, focal-loss, dual-focal-loss, triplet-loss, giou/diou/ciou-loss/func, affinity-loss, pc_softmax_cross_entropy, ohem-loss(softmax based on line hard mining loss), large-margin-softmax(bmvc2019), lovasz-softmax-loss, and dice-loss(both generalized soft dice loss and batch soft dice loss). Maybe this is useful in my future work.\n\n\nAlso tried to implement swish, hard-swish(hswish) and mish activation functions.\n\nAdditionally, cuda based one-hot function is added (support label smooth).\n\nNewly add an \"Exponential Moving Average(EMA)\" operator.\n\nAdd convolution ops, such as coord-conv2d, and dynamic-conv2d(dy-conv2d).\n\nSome operators are implemented with pytorch cuda extension, so you need to compile it first: \n```\n    $ python -m pip install .\n```\n\nAfter installing, now you can pick up what you need and use the losses or ops like one of thes: \n```python\nfrom pytorch_loss import SwishV1, SwishV2, SwishV3\nfrom pytorch_loss import HSwishV1, HSwishV2, HSwishV3\nfrom pytorch_loss import MishV1, MishV2, MishV3\nfrom pytorch_loss import convert_to_one_hot, convert_to_one_hot_cu, OnehotEncoder\nfrom pytorch_loss import EMA\n\nfrom pytorch_loss import TripletLoss\nfrom pytorch_loss import SoftDiceLossV1, SoftDiceLossV2, SoftDiceLossV3\nfrom pytorch_loss import PCSoftmaxCrossEntropyV1, PCSoftmaxCrossEntropyV2\nfrom pytorch_loss import LargeMarginSoftmaxV1, LargeMarginSoftmaxV2, LargeMarginSoftmaxV3\nfrom pytorch_loss import LabelSmoothSoftmaxCEV1, LabelSmoothSoftmaxCEV2, LabelSmoothSoftmaxCEV3\nfrom pytorch_loss import GIOULoss, DIOULoss, CIOULoss\nfrom pytorch_loss import iou_func, giou_func, diou_func, ciou_func\nfrom pytorch_loss import FocalLossV1, FocalLossV2, FocalLossV3\nfrom pytorch_loss import Dual_Focal_loss\nfrom pytorch_loss import GeneralizedSoftDiceLoss, BatchSoftDiceLoss\nfrom pytorch_loss import AMSoftmax\nfrom pytorch_loss import AffinityFieldLoss, AffinityLoss\nfrom pytorch_loss import OhemCELoss, OhemLargeMarginLoss\nfrom pytorch_loss import LovaszSoftmaxV1, LovaszSoftmaxV3\nfrom pytorch_loss import TaylorCrossEntropyLossV1, TaylorCrossEntropyLossV3\nfrom pytorch_loss import InfoNceDist\nfrom pytorch_loss import PartialFCAMSoftmax\n\nfrom pytorch_loss import TaylorSoftmaxV1, TaylorSoftmaxV3\nfrom pytorch_loss import LogTaylorSoftmaxV1, LogTaylorSoftmaxV3\n\nfrom pytorch_loss import CoordConv2d, DY_Conv2d\n```\nNote that some losses or ops have 3 versions, like `LabelSmoothSoftmaxCEV1`, `LabelSmoothSoftmaxCEV2`, `LabelSmoothSoftmaxCEV3`, here `V1` means the implementation with pure pytorch ops and use `torch.autograd` for backward computation, `V2` means implementation with pure pytorch ops but use self-derived formula for backward computation, and `V3` means implementation with cuda extension. Generally speaking, the `V3` ops are faster and more memory efficient, since I have tried to squeeze everything in one cuda kernel function, which in most cases brings less overhead than a combination of pytorch ops.\n\n\nFor those who happen to find this repo, if you see errors in my code, feel free to open an issue to correct me.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FCoinCheung%2Fpytorch-loss","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FCoinCheung%2Fpytorch-loss","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FCoinCheung%2Fpytorch-loss/lists"}