Getting proper class predictions in multi-class segmentation

username: banikr
cooked: <p>Hello,<br>
I am using the following codes to finding the class probabilities to classify channels into different labels. The training was of 6 class labels<code>[0,1,2,3,4,56]</code> in a one-hot encoded method.</p>
<pre><code class="lang-auto">for bIdx, sample in enumerate(test_loader):                          
    img, seg = sample[0].to(device), sample[1].to(device)   # shape --&gt; [2,6,48,64,64]           
    pred = model(img)                                                 
    lbl_pred = pred.data.max(1)[1].cpu().numpy()[:, :, :].astype('uint8')                                                                                          
</code></pre>
<p>But I am missing <code>label 5</code> in the prediction/output(the cursor in the following image).<br>
<img src="https://discuss.pytorch.org/uploads/default/original/3X/8/d/8dd838b83345ff55b11e99d2bbbefeb227aa17bd.png" alt="image" data-base62-sha1="keOzHIQqJCqJEmEepQnGM3k8jMN" width="170" height="207"></p>
<p>This shows as <code>label 0</code> which is clearly not the case as label 0: background.<br>
But if I check <code>pred.data</code> separately, it has label 5 probability values in it.</p>
<pre><code class="lang-auto">plt.imshow(pred.data[0, 5, :, 20, :].cpu().numpy())
plt.show()
</code></pre>
<p>resulting in the following image.<br>
<img src="https://discuss.pytorch.org/uploads/default/original/3X/4/0/40502fb349b0ee5b516701534191bef12a6804e3.png" alt="Screenshot from 2021-06-22 22-23-57" data-base62-sha1="9aWm6ur59hV19XxFvcLPivBuYXF" width="183" height="245"></p>
<p>Am I missing anything?</p>

username: ptrblck
cooked: <p>While the class5 channel would have probabilities (or logits) for this class, the max. logit for these pixels could still be class0. Did you compare the values of both classes for the area of interest?</p>

username: banikr
cooked: <p>This is for channel 0:</p>
<pre><code class="lang-auto">c = plt.imshow(pred.data[0, 0, :, 20, :].cpu().numpy())
</code></pre>
<p><img src="https://discuss.pytorch.org/uploads/default/original/3X/6/0/604e17eac7666b5c0b68f8ae8e0a84af9b5df49f.png" alt="image" data-base62-sha1="dJX9oAikia9yvezSGMEUMg77Ijt" width="284" height="217"></p>
<p>This is for channel 5:</p>
<pre><code class="lang-auto">c = plt.imshow(pred.data[0, 5, :, 20, :].cpu().numpy())
</code></pre>
<p><img src="https://discuss.pytorch.org/uploads/default/original/3X/6/a/6ac12965f21339168a33d2904653d151f590a7bc.png" alt="image" data-base62-sha1="feoss72wnu40l0VtVnklHPwdMqU" width="270" height="206"></p>
<pre><code class="lang-auto">c = plt.imshow(pred.data[0, 1, :, 20, :].cpu().numpy())
</code></pre>
<p>Channel 1:<br>
<img src="https://discuss.pytorch.org/uploads/default/original/3X/8/b/8b13c233a3f7c19aefddd36a30dadaa49ad5ba24.png" alt="image" data-base62-sha1="jQkHsDCduNbxsBkzDsG0PgPRKWo" width="263" height="203"></p>

username: ptrblck
cooked: <p>I’m not the best at color matching, but I guess that the “yellow” output for channel5 is at <code>~0.16</code>, while the output for channel0 would be at <code>~0.2</code>. To better compare these outputs you could use the same scale for the probabilities (use <code>[0, 1]</code> as it would be the limit) or compare the values directly.</p>

username: banikr
cooked: <p>I guess the value in channels 0 and 5 are the same for the anatomy.</p>
<p>Channel 5:<br>
<img src="https://discuss.pytorch.org/uploads/default/original/3X/4/c/4cd5c75df4455cf6576eaa6e96fabccf4a5b81a1.png" alt="image" data-base62-sha1="aXIj0QAUG81PFLcz7OGsO9rIV8t" width="259" height="200"><br>
Channel 0:<br>
<img src="https://discuss.pytorch.org/uploads/default/original/3X/6/e/6ec7cd3e42fb8f39c8719bd897ece826209cdc6f.png" alt="image" data-base62-sha1="fO0AT7rNDHN6TU4m3aqR6pFYs5V" width="254" height="200"></p>
<p>I think it is because the tissue didn’t train well as visible from the dice score(TP(valid/black)).<br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/b/3/b36bcc042081cf301809efc9666c0df948ed8882.jpeg" data-download-href="https://discuss.pytorch.org/uploads/default/b36bcc042081cf301809efc9666c0df948ed8882" title="image"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/b/3/b36bcc042081cf301809efc9666c0df948ed8882_2_517x166.jpeg" alt="image" data-base62-sha1="pBeq6Ej4f6xS9k0ZhFqfaRcGTjY" width="517" height="166" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/b/3/b36bcc042081cf301809efc9666c0df948ed8882_2_517x166.jpeg, https://discuss.pytorch.org/uploads/default/optimized/3X/b/3/b36bcc042081cf301809efc9666c0df948ed8882_2_775x249.jpeg 1.5x, https://discuss.pytorch.org/uploads/default/optimized/3X/b/3/b36bcc042081cf301809efc9666c0df948ed8882_2_1034x332.jpeg 2x" data-dominant-color="F7F4F4"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">image</span><span class="informations">1504×484 102 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>

username: Faaiz
cooked: <p>How can you show all the channels?</p>