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

[Bug fixed]Fix dice_loss errors #417

Merged
merged 4 commits into from
Mar 29, 2021
Merged

Conversation

xiexinch
Copy link
Collaborator

Fix training errors #411

@xiexinch xiexinch closed this Mar 13, 2021
@xiexinch xiexinch reopened this Mar 13, 2021
@codecov
Copy link

codecov bot commented Mar 13, 2021

Codecov Report

Merging #417 (ab5ebc8) into master (7e1b24d) will decrease coverage by 0.06%.
The diff coverage is 76.92%.

❗ Current head ab5ebc8 differs from pull request most recent head 22f9fb4. Consider uploading reports for the commit 22f9fb4 to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##           master     #417      +/-   ##
==========================================
- Coverage   86.44%   86.38%   -0.07%     
==========================================
  Files          97       97              
  Lines        4958     4957       -1     
  Branches      805      804       -1     
==========================================
- Hits         4286     4282       -4     
- Misses        517      519       +2     
- Partials      155      156       +1     
Flag Coverage Δ
unittests 86.38% <76.92%> (-0.07%) ⬇️

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

Impacted Files Coverage Δ
mmseg/apis/test.py 22.68% <ø> (ø)
mmseg/models/segmentors/base.py 44.95% <0.00%> (-0.42%) ⬇️
mmseg/apis/inference.py 66.07% <50.00%> (ø)
mmseg/models/decode_heads/fcn_head.py 100.00% <100.00%> (ø)
mmseg/models/losses/dice_loss.py 100.00% <100.00%> (+1.96%) ⬆️
mmseg/datasets/pipelines/transforms.py 97.12% <0.00%> (-0.87%) ⬇️

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 7e1b24d...22f9fb4. Read the comment docs.

@zhongqiu1245
Copy link

zhongqiu1245 commented Mar 13, 2021

Hi
I used your modified dice_loss to test, the original error disappeared, but a new error appeared.
My data is only two types (background and people), in the VOC format.

No error is reported when loss is the Cross_Entropy or LovaszLoss
It will appear when loss is DiceLoss:
"num_classes=(1 if num_classes == 2 else num_classes))
RuntimeError: Class values must be smaller than num_classes."
2021-03-13 22-09-26屏幕截图

In the config file, I call DiceLoss like this:
loss_decode=dict(type='DiceLoss')
Is this method right?
Thank you!

@xiexinch
Copy link
Collaborator Author

Hi
I used your modified dice_loss to test, the original error disappeared, but a new error appeared.
My data is only two types (background and people), in the VOC format.

No error is reported when loss is the Cross_Entropy or LovaszLoss
It will appear when loss is DiceLoss:
"num_classes=(1 if num_classes == 2 else num_classes))
RuntimeError: Class values must be smaller than num_classes."
2021-03-13 22-09-26屏幕截图

In the config file, I call DiceLoss like this:
loss_decode=dict(type='DiceLoss')
Is this method right?
Thank you!

Hi @zhongqiu1245
This error occurs if num_classes == 2, I am trying to fix it, sorry..

@zhongqiu1245
Copy link

zhongqiu1245 commented Mar 19, 2021

Thanks, it works perfectly
Sorry to interrupt you again, I want to try to change dice loss to tversky loss, but I am having trouble calculating the false positives and false negatives on the denominator.
How do you calculate false positives and false negatives?
Why is the denominator of your dice loss the sum of squares? Is there any benefit to doing this?
Thank you

@xiexinch xiexinch mentioned this pull request Mar 19, 2021
Comment on lines 81 to 90
assert loss_type in ['multi_class', 'binary']
if loss_type == 'multi_class':
self.cls_criterion = dice_loss
else:
self.cls_criterion = binary_dice_loss
# assert loss_type in ['multi_class', 'binary']
# if loss_type == 'multi_class':
# # self.cls_criterion = dice_loss
# self.binary_cls = False
# else:
# # self.cls_criterion = binary_dice_loss
# self.binary_cls = True
# self.cls_criterion = dice_loss
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why comment these lines?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Cause dice_loss() method has handled these two cases, I think it's no need to add extra codes.

Copy link
Collaborator

Choose a reason for hiding this comment

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

In this case, we could delete this code.

@xvjiarui
Copy link
Collaborator

Kindly ping @xiexinch

@xiexinch
Copy link
Collaborator Author

Kindly ping @xiexinch

I will update it soon, sorry..

@xvjiarui xvjiarui merged commit 1fc3e37 into open-mmlab:master Mar 29, 2021
@ChenLiufeng
Copy link

Hi
I used your modified dice_loss to test, the original error disappeared, but a new error appeared.
My data is only two types (background and people), in the VOC format.
No error is reported when loss is the Cross_Entropy or LovaszLoss
It will appear when loss is DiceLoss:
"num_classes=(1 if num_classes == 2 else num_classes))
RuntimeError: Class values must be smaller than num_classes."
2021-03-13 22-09-26屏幕截图
In the config file, I call DiceLoss like this:
loss_decode=dict(type='DiceLoss')
Is this method right?
Thank you!

Hi @zhongqiu1245 This error occurs if num_classes == 2, I am trying to fix it, sorry..
@xiexinch I changed loss_decode=dict(type='FocalLoss'). And my num_classes=2. I met the same problem.
J$0C}0 4K$NR)CZ)MV}C@2U
Could you fix it? Thanks!

bowenroom pushed a commit to bowenroom/mmsegmentation that referenced this pull request Feb 25, 2022
* fix training bugs

* fix unitest error

* fix error in num_classes==2 case

* delete comments
aravind-h-v pushed a commit to aravind-h-v/mmsegmentation that referenced this pull request Mar 27, 2023
* Update conditional_image_generation.mdx

* Update unconditional_image_generation.mdx
sibozhang pushed a commit to sibozhang/mmsegmentation that referenced this pull request Mar 22, 2024
* update template

* update emoji
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.

4 participants