-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Generalized Dice Loss - Reduction="none" + batch=True #5466
Comments
KumoLiu
added a commit
to KumoLiu/MONAI
that referenced
this issue
Nov 4, 2022
Signed-off-by: KumoLiu <[email protected]>
wyli
pushed a commit
that referenced
this issue
Nov 4, 2022
Signed-off-by: KumoLiu <[email protected]> Fixes #5466. ### Description In `GeneralizedDiceLoss`, now it do channel reduction before reduction, remove channel reduction in this PR. https://github.com/Project-MONAI/MONAI/blob/c38d503a587f1779914bd071a1b2d66a6d9080c2/monai/losses/dice.py#L360-L363 ### Types of changes <!--- Put an `x` in all the boxes that apply, and remove the not applicable items --> - [x] Non-breaking change (fix or new feature that would not break existing functionality). - [ ] Breaking change (fix or new feature that would cause existing functionality to change). - [x] New tests added to cover the changes. - [ ] Integration tests passed locally by running `./runtests.sh -f -u --net --coverage`. - [ ] Quick tests passed locally by running `./runtests.sh --quick --unittests --disttests`. - [ ] In-line docstrings updated. - [ ] Documentation updated, tested `make html` command in the `docs/` folder. Signed-off-by: KumoLiu <[email protected]>
wyli
pushed a commit
that referenced
this issue
Nov 6, 2022
Signed-off-by: KumoLiu <[email protected]> Fixes #5466. ### Description In `GeneralizedDiceLoss`, now it do channel reduction before reduction, remove channel reduction in this PR. https://github.com/Project-MONAI/MONAI/blob/c38d503a587f1779914bd071a1b2d66a6d9080c2/monai/losses/dice.py#L360-L363 ### Types of changes <!--- Put an `x` in all the boxes that apply, and remove the not applicable items --> - [x] Non-breaking change (fix or new feature that would not break existing functionality). - [ ] Breaking change (fix or new feature that would cause existing functionality to change). - [x] New tests added to cover the changes. - [ ] Integration tests passed locally by running `./runtests.sh -f -u --net --coverage`. - [ ] Quick tests passed locally by running `./runtests.sh --quick --unittests --disttests`. - [ ] In-line docstrings updated. - [ ] Documentation updated, tested `make html` command in the `docs/` folder. Signed-off-by: KumoLiu <[email protected]>
That's fantastic, impressed by the quickness. Well done, thank you! |
This was referenced Jul 25, 2023
wyli
added a commit
that referenced
this issue
Jul 26, 2023
Fixes #6765 ### Description as discussed in #6765, when `batch=True` the loss should still return 1 aggregated value instead of C channels. #5466 is not actually achievable with this formulation. ### Types of changes <!--- Put an `x` in all the boxes that apply, and remove the not applicable items --> - [x] Non-breaking change (fix or new feature that would not break existing functionality). - [ ] Breaking change (fix or new feature that would cause existing functionality to change). - [ ] New tests added to cover the changes. - [ ] Integration tests passed locally by running `./runtests.sh -f -u --net --coverage`. - [ ] Quick tests passed locally by running `./runtests.sh --quick --unittests --disttests`. - [ ] In-line docstrings updated. - [ ] Documentation updated, tested `make html` command in the `docs/` folder. --------- Signed-off-by: Wenqi Li <[email protected]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Describe the bug
GeneralizedDiceLoss(..., reduction="none", batch=True)
does not return the expected shape.To Reproduce
Steps to reproduce the behavior:
Correct behaviour, since I am asking for no reduction and batch=True:
While if you do the same with GeneralizedDiceLoss:
which is not correct, since again you are asking for no reduction and batch=True.
The relevant piece of code which seems to lose the correct shape is in
https://github.com/Project-MONAI/MONAI/blob/dev/monai/losses/dice.py#L360
where
numer
anddenom
are collapsed to shape (1,) since bothintersection,denominator
andw
are of shape (C,),thus
.sum(final_reduce_dim, keepdim=True)
does collapse the shape (C,) into (1,).I believe the solution would be to not let those tensors be of singleton shape (C,) but instead keep them at (1, C) or (C, 1)
Environment
Python 3.7.9,
Monai 0.9.1,
PyTorch 1.11.0
The text was updated successfully, but these errors were encountered: