Where are the masks unnormalized for Segmentation in torchvision train file?

I am looking here in the segmentation training file from torchvision
train.py

def get_dataset(name, image_set, transform):
    .
    .
    .
    ds = ds_fn(p, image_set=image_set, transforms=transform)
    return ds, num_classes

And it has got no specific target_transforms just transforms
So, whatever transforms are applied to the inputs, the same are applied to the masks.

Now, if I see the transforms that are being applied
They are

def get_transform(train):
    .
    .
    .
    transforms.append(T.ToTensor())
    transforms.append(T.Normalize(mean=[0.485, 0.456, 0.406],
                                  std=[0.229, 0.224, 0.225]))

    return T.Compose(transforms)

So, the masks are also normalized (???)
It should not be so, rather, this is not the case, as I have executed the file
and have seen that the masks are of shape
[N x 21 x H x W] which should be the case, and the values in the mask
also, ranges from 0 - 21 (excluding 255).

So, my question is where is the code that converts the masks to the tensors whose value ranges from 0 - 21 after they are normalized? (If they are)

P.S. This is a pretty easy question, I know, but its just that I am missing something.
I am tagging @ptrblck, as I think he can answer this easily.

Okay. Got it!!

They don’t apply the ToTensor and Normalize to the masks even though they are passed into the functions! :rofl: I was going crazy over this!

Here the two snippets of code, that brought me back from crazy
In this file, here


See, the transforms are never applied to the masks! YAY!
Happy Coding Everyone! :man_technologist:

1 Like