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

Wrong channel in DiceHelper #6409

Closed
KumoLiu opened this issue Apr 21, 2023 · 1 comment · Fixed by #6412
Closed

Wrong channel in DiceHelper #6409

KumoLiu opened this issue Apr 21, 2023 · 1 comment · Fixed by #6412
Assignees
Labels
enhancement New feature or request Feature request

Comments

@KumoLiu
Copy link
Contributor

KumoLiu commented Apr 21, 2023

Describe the bug
DiceHelper should add a n_classs arg if the user adds post-processing on the prediction, L218 will generate wrong channel.

n_pred_ch = y_pred.shape[1]

To Reproduce

import torch
import monai.transforms as mt
from monai.metrics import DiceHelper, DiceMetric

n_classes = 5
spatial_shape = (128, 128, 128)

y_pred = torch.rand(n_classes, *spatial_shape).float()  # predictions
y = torch.randint(0, n_classes, size=(1, *spatial_shape)).long()  # ground truth

y_pred_argmax = mt.AsDiscrete(argmax=True)(y_pred)

score, not_nans = DiceHelper(include_background=False, reduction="mean")(y_pred.unsqueeze(0), y.unsqueeze(0))
metric = DiceMetric(include_background=False)
metric([y_pred_argmax], [y])
_metric = metric.aggregate().item()
metric.reset()
print(_metric)
print(score, not_nans)

Expected behavior
add n_class in DiceHelper and DiceMetric
cc @wyli

@wyli
Copy link
Contributor

wyli commented Apr 21, 2023

previously the docstring states that y_pred should have n-channels though

`y_pred` is expected to have binarized predictions and `y` can be single-channel class indices or in the

`y_pred` must have N channels, `y` can be single-channel class indices or in the one-hot format.

so considering this as a feature request instead of a bug...

@wyli wyli added enhancement New feature or request Feature request labels Apr 21, 2023
@wyli wyli self-assigned this Apr 21, 2023
wyli added a commit that referenced this issue Apr 21, 2023
Fixes #6409


### 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`.
- [x] Quick tests passed locally by running `./runtests.sh --quick
--unittests --disttests`.
- [x] In-line docstrings updated.
- [x] Documentation updated, tested `make html` command in the `docs/`
folder.

---------

Signed-off-by: Wenqi Li <wenqil@nvidia.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request Feature request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants