Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[New Feature]add lovasz loss #351

Merged
merged 5 commits into from
Jan 19, 2021
Merged

[New Feature]add lovasz loss #351

merged 5 commits into from
Jan 19, 2021

Conversation

yamengxi
Copy link
Collaborator

No description provided.

@hellock
Copy link
Member

hellock commented Jan 16, 2021

Task linked: CU-j6umcn Lovász-Softmax loss #351

@codecov
Copy link

codecov bot commented Jan 16, 2021

Codecov Report

Merging #351 (a222588) into master (1c96a89) will increase coverage by 0.07%.
The diff coverage is 89.18%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #351      +/-   ##
==========================================
+ Coverage   86.07%   86.14%   +0.07%     
==========================================
  Files          95       96       +1     
  Lines        4789     4900     +111     
  Branches      778      798      +20     
==========================================
+ Hits         4122     4221      +99     
- Misses        519      526       +7     
- Partials      148      153       +5     
Flag Coverage Δ
unittests 86.14% <89.18%> (+0.07%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
mmseg/models/losses/lovasz_loss.py 89.09% <89.09%> (ø)
mmseg/models/losses/__init__.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1c96a89...a222588. Read the comment docs.

@@ -0,0 +1,296 @@
import mmcv
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may add sth like

Modified from ...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Get it!

"""Binary Lovasz hinge loss.

Args:
probas (torch.Tensor): [B, H, W], logits at each pixel
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probas is not an ideal abbr.
We may use logits directly.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In our codebase, logits usually refers to unnormalized energy. prob refers to probability distribution.

"""Multi-class Lovasz-Softmax loss.

Args:
probas (torch.Tensor): [P, C], class probabilities at each prediction
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly.

"""Multi-class Lovasz-Softmax loss.

Args:
probas (torch.Tensor): [B, C, H, W], class probabilities at each
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly.


This loss is proposed in `The Lovasz-Softmax loss: A tractable surrogate
for the optimization of the intersection-over-union measure in neural
networks <https://openaccess.thecvf.com/content_cvpr_2018/html/Berman_The_LovaSz-Softmax_Loss_CVPR_2018_paper.html>`_. # noqa
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://arxiv.org/abs/1705.08790 should be fine.

# only void pixels, the gradients should be 0
return logits.sum() * 0.
signs = 2. * labels.float() - 1.
errors = (1. - logits * Variable(signs))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why Variable here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know, it is the original code.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@xvjiarui xvjiarui merged commit 0ee3016 into open-mmlab:master Jan 19, 2021
bowenroom pushed a commit to bowenroom/mmsegmentation that referenced this pull request Feb 25, 2022
* add lovasz loss

* Modify as comments

* Modify paper url

* add unittest and remove Var

* impove unittest
sibozhang pushed a commit to sibozhang/mmsegmentation that referenced this pull request Mar 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants