2493 Fix decollate logic in integration test#2494
Conversation
merge master
merge master
merge master
Signed-off-by: Nic Ma <[email protected]>
Signed-off-by: Nic Ma <[email protected]>
|
/black |
|
/integration-test |
Signed-off-by: monai-bot <[email protected]>
|
/black |
Signed-off-by: monai-bot <[email protected]>
|
This PR also slightly changed the logic of Thanks. |
Please ignore this comment, I restored back to be non-breaking. Thanks. |
|
I found an blocking issue when developing this PR: So the workflows of our current dev branch can't work with classification task. Thanks. |
Signed-off-by: Nic Ma <[email protected]>
1cb8c03 to
4f599ce
Compare
|
hi @Nic-Ma , do we not have the possibility of leaving things as they are? As in, if part of the input is Tensor, return it as a Tensor. If it's a float (for example), then return it as a float. That would avoid the binary problem that you're seeing, wouldn't it? |
|
Yes, this idea can fix the binary issue I am facing, but as the input label is # ensure input data is a PyTorch Tensor
img = torch.as_tensor(img)
# ensure `channel-first` Tensor
img = img.unsqueeze(0) if img.ndim == 0 else imgWhat do you think? Thanks. |
|
I'm a little lost, I think we're talking about classification labels, but in your code snippet you used Are you suggesting adding an extra dimension to the classification labels so that when they get decollated they stay as a tensor? |
|
I think the root cause is that both non-tensor and tensor values are collated into torch tensors by default https://github.com/pytorch/pytorch/blob/v1.9.0/torch/utils/data/_utils/collate.py#L67-L72 |
|
/build |
|
As @wyli summarized, the root cause is that we don't know the original data type when decollating.
Do you guys have any other ideas? Thanks. |
just for clarification,
so, a workaround would be making the labels to be always at least 2d tensor? we ensure the classification labels are channel-first, spatial_dim=1, e.g. we expect for the pytorch loss functions, I think the APIs may assume different input dimensions anyway...e.g. |
|
Hi @wyli , Thanks for your summary, actually, I also tested PyTorch loss functions with channel dim in labels, it failed: Thanks. |
ok, in the worst case, for case 2 we return numpy arrays for classification label outputs, what would be the issue? I don't think we need complicated postprocessing transforms for the label vector... so I don't think it is a blocking issue |
|
Hi @wyli , Do you mean to change 0-dim tensor into numpy array? Thanks. |
If tensor is needed, in the postprocessing transform we can still add a ToTensorD, and problem solved, correct? |
|
Hi @wyli , Thanks for your suggestion. Thanks. |
Cool, now it's just a documentation issue. I think we need a migration guide to explain all the decollating feature, it's a major change since 0.5.3. (I've already received questions about it) |
We can rename the "ToTensor" transform to "EnsureTensor" transform, maybe that sounds more elegant |
|
Hi @wyli , Plan sounds good to me. Let me work on these following PRs next week.
Thanks. |
|
/black |
|
/integration-test |
|
Integration tests passed locally with V100 GPU. Thanks. |
wyli
left a comment
There was a problem hiding this comment.
thanks! we'll have some follow-ups as discussed in the PR comments
Fixes #2493 .
Description
This PR added the missing decollate logic in integration test and also enhanced plot API to support new data shape.
Status
Ready
Types of changes
./runtests.sh -f -u --net --coverage../runtests.sh --quick --unittests.make htmlcommand in thedocs/folder.