Training Semantic Segmentation

Hi,
I am trying really hard to convert the tensor I obtained after training the model to the mask image as mentioned in this question.
But before that, I am finding the below code hard to understand-

for k in mapping:
    # Get all indices for current class
    idx = (target==torch.tensor(k, dtype=torch.uint8).unsqueeze(1).unsqueeze(2))
    validx = (idx.sum(0) == 3)  # Check that all channels match
    mask[validx] = torch.tensor(mapping[k], dtype=torch.long)

I am really not understanding what’s happening here.Could you please help me out?

1 Like