{"id":19702681,"url":"https://github.com/mikoto10032/automaticweightedloss","last_synced_at":"2025-04-05T13:06:08.337Z","repository":{"id":41190461,"uuid":"270279468","full_name":"Mikoto10032/AutomaticWeightedLoss","owner":"Mikoto10032","description":"Multi-task learning using uncertainty to weigh losses for scene geometry and semantics, Auxiliary Tasks in Multi-task Learning","archived":false,"fork":false,"pushed_at":"2020-06-20T06:07:20.000Z","size":9,"stargazers_count":611,"open_issues_count":13,"forks_count":83,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-29T12:08:03.989Z","etag":null,"topics":["auxiliary-tasks","deep-learning","multi-task","multi-task-learning","pytorch","weigh-losses"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Mikoto10032.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}},"created_at":"2020-06-07T11:06:39.000Z","updated_at":"2025-03-27T12:31:03.000Z","dependencies_parsed_at":"2022-08-10T01:43:05.043Z","dependency_job_id":null,"html_url":"https://github.com/Mikoto10032/AutomaticWeightedLoss","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/Mikoto10032%2FAutomaticWeightedLoss","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mikoto10032%2FAutomaticWeightedLoss/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mikoto10032%2FAutomaticWeightedLoss/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mikoto10032%2FAutomaticWeightedLoss/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Mikoto10032","download_url":"https://codeload.github.com/Mikoto10032/AutomaticWeightedLoss/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247339155,"owners_count":20923014,"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":["auxiliary-tasks","deep-learning","multi-task","multi-task-learning","pytorch","weigh-losses"],"created_at":"2024-11-11T21:15:50.782Z","updated_at":"2025-04-05T13:06:08.315Z","avatar_url":"https://github.com/Mikoto10032.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# AutomaticWeightedLoss\r\n\r\nA PyTorch implementation of Liebel L, Körner M. [Auxiliary tasks in multi-task learning](https://arxiv.org/pdf/1805.06334)[J]. arXiv preprint arXiv:1805.06334, 2018. \r\n\r\nThe above paper improves the paper \"[Multi-task learning using uncertainty to weigh losses for scene geometry and semantics](http://openaccess.thecvf.com/content_cvpr_2018/html/Kendall_Multi-Task_Learning_Using_CVPR_2018_paper.html)\" to avoid the loss of becoming negative during training.\r\n\r\n## Requirements\r\n\r\n* Python\r\n* PyTorch\r\n\r\n## How to Train with Your Model\r\n\r\n* Clone the repository\r\n\r\n``` bash\r\ngit clone git@github.com:Mikoto10032/AutomaticWeightedLoss.git\r\n```\r\n\r\n* Create an AutomaticWeightedLoss module\r\n\r\n```python\r\nfrom AutomaticWeightedLoss import AutomaticWeightedLoss\r\n\r\nawl = AutomaticWeightedLoss(2)\t# we have 2 losses\r\nloss1 = 1\r\nloss2 = 2\r\nloss_sum = awl(loss1, loss2)\r\n```\r\n\r\n* Create an optimizer to learn weight coefficients\r\n\r\n```python\r\nfrom torch import optim\r\n\r\nmodel = Model()\r\noptimizer = optim.Adam([\r\n                {'params': model.parameters()},\r\n                {'params': awl.parameters(), 'weight_decay': 0}\t\r\n            ])\r\n```\r\n\r\n* A complete example\r\n\r\n```python\r\nfrom torch import optim\r\nfrom AutomaticWeightedLoss import AutomaticWeightedLoss\r\n\r\nmodel = Model()\r\n\r\nawl = AutomaticWeightedLoss(2)\t# we have 2 losses\r\nloss_1 = ...\r\nloss_2 = ...\r\n\r\n# learnable parameters\r\noptimizer = optim.Adam([\r\n                {'params': model.parameters()},\r\n                {'params': awl.parameters(), 'weight_decay': 0}\r\n            ])\r\n\r\nfor i in range(epoch):\r\n    for data, label1, label2 in data_loader:\r\n        # forward\r\n        pred1, pred2 = Model(data)\t\r\n        # calculate losses\r\n        loss1 = loss_1(pred1, label1)\r\n        loss2 = loss_2(pred2, label2)\r\n        # weigh losses\r\n        loss_sum = awl(loss1, loss2)\r\n        # backward\r\n        optimizer.zero_grad()\r\n        loss_sum.backward()\r\n        optimizer.step()\r\n```\r\n\r\n## Something to Say\r\n\r\nActually, it is not always effective, but I hope it can help you.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmikoto10032%2Fautomaticweightedloss","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmikoto10032%2Fautomaticweightedloss","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmikoto10032%2Fautomaticweightedloss/lists"}