How to solve RuntimeError size mismatch

RuntimeError Traceback (most recent call last)
in ()
7 # Forward + Backward + Optimize
8 optimizer.zero_grad()
----> 9 outputs = model(images)
10 loss = criterion(outputs, labels)
11 loss.backward()

~\Anaconda3\lib\site-packages\torch\nn\modules\module.py in call(self, *input, **kwargs)
475 result = self._slow_forward(*input, **kwargs)
476 else:
–> 477 result = self.forward(*input, **kwargs)
478 for hook in self._forward_hooks.values():
479 hook_result = hook(self, input, result)

in forward(self, x)
13 out = self.Maxpool(self.relu(self.cov2(out)))
14 out = out.view(n_size,-1)
—> 15 out = self.fc(out)
16
17 return out

~\Anaconda3\lib\site-packages\torch\nn\modules\module.py in call(self, *input, **kwargs)
475 result = self._slow_forward(*input, **kwargs)
476 else:
–> 477 result = self.forward(*input, **kwargs)
478 for hook in self._forward_hooks.values():
479 hook_result = hook(self, input, result)

~\Anaconda3\lib\site-packages\torch\nn\modules\linear.py in forward(self, input)
53
54 def forward(self, input):
—> 55 return F.linear(input, self.weight, self.bias)
56
57 def extra_repr(self):

~\Anaconda3\lib\site-packages\torch\nn\functional.py in linear(input, weight, bias)
1022 if input.dim() == 2 and bias is not None:
1023 # fused op is marginally faster
-> 1024 return torch.addmm(bias, input, weight.t())
1025
1026 output = input.matmul(weight.t())

RuntimeError: size mismatch, m1: [100 x 512], m2: [1568 x 10] at c:\programdata\miniconda3\conda-bld\pytorch_1532504087133\work\aten\src\th\generic/THTensorMath.cpp:2070

in_feature of torch.nn.Linear might mismatch to the feature size of input.

class cnn_model(nn.Module):
def init(self):
super(cnn_model,self).init()
self.cov1 = nn.Conv2d(1,16,kernel_size=5)
self.cov2 = nn.Conv2d(16,32, kernel_size = 5)
self.fc = nn.Linear(1568,10)
self.relu = nn.ReLU()
self.Maxpool = nn.MaxPool2d(kernel_size = 2)

def forward(self, x):
    n_size = x.size(0)
    out = self.Maxpool(self.relu(self.cov1(x)))
    out = self.Maxpool(self.relu(self.cov2(out)))
    out = out.view(n_size,-1)
    out = self.fc(out)
    
    return out

If the size of images is correct, you should use the following setting for the Linear layer.

self.fc = nn.Linear(512,10)

sure it work, can you give me explanation on how to know the value, i was working with mnist fashion dataset which i think is 28*28 gray scale

As 4*4*50 in the MNIST example, 4*4*32 = 512.