How to handle multi-class segmentation?
See original GitHub issueHi everyone,
How does TorchIO handle multi class segmentation? For example, if I am training a 3D Semantic Segmentation Model with multiple classes, my ground truth label would be a 4D one-hot encoded label like this: num_classes * H * W * D
. For example in this snippet:
one_subject = Subject(
T1=Image('../BRATS2018_crop_renamed/LGG75_T1.nii.gz', torchio.INTENSITY),
T2=Image('../BRATS2018_crop_renamed/LGG75_T2.nii.gz', torchio.INTENSITY),
label=Image('../BRATS2018_crop_renamed/LGG75_Label.nii.gz', torchio.LABEL),
)
What is the kind of mask does the label
expect? Should it be a one-hot encoded mask or can it be a 3D mask itself, and tochio would handle the one-hot encoding part internally?
Thank you.
Issue Analytics
- State:
- Created 3 years ago
- Comments:9 (6 by maintainers)
Top Results From Across the Web
Multi-Class Semantic Segmentation with U-Net & PyTorch
Semantic segmentation is a computer vision task in which every pixel of a given image frame is classified/labelled based on whichever class ...
Read more >A Machine Learning Engineer's Tutorial to Transfer Learning ...
U-net Model from Binary to Multi-class Segmentation Tasks (Image by ... Other codebases that deal with multi-class segmentation are in [15].
Read more >How to implement multi-class semantic segmentation?
Each channel of your target should be one class. Each channel is an image of 0's and 1's, where 1 means that pixel...
Read more >U-net-for-Multi-class-semantic-segmentation - GitHub
This supports binary and multi-class segmentation. Google Colab support. The Google colab folder contains code to help replicate the process for the DIARETDB1 ......
Read more >Multiclass Segmentation - PyTorch Forums
I assume you have already found suitable code snippets for a binary segmentation use case? If so, you could use it as a...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
You can use
torchio.LabelMap
for your segmentations. They can be one-hot or not, as everything is 4D after #238.Sorry, I was wrong in my last message, transforms are ok.
Problems come when you use patch based approaches and you want to define some sampling strategies based on the values of your PV label maps. We wanted to have the same probabilty to draw a patch for every class, to do so you just have to take your different PV label maps, get the total volume occupied per class (the sum over a PV label map) and sum all your maps weighted by the inverse of the volumes. The current solution to do so would be to create a key in your sample with the probability map and call the
WeightedSampler
with this key.Maybe an implementation like the one used for the
masking_method
used in some scaling transforms would be a good idea. But it would need to accept the whole sample and not only theImage
. This would bring the flexibility to deal with multiple PV label maps and to address the possibly complicated ways of creating the probability map out of (PV) label map(s).