I have a follow up question on this-
1)Do we need to apply any normalisation on the masks?
Following is my custom data loader for image segmentation-
class DataLoaderSegmentation(data.Dataset):
    def __init__(self,folder_path,transform = None):
        super(DataLoaderSegmentation, self).__init__()
        self.img_files = glob.glob(os.path.join(folder_path,'images','*.tif'))
        self.mask_files = glob.glob(os.path.join(folder_path,'mask','*.bmp'))
        self.transform = transform
    def __getitem__(self, index):
        img_path = self.img_files[index]
        mask_path = self.mask_files[index]
        data = Image.open(img_path)
        label = Image.open(mask_path)
        if self.transform:
            data = self.transform(data)
        label = np.array(label)
        return data, torch.from_numpy(label).long()
    
    def __len__(self):
        return len(self.img_files)`Preformatted text`

Also when I don’t use transform.ToTensor normalisation but rather use torch.from_numpy(label).long(), the shape of target comes out to be Batch_size,height,width,num_channels
2)Why the difference and how to solve this problem?
3)Also, I couldn’t understand this line much Depending on the format of your segmentation mask images, you might need to create a mapping e.g. between color codes and the corresponding class indices.