segmentation_models.pytorch icon indicating copy to clipboard operation
segmentation_models.pytorch copied to clipboard

Multiclass segmentation, some basic questions

Open karaposu opened this issue 1 year ago • 5 comments

Hello All, This is a great library which i am already using for couple of my projects. But I couldnt manage to make it work for multiclass segmentation. There is one outdated example and it is not enough. I have couple of questions

Should labels for each segmentation class merged in channel-wise manner of unique-class-pixel-value-wise manner (should we add to the label masks a channel for each class we want to segment or should we create one channel label image with different pixel values for each class?)

How should the post processsing funciton change for multiclass segmentation? Simply changing the labels and and changing the num_classes variable in relevant function is enough?

karaposu avatar Nov 20 '23 14:11 karaposu

I created one channel label image by indexing the RGB value of different classes from label images, and it worked. It has been a month since you opened this issue, have you solved your problem and successfully used this repo for multiclass segmentation? I got a question to consult. Can you set batch size more than 1 and successfully run this code when doing multiclass segmentation? It comes up errors about unmatched size of predicted and ground truth data when batch size isn't 1.

Billy-ZTB avatar Dec 26 '23 05:12 Billy-ZTB

@Billy-ZTB yes, i managed to do 3 class segmentation and batch number was 32 i think. However one class was imbalanced (only very small part of the image) and this caused not really good results

karaposu avatar Dec 26 '23 13:12 karaposu

@Billy-ZTB yes, i managed to do 3 class segmentation and batch number was 32 i think. However one class was imbalanced (only very small part of the image) and this caused not really good results

What could be the solution to imbalanced samples? I think I am encountering this kind of problem. I used this repo to do 8 class segmentation but it came out to predict all the pixels to 4 of those classes.

Billy-ZTB avatar Jan 05 '24 03:01 Billy-ZTB

@Billy-ZTB yes, i managed to do 3 class segmentation and batch number was 32 i think. However one class was imbalanced (only very small part of the image) and this caused not really good results

What could be the solution to imbalanced samples? I think I am encountering this kind of problem. I used this repo to do 8 class segmentation but it came out to predict all the pixels to 4 of those classes.

i think there is an option to give weight to classes, however in my case this did not help much. We should run some experiments to understand. lets say we have 3 class A, B and C (very small area). We already now doing 2 class segmentation with A,B works. Now we need to train individual model for C and see that model can segment it well regardless of it being only small area of image. If yes, Then we need to try B, C together. If this doesnt work well then we must increase model complexity and try again.

karaposu avatar Jan 06 '24 07:01 karaposu

@Billy-ZTB yes, i managed to do 3 class segmentation and batch number was 32 i think. However one class was imbalanced (only very small part of the image) and this caused not really good results

What could be the solution to imbalanced samples? I think I am encountering this kind of problem. I used this repo to do 8 class segmentation but it came out to predict all the pixels to 4 of those classes.

i think there is an option to give weight to classes, however in my case this did not help much. We should run some experiments to understand. lets say we have 3 class A, B and C (very small area). We already now doing 2 class segmentation with A,B works. Now we need to train individual model for C and see that model can segment it well regardless of it being only small area of image. If yes, Then we need to try B, C together. If this doesnt work well then we must increase model complexity and try again.

Thanks, that is a way to find out if the sample is imbalanced, I will try it later.

Billy-ZTB avatar Jan 07 '24 10:01 Billy-ZTB

Is there any chance you'd be willing to share the code for multiclass? I can't figure out what I need to change to make it work. For reference, I'm trying to get 4 classes to work, one of which being a background class. Any help would be appreciated.

brandon-dubbs avatar Feb 22 '24 01:02 brandon-dubbs

@brandon-dubbs np at all, here is my repo: https://github.com/karaposu/head-segmentation/blob/main/configs/training_experiment.yaml (The config file in this link shows i am using 3 classes. However structure of repo might be a bit complex. )

what you need is probably the create_multiclass_segmaps_pixel_wise function in this file : https://github.com/karaposu/head-segmentation/blob/main/scripts/dataset/preprocess_raw_dataset.py

karaposu avatar Feb 22 '24 17:02 karaposu

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 7 days.

github-actions[bot] avatar Apr 23 '24 01:04 github-actions[bot]

This issue was closed because it has been stalled for 7 days with no activity.

github-actions[bot] avatar May 01 '24 01:05 github-actions[bot]