Channel class mapping in semantic segmentaiton

I’m using the deeplab Mobilnet pre-trained model for semantic segmentation where I have 4 classes. The prediction of my model is [batch_size,num_classes, H, W] and to calculate the loss I have made my ground truth of the same dimension having 4 binary masks and using the CrossEntropyLoss function.I want to know which channel,the prediction corresponds to which class?, and also I’m getting a massive loss of about 5000 for 1 epoch during training. Can anyone help me? Thanks!

The channel index corresponds directly to the class index and you are defining it by creating the targets.
I.e. the logits of output[:, 0] will correspond to class0, output[:, 1] to class1, etc.
You can of course change the mapping by creating the target indices in the desired order.

To make the model return 4 classes,.I have changed the last classifier layer from 22 to 4.
For example, if my classess are background, person, car and licence plate, I took the rgb mask and converted it into 4 binary mask, one for each class. Here I made sure that all targets have the same order of channels i.e. first channel is background, then person then car and then license plate. This is what is meant by defining the order in the targets sir? And will the model return the output in the same order? Thanks!

Yes, you are defining the order of the targets and the model doesn’t have any knowledge which class corresponds to which index as it just tries to learn the mapping between the input and the target.
If you define that e.g. the background class corresponds to class0 (and thus also the 0-th channel of the model output) the model will try to learn it.

1 Like

Thanks for the help!