Getting correct output

arefmalek: <p>Hello,</p>
<p>I am trying to get my net to output a prediction for each input image, but I am only getting it to predict two value, rather then 4 for each input image.</p>
<p><div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/6/b/6ba914303d87d5439a8665204be433dc2404f6a2.png" data-download-href="https://discuss.pytorch.org/uploads/default/6ba914303d87d5439a8665204be433dc2404f6a2" title="image"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/6/b/6ba914303d87d5439a8665204be433dc2404f6a2_2_690x457.png" alt="image" data-base62-sha1="fmpl1Bwg8aIPWzI2NBgr5m1GRcC" width="690" height="457" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/6/b/6ba914303d87d5439a8665204be433dc2404f6a2_2_690x457.png, https://discuss.pytorch.org/uploads/default/optimized/3X/6/b/6ba914303d87d5439a8665204be433dc2404f6a2_2_1035x685.png 1.5x, https://discuss.pytorch.org/uploads/default/original/3X/6/b/6ba914303d87d5439a8665204be433dc2404f6a2.png 2x" data-dominant-color="F3F4F4"><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">1135×752 78.1 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>
<p>I was going through a pretrained CNN (mnist for digits) and it predicts 4 tensors desptie its final linear layer outputting 10 (not 4)</p>
<p><strong>mnist dataset - not the one I want to fix</strong><br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/a/b/ab1459d79d4d73d5f1cb9a46b547ba03577aabe8.png" data-download-href="https://discuss.pytorch.org/uploads/default/ab1459d79d4d73d5f1cb9a46b547ba03577aabe8" title="image"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/a/b/ab1459d79d4d73d5f1cb9a46b547ba03577aabe8_2_689x410.png" alt="image" data-base62-sha1="oprfrIXDUkg2gUX2sexQDthd3FC" width="689" height="410" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/a/b/ab1459d79d4d73d5f1cb9a46b547ba03577aabe8_2_689x410.png, https://discuss.pytorch.org/uploads/default/optimized/3X/a/b/ab1459d79d4d73d5f1cb9a46b547ba03577aabe8_2_1033x615.png 1.5x, https://discuss.pytorch.org/uploads/default/original/3X/a/b/ab1459d79d4d73d5f1cb9a46b547ba03577aabe8.png 2x" data-dominant-color="F1F2F2"><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">1209×720 76.3 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>

ptrblck: <aside class="quote no-group" data-username="arefmalek" data-post="1" data-topic="112130">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/a/82dd89/48.png" class="avatar"> arefmalek:</div>
<blockquote>
<p>I am trying to get my net to output a prediction for each input image, but I am only getting it to predict two value, rather then 4 for each input image.</p>
</blockquote>
</aside>
<p>Your model uses two output neurons via <code>self.fc3</code>, which will result in an output shape of <code>[batch_size, 2]</code> and can be used for a 2-class multi-class classification.<br>
Currently your model is most likely reshaping the activation in a wrong way, as the batch size is set to 4, while the model only returns a single prediction.<br>
Change the <code>view</code> operation to:</p>
<pre data-code-wrap="python"><code class="lang-python">x = x.view(x.size(0), -1)
</code></pre>
<p>and you should get a shape mismatch error in <code>self.fc1</code>. Use the reported shapes from the error message to change the <code>in_features</code> in <code>self.fc1</code>.</p>
<p>PS: you can post code snippets by wrapping them into three backticks ```, which would make debugging easier.</p>