Regarding size mismatch issue

Hi All , I’m a beginner in Pytorch , ran into an issue couldnt understand what’s going wrong…

I have the following model architecture

class Fashion_MNIST_NeuralNet(nn.Module) :
  
  def __init__ (self) :
    
    #Calling the module class for the reason mentioned above...
    super(Fashion_MNIST_NeuralNet , self).__init__()
    self.fMnistConv1 = nn.Conv2d(in_channels = 1 , out_channels = 6 , kernel_size = 5)
    self.fMnistConv2 = nn.Conv2d(in_channels = 6 , out_channels = 12 , kernel_size = 5)
    
    #adding fully connected layers
    
    self.fMnist_fc1 = nn.Linear(12*4*4 , 120)
    self.fMnist_fc2 = nn.Linear(120 , 84)
    self.fMnist_fc3 = nn.Linear(84 , 10)
    
    
    
  def forward(self,x) :
    #appplying max_pool2d layer to reduce the dimensionality of the matrix obtained from convolutions..
    # Max pooling over a (2, 2) window
    x = F.max_pool2d(F.relu(self.fMnistConv1(x)), (2, 2))
    # If the size is a square you can only specify a single number
    x = F.max_pool2d(F.relu(self.fMnistConv2(x)), 2)
    print("===x===1" , x.shape)
    x = x.view(-1 , self.get_num_features(x))
    print("==View==" , x.size())
    x = F.relu(self.fMnist_fc1(x))
    x = F.relu(self.fMnist_fc1(x))
    x = self.fMnist_fc3(x)
    return x
   
    
    
  def get_num_features(self ,x):
    print('Number of Features found=====' , x.shape)
    size = x.size()[1:]
    print("Size" , size)
    num_features = 1
    for s in size:
      num_features*=s
    
    print("==Mult==" , num_features)
    return num_features
    
fn = Fashion_MNIST_NeuralNet()
fn(torch.randn([1,1,28,28]))
Error : 
**size mismatch, m1: [1 x 120], m2: [192 x 120] at /pytorch/aten/src/TH/generic/THTensorMath.cpp:940**

Please help me with this

Thanks in advance!!

You have a typo. This should be:

x = F.relu(self.fMnist_fc2(x))

Yea , later i got to know
Shoot me:smiley:

Anyway,Thanks!