RuntimeError: size mismatch, m1: [32 x 5184], m2: [400 x 120] at /opt/conda/conda-bld/pytorch_1570910687230/work/aten/src/THC/generic/THCTensorMathBlas.cu:290

MyKindom: <p>I don’t know whats wrong  with my LeNet,I can not understand why it could be wrong</p>
<pre><code class="lang-auto">class LeNet(nn.Module):
    def __init__(self):
        super(LeNet,self).__init__()
        self.conv1=nn.Conv2d(3,6,5)
        self.conv2=nn.Conv2d(6,16,5)
        self.fc1=nn.Linear(16*5*5,120)
        self.fc2=nn.Linear(120,84)
        self.fc3=nn.Linear(84,48)
    def forward(self,x):
        out = F.relu(self.conv1(x))
        out = F.max_pool2d(out, 2)
        out = F.relu(self.conv2(out))
        out = F.max_pool2d(out, 2)
        out = out.view(out.size(0), -1)
        out = F.relu(self.fc1(out))
        out = F.relu(self.fc2(out))
        out = self.fc3(out)
        return x
</code></pre>
<pre><code class="lang-auto">Traceback (most recent call last):
  File "/home/xiu/Desktop/mediacompute/ImageRecognition/main1.py", line 97, in &lt;module&gt;
    main(config)
  File "/home/xiu/Desktop/mediacompute/ImageRecognition/main1.py", line 48, in main
    solver.train()
  File "/home/xiu/Desktop/mediacompute/ImageRecognition/solver.py", line 135, in train
    outputs =self.model(inputs)
  File "/home/xiu/anaconda3/envs/torch1.0/lib/python3.6/site-packages/torch/nn/modules/module.py", line 541, in __call__
    result = self.forward(*input, **kwargs)
  File "/home/xiu/Desktop/mediacompute/ImageRecognition/Lenet.py", line 17, in forward
    out = F.relu(self.fc1(out))
  File "/home/xiu/anaconda3/envs/torch1.0/lib/python3.6/site-packages/torch/nn/modules/module.py", line 541, in __call__
    result = self.forward(*input, **kwargs)
  File "/home/xiu/anaconda3/envs/torch1.0/lib/python3.6/site-packages/torch/nn/modules/linear.py", line 87, in forward
    return F.linear(input, self.weight, self.bias)
  File "/home/xiu/anaconda3/envs/torch1.0/lib/python3.6/site-packages/torch/nn/functional.py", line 1370, in linear
    ret = torch.addmm(bias, input, weight.t())
RuntimeError: size mismatch, m1: [32 x 5184], m2: [400 x 120] at /opt/conda/conda-bld/pytorch_1570910687230/work/aten/src/THC/generic/THCTensorMathBlas.cu:290
</code></pre>

ptrblck: <p>It seems the flattened output of <code>self.conv2</code> and <code>F.max_pool</code> seems to be <code>[batch_size, 5184]</code>, while <code>self.fc1</code> expects an input of <code>[batch_size, 400]</code>.<br>
Which input size are you using?</p>

junaidtariq_tariq: <p>Hy sir am getting same type of error and the error is<br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/b/5/b598c38741a5f8dc3189a66135353c022271af36.png" data-download-href="https://discuss.pytorch.org/uploads/default/b598c38741a5f8dc3189a66135353c022271af36" title="erro"><img src="https://discuss.pytorch.org/uploads/default/original/3X/b/5/b598c38741a5f8dc3189a66135353c022271af36.png" alt="erro" data-base62-sha1="pUtIsk94cMv8asQFlE0XLrXCuTc" width="690" height="37" data-dominant-color="FAF6F6"><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">erro</span><span class="informations">1298×70 3.24 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> i cannot be able to understand this that why it is occuring?<br>
Or either i changed the num of workers and batch size is it due to that one? kindly guide me how to solve it.</p>

junaidtariq_tariq: <p>And the relevent part of the code is<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/b/2/b2ad7ea5f75202da50726cc2d01af83b2fa107bd.png" data-download-href="https://discuss.pytorch.org/uploads/default/b2ad7ea5f75202da50726cc2d01af83b2fa107bd" title="parser"><img src="https://discuss.pytorch.org/uploads/default/original/3X/b/2/b2ad7ea5f75202da50726cc2d01af83b2fa107bd.png" alt="parser" data-base62-sha1="puEHqzY2QKnVJMBdKaN9aTUEgS9" width="690" height="322" data-dominant-color="EDF0F3"><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">parser</span><span class="informations">960×448 16.4 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: <p>Could you post your model definition as well as the input shapes?<br>
Please post the code by wrapping it into three backticks ``` instead of pictures, as this is easier to debug.</p>

junaidtariq_tariq: <p>hy sir actually i gave three features in my original model but am trying to update it in one feature but its giving this error wich i posted kindly guide me that how can i post model and training file so that you can guide me?</p>

junaidtariq_tariq: <p>Moreover sir i cant be able to upload the model because here one can just upload the jpg kindly guide me how can i upload my model and the new one so that you may help me to debug it</p>