How to correctly mutli-channel labels in single channel after onehot encoding? #6868
Replies: 2 comments 1 reply
-
Hi @OmarAshkar, you can also add an AsDiscrete for the label.
Thanks! |
Beta Was this translation helpful? Give feedback.
-
Thanks @KumoLiu. I just keep getting inconsitencies here and there. For example, in this tutorial https://github.com/Project-MONAI/tutorials/blob/main/3d_segmentation/brats_segmentation_3d.ipynb 3 labels were passed as onehot (not using AsDiscrete for that process). and the post_trans looked like that and it resulted in 3 label channels again.
If I used used this same config, I get only one channel with my 5 labels that causes error on calculate dice between the outputs and labels. But if I passed to_onehot, I get the correct shape. So why the tutorial data gives different results? Also, would it differ here if I used threshold or argmax? Also did the loss function looks correctly like that for multi-label?
Many thanks! |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello,
I have a struggle here. I started from the unet_2d tutorial and changed few things:
1- included 5 clasess (4 labels + 0 bg)
2- used reduction in Dice as "None"
3- Changed the post-process in the evaluation to have argmax.
4- change to swin-unetr
Here is the training code:
The training was finished successfully but I need to evaluate and save the output inference
here is the eval code
By adding argmax before dice_metric(), I get size mismatch
ValueError: y_pred and y should have same shapes, got torch.Size([1, 1, 512, 512]) and torch.Size([1, 5, 512, 512]).
I need to return and save one channel with the class predicted.
Thanks in advance.
Beta Was this translation helpful? Give feedback.
All reactions