CNN model pytorch

randinoo: <p>I tested this code</p>
<pre><code class="lang-auto">class Net(nn.Module):
    def __init__(self):
        super(Net,self).__init__()
        

        self.features1 = nn.Sequential(
            nn.Conv2d(1, 6, 3, 1, 1),
            nn.ReLU(),
            nn.MaxPool2d(2),
            nn.Conv2d(6,6, 3, 1, 1),
            nn.ReLU(),
            nn.MaxPool2d(2)
        )
      
        self.fc_out = nn.Linear((6), 2)
        
    def forward(self, x1):
        x1 = self.features1(x1)
        x1 = x1.view(x1.size(0), -1)
        x1 = F.relu(self.fc_out(x1))
        x1 = self.fc_out(x1)
        return x1
</code></pre>
<p>but this problem is displayed</p>
<pre><code class="lang-auto">RuntimeError: mat1 and mat2 shapes cannot be multiplied (6451x6 and 32x2)
</code></pre>
<p>help me plzzz</p>

randinoo: <p>the problem in layer conv?</p>

csblacknet: <p>There are two problems with this code,</p>
<ul>
<li>You are applying self.fc_out layer two times in your forward function,</li>
</ul>
<pre><code class="lang-auto">x1 = F.relu(self.fc_out(x1))
x1 = self.fc_out(x1)
</code></pre>
<ul>
<li>If after correcting the above, the error comes up it might be because of number of input neurons in self.fc_out. To fix it, comment out self.fc_out layer totally from <em>init</em> and forward, pass images through the model and print the resultant shape, the last dim should be your number of input_neurons, put it back and now you have fixed your self.fc_out.</li>
</ul>

randinoo: <p>Hi csblacknet, thanks for this response. But I didn’t quite understand what I am changing in the</p>
<p>code</p>

randinoo: <p>how do i change my code?</p>

randinoo: <p>help me plzz!! <img src="https://discuss.pytorch.org/images/emoji/apple/slightly_smiling_face.png?v=9" title=":slightly_smiling_face:" class="emoji" alt=":slightly_smiling_face:"></p>

csblacknet: <p>Try this one, the correct code is here,</p><aside class="onebox allowlistedgeneric">
  <header class="source">
      <img src="https://colab.research.google.com/img/favicon.ico?vrz=colab-20201222-085609-RC00_348636243" class="site-icon" width="16" height="16">
      <a href="https://colab.research.google.com/drive/1yv6btC0_RZi2rzGcuVcTk0axiC6RpFHR?usp=sharing" target="_blank" rel="noopener nofollow ugc">colab.research.google.com</a>
  </header>
  <article class="onebox-body">
    <img src="https://colab.research.google.com/img/colab_favicon_256px.png" class="thumbnail onebox-avatar" width="60" height="60">

<h3><a href="https://colab.research.google.com/drive/1yv6btC0_RZi2rzGcuVcTk0axiC6RpFHR?usp=sharing" target="_blank" rel="noopener nofollow ugc">Google Colaboratory</a></h3>



  </article>
  <div class="onebox-metadata">
    
    
  </div>
  <div style="clear: both"></div>
</aside>


randinoo: <p>thanks csblacknet  <img src="https://discuss.pytorch.org/images/emoji/apple/slightly_smiling_face.png?v=9" title=":slightly_smiling_face:" class="emoji" alt=":slightly_smiling_face:"></p>

randinoo: <p>i will test it <img src="https://discuss.pytorch.org/images/emoji/apple/slightly_smiling_face.png?v=9" title=":slightly_smiling_face:" class="emoji" alt=":slightly_smiling_face:"></p>

randinoo: <p>CSblacknet how to display the final image when i do the test and train?</p>