question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to handle multi-class segmentation?

See original GitHub issue

Hi 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:closed
  • Created 3 years ago
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
fepegarcommented, Aug 3, 2020

You can use torchio.LabelMap for your segmentations. They can be one-hot or not, as everything is 4D after #238.

0reactions
GFabiencommented, Jul 21, 2020

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 the Image. 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).

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found