Mask size not clear in semantic segmentation

Sarmad_GTU: <p>hi all<br>
I am new in PyTorch and now I am working on semantic segmentation topics<br>
I have a question and I hope I will find the answer<br>
I have an image (RGB.PNG) and mask (contain indices of 5 classes [0, 1, 2, 3, 4]) but has three-channel (.PNG) so:<br>
How can I deal with the mask as input (batch_size x H x W)?  can I take the first channel<br>
ex:  mask = mask[:,:,0] or how ?</p>

arya47: <p>There are a few different ways to tackle this project<br>
If you have time have a look at how its done here:</p><aside class="onebox allowlistedgeneric" data-onebox-src="https://github.com/CSAILVision/semantic-segmentation-pytorch">
  <header class="source">
      <img src="https://github.githubassets.com/favicons/favicon.svg" class="site-icon" width="32" height="32">

      <a href="https://github.com/CSAILVision/semantic-segmentation-pytorch" target="_blank" rel="noopener nofollow ugc">GitHub</a>
  </header>

  <article class="onebox-body">
    <div class="aspect-image" style="--aspect-ratio:690/345;"><img src="https://opengraph.githubassets.com/d41de1bd081d3546d9e5865862f92a5bad8723f1318aae28cf7789700f252047/CSAILVision/semantic-segmentation-pytorch" class="thumbnail" width="690" height="345"></div>

<h3><a href="https://github.com/CSAILVision/semantic-segmentation-pytorch" target="_blank" rel="noopener nofollow ugc">GitHub - CSAILVision/semantic-segmentation-pytorch: Pytorch implementation...</a></h3>

  <p>Pytorch implementation for Semantic Segmentation/Scene Parsing on MIT ADE20K dataset - GitHub - CSAILVision/semantic-segmentation-pytorch: Pytorch implementation for Semantic Segmentation/Scene Par...</p>


  </article>

  <div class="onebox-metadata">
    
    
  </div>

  <div style="clear: both"></div>
</aside>


Sarmad_GTU: <p>thank you for replying<br>
I will check your link<br>
my question is exactly<br>
what is the input and output format for images and masks in semantic segmentation models any example?</p>

arya47: <p>Depends on the model you’re using. For example if you implement the original UNET from the paper it clearly defines the dimensions for images and masks<br>
<img src="https://discuss.pytorch.org/uploads/default/original/3X/e/6/e6f3c0418f8b8a7d84ab880edebd462b46f2965c.png" alt="Screenshot from 2021-08-16 19-35-40" data-base62-sha1="wX63f5Fxi1RSDqB3bIIBIk5iaio" width="647" height="454"></p>
<p>I tried out UNET a while back where i implemented the model from the paper and used it in binary segmentation task.  (Have a look at the input and output dimensions)<br>
I haven’t done anything complex in my training and the code is pretty straightforward:</p>
<h2><a name="binary-segmentation-use-case-1" class="anchor" href="#binary-segmentation-use-case-1"></a>Binary segmentation use case</h2>
<aside class="onebox allowlistedgeneric" data-onebox-src="https://github.com/aryaman-sh/Satellite-images-semantic-segmentation">
  <header class="source">
      <img src="https://github.githubassets.com/favicons/favicon.svg" class="site-icon" width="32" height="32">

      <a href="https://github.com/aryaman-sh/Satellite-images-semantic-segmentation" target="_blank" rel="noopener nofollow ugc">GitHub</a>
  </header>

  <article class="onebox-body">
    <div class="aspect-image" style="--aspect-ratio:690/344;"><img src="https://opengraph.githubassets.com/f16179d22e8cb91db677716349c5ed71b1c2c2ce741672ce3b7cbe1909d8613e/aryaman-sh/Satellite-images-semantic-segmentation" class="thumbnail" width="690" height="345"></div>

<h3><a href="https://github.com/aryaman-sh/Satellite-images-semantic-segmentation" target="_blank" rel="noopener nofollow ugc">GitHub - aryaman-sh/Satellite-images-semantic-segmentation: Satellite...</a></h3>

  <p>Satellite segmentation of satellite images to extract roads. - GitHub - aryaman-sh/Satellite-images-semantic-segmentation: Satellite segmentation of satellite images to extract roads.</p>


  </article>

  <div class="onebox-metadata">
    
    
  </div>

  <div style="clear: both"></div>
</aside>

<h2><a name="unet-in-pytorch-2" class="anchor" href="#unet-in-pytorch-2"></a>UNET in pytorch</h2>
<aside class="onebox githubfolder" data-onebox-src="https://github.com/aryaman-sh/model-implementations-PyTorch/tree/main/UNET">
  <header class="source">

      <a href="https://github.com/aryaman-sh/model-implementations-PyTorch/tree/main/UNET" target="_blank" rel="noopener nofollow ugc">github.com</a>
  </header>

  <article class="onebox-body">
    <h3><a href="https://github.com/aryaman-sh/model-implementations-PyTorch/tree/main/UNET" target="_blank" rel="noopener nofollow ugc"></a></h3>

  <p><a href="https://github.com/aryaman-sh/model-implementations-PyTorch/tree/main/UNET" target="_blank" rel="noopener nofollow ugc">//github.com/aryaman-sh/model-implementations-PyTorch/tree/main/UNET</a></p>


  </article>

  <div class="onebox-metadata">
    
    
  </div>

  <div style="clear: both"></div>
</aside>

<p>Hopefully this helps</p>

Sarmad_GTU: <p>thank you so much<br>
in the case of multiclass what will be happen?</p>

arya47: <p>Only difference i can think of is changing the number of output channels of the model.<br>
Also found a article that might help you</p><aside class="onebox allowlistedgeneric" data-onebox-src="https://medium.com/@mhamdaan/multi-class-semantic-segmentation-with-u-net-pytorch-ee81a66bba89">
  <header class="source">

      <a href="https://medium.com/@mhamdaan/multi-class-semantic-segmentation-with-u-net-pytorch-ee81a66bba89" target="_blank" rel="noopener nofollow ugc" title="05:37AM - 22 July 2021">Medium – 22 Jul 21</a>
  </header>

  <article class="onebox-body">
    <div class="aspect-image" style="--aspect-ratio:690/370;"><img src="https://miro.medium.com/max/1080/1*B16t8Do6hvuq2Q_2YOM-UQ.png" class="thumbnail" width="690" height="370"></div>

<h3><a href="https://medium.com/@mhamdaan/multi-class-semantic-segmentation-with-u-net-pytorch-ee81a66bba89" target="_blank" rel="noopener nofollow ugc">Multi-Class Semantic Segmentation with U-Net &amp; PyTorch</a></h3>

  <p>Learn how to perform image segmentation using Deep Learning and PyTorch.</p>

  <p>
    <span class="label1">Reading time: 8 min read</span>
  </p>

  </article>

  <div class="onebox-metadata">
    
    
  </div>

  <div style="clear: both"></div>
</aside>


Sarmad_GTU: <p>Thank you so much<br>
i appreciate that</p>