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

username: iArunava
cooked: <p>I am looking here in the segmentation training file from torchvision<br>
<a href="https://github.com/pytorch/vision/blob/master/references/segmentation/train.py" rel="nofollow noopener">train.py</a></p>
<pre><code class="lang-auto">def get_dataset(name, image_set, transform):
    .
    .
    .
    ds = ds_fn(p, image_set=image_set, transforms=transform)
    return ds, num_classes
</code></pre>
<p>And it has got no specific <code>target_transforms</code> just <code>transforms</code><br>
So, whatever transforms are applied to the inputs, the same are applied to the masks.</p>
<p>Now, if I see the transforms that are being applied<br>
They are</p>
<pre><code class="lang-auto">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)
</code></pre>
<p>So, the masks are also normalized (???)<br>
It should not be so, rather, this is not the case, as I have executed the file<br>
and have seen that the masks are of shape<br>
<code>[N x 21 x H x W]</code> which should be the case, and the values in the mask<br>
also, ranges from <code>0 - 21</code> (excluding <code>255</code>).</p>
<p>So, my question is where is the code that converts the masks to the tensors whose value ranges from <code>0 - 21</code> after they are normalized? (If they are)</p>
<p>P.S. This is a pretty easy question, I know, but its just that I am missing something.<br>
I am tagging <a class="mention" href="/u/ptrblck">@ptrblck</a>, as I think he can answer this easily.</p>

username: iArunava
cooked: <p>Okay. Got it!!</p>
<p>They don’t apply the <code>ToTensor</code> and <code>Normalize</code> to the masks even though they are passed into the functions! <img src="https://discuss.pytorch.org/images/emoji/apple/rofl.png?v=9" title=":rofl:" class="emoji" alt=":rofl:"> I was going crazy over this!</p>
<p>Here the two snippets of code, that brought me back from crazy<br>
In this file, <a href="https://github.com/pytorch/vision/blob/master/references/segmentation/transforms.py" rel="nofollow noopener">here</a></p>
<p><aside class="onebox githubblob">
  <header class="source">
      <a href="https://github.com/pytorch/vision/blob/3c81d474a2525b11356ca1dde299a9b1ab3715c6/references/segmentation/transforms.py#L80-L82" target="_blank" rel="nofollow noopener">github.com</a>
  </header>
  <article class="onebox-body">
    <h4><a href="https://github.com/pytorch/vision/blob/3c81d474a2525b11356ca1dde299a9b1ab3715c6/references/segmentation/transforms.py#L80-L82" target="_blank" rel="nofollow noopener">pytorch/vision/blob/3c81d474a2525b11356ca1dde299a9b1ab3715c6/references/segmentation/transforms.py#L80-L82</a></h4>
<pre class="onebox"><code class="lang-py"><ol class="start lines" start="80" style="counter-reset: li-counter 79 ;">
<li>image = F.to_tensor(image)</li>
<li>target = torch.as_tensor(np.asarray(target), dtype=torch.int64)</li>
<li>return image, target</li>
</ol></code></pre>


  </article>
  <div class="onebox-metadata">
    
    
  </div>
  <div style="clear: both"></div>
</aside>
<br>
<aside class="onebox githubblob">
  <header class="source">
      <a href="https://github.com/pytorch/vision/blob/3c81d474a2525b11356ca1dde299a9b1ab3715c6/references/segmentation/transforms.py#L91-L92" target="_blank" rel="nofollow noopener">github.com</a>
  </header>
  <article class="onebox-body">
    <h4><a href="https://github.com/pytorch/vision/blob/3c81d474a2525b11356ca1dde299a9b1ab3715c6/references/segmentation/transforms.py#L91-L92" target="_blank" rel="nofollow noopener">pytorch/vision/blob/3c81d474a2525b11356ca1dde299a9b1ab3715c6/references/segmentation/transforms.py#L91-L92</a></h4>
<pre class="onebox"><code class="lang-py"><ol class="start lines" start="91" style="counter-reset: li-counter 90 ;">
<li>image = F.normalize(image, mean=self.mean, std=self.std)</li>
<li>return image, target</li>
</ol></code></pre>


  </article>
  <div class="onebox-metadata">
    
    
  </div>
  <div style="clear: both"></div>
</aside>
</p>
<p>See, the transforms are never applied to the masks! YAY!<br>
Happy Coding Everyone! <img src="https://discuss.pytorch.org/images/emoji/apple/man_technologist.png?v=9" title=":man_technologist:" class="emoji" alt=":man_technologist:"></p>