{"id":15029342,"url":"https://github.com/bermanmaxim/lovaszsoftmax","last_synced_at":"2025-04-08T08:16:12.082Z","repository":{"id":40685937,"uuid":"122314187","full_name":"bermanmaxim/LovaszSoftmax","owner":"bermanmaxim","description":"Code for the Lovász-Softmax loss (CVPR 2018)","archived":false,"fork":false,"pushed_at":"2024-04-12T21:01:35.000Z","size":2162,"stargazers_count":1388,"open_issues_count":18,"forks_count":270,"subscribers_count":31,"default_branch":"master","last_synced_at":"2025-04-08T08:15:52.355Z","etag":null,"topics":["image-segmentation","loss-functions","neural-networks","pytorch"],"latest_commit_sha":null,"homepage":"http://bmax.im/LovaszSoftmax","language":"Jupyter Notebook","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/bermanmaxim.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":"2018-02-21T09:11:59.000Z","updated_at":"2025-03-17T01:06:36.000Z","dependencies_parsed_at":"2024-12-21T09:05:23.421Z","dependency_job_id":"04a10033-2e53-4aa5-959b-b36a8fb7fea4","html_url":"https://github.com/bermanmaxim/LovaszSoftmax","commit_stats":{"total_commits":27,"total_committers":4,"mean_commits":6.75,"dds":"0.11111111111111116","last_synced_commit":"7d48792d35a04d3167de488dd00daabbccd8334b"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bermanmaxim%2FLovaszSoftmax","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bermanmaxim%2FLovaszSoftmax/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bermanmaxim%2FLovaszSoftmax/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bermanmaxim%2FLovaszSoftmax/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bermanmaxim","download_url":"https://codeload.github.com/bermanmaxim/LovaszSoftmax/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247801175,"owners_count":20998339,"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":["image-segmentation","loss-functions","neural-networks","pytorch"],"created_at":"2024-09-24T20:10:21.737Z","updated_at":"2025-04-08T08:16:12.040Z","avatar_url":"https://github.com/bermanmaxim.png","language":"Jupyter Notebook","funding_links":[],"categories":[],"sub_categories":[],"readme":"# The Lovász-Softmax loss: A tractable surrogate for the optimization of the intersection-over-union measure in neural networks\n\n\u003cimg src=\"https://cdn.rawgit.com/bermanmaxim/bermanmaxim.github.io/5edecd41/single_LSimage.jpg\" height=\"180\"\u003e\n\nMaxim Berman, Amal Rannen Triki, Matthew B. Blaschko\n\nESAT-PSI, KU Leuven, Belgium.\n\nPublished in CVPR 2018. See [project page](http://bmax.im/LovaszSoftmax), [arxiv paper](https://arxiv.org/abs/1705.08790), [paper on CVF open access](http://openaccess.thecvf.com/content_cvpr_2018/html/Berman_The_LovaSz-Softmax_Loss_CVPR_2018_paper.html).\n\n## PyTorch implementation of the loss layer (*pytorch* folder)\n**Files included:**\n* **lovasz_losses.py**: Standalone PyTorch implementation of the Lovász hinge and Lovász-Softmax for the Jaccard index\n* **demo_binary.ipynb**: Jupyter notebook showcasing binary training of a linear model, with the Lovász Hinge and with the Lovász-Sigmoid.\n* **demo_multiclass.ipynb**: Jupyter notebook showcasing multiclass training of a linear model with the Lovász-Softmax\n\nThe binary `lovasz_hinge` expects real-valued scores (positive scores correspond to foreground pixels). \n\nThe multiclass `lovasz_softmax` expect class probabilities (the maximum scoring category is predicted). First use a `Softmax` layer on the unnormalized scores.\n\n## TensorFlow implementation of the loss layer (*tensorflow* folder)\n**Files included:**\n* **lovasz_losses_tf.py**: Standalone TensorFlow implementation of the Lovász hinge and Lovász-Softmax for the Jaccard index\n* **demo_binary_tf.ipynb**: Jupyter notebook showcasing binary training of a linear model, with the Lovász Hinge and with the Lovász-Sigmoid.\n* **demo_multiclass_tf.ipynb**: Jupyter notebook showcasing the application of the multiclass loss with the Lovász-Softmax\n\n*Warning: the losses values and gradients have been tested to be the same as in PyTorch (see notebooks), however we have not used the TF implementation in a training setting.*\n\n## Usage\nSee the demos for simple proofs of principle.\n\n## FAQ\n* How should I use the Lovász-Softmax loss?\n\nThe loss can be optimized on its own, but the optimal optimization hyperparameters (learning rates, momentum) might be different from the best ones for cross-entropy. As discussed in the paper, optimizing the dataset-mIoU (Pascal VOC measure) is dependent on the batch size and number of classes. Therefore you might have best results by optimizing with cross-entropy first and finetuning with our loss, or by combining the two losses. \n\nSee for example how the work [*Land Cover Classification From Satellite Imagery With U-Net and Lovasz-Softmax Loss* by Alexander Rakhlin et al.](http://openaccess.thecvf.com/content_cvpr_2018_workshops/w4/html/Rakhlin_Land_Cover_Classification_CVPR_2018_paper.html) used our loss in the [CVPR 18 DeepGlobe challenge](http://deepglobe.org/).\n\n* Inference in Tensorflow is very slow...\n\nCompiling from Tensorflow master (or using a future distribution that includes commit [tensorflow/tensorflow@73e3215](https://github.com/tensorflow/tensorflow/commit/73e3215c3a2edadbf9111cca44ab3d5ca146c327)) should solve this problem; see [issue #6](https://github.com/bermanmaxim/LovaszSoftmax/issues/6).\n\n## Citation\nPlease cite\n```\n@inproceedings{berman2018lovasz,\n  title={The Lov{\\'a}sz-Softmax loss: A tractable surrogate for the optimization of the intersection-over-union measure in neural networks},\n  author={Berman, Maxim and Rannen Triki, Amal and Blaschko, Matthew B},\n  booktitle={Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition},\n  pages={4413--4421},\n  year={2018}\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbermanmaxim%2Flovaszsoftmax","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbermanmaxim%2Flovaszsoftmax","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbermanmaxim%2Flovaszsoftmax/lists"}