"RuntimeError: mat1 dim 1 must match mat2 dim 0" PyTorch
I've been trying to build a simple neural network with linear layers:
class Net(nn.Module):
    def __init__(self):
        super(Net, self).__init__()
        
        self.lin1 = nn.Linear(64 * 1 * 28 * 28, 6)
        self.lin2 = nn.Linear(6, 4)
        self.out = nn.Linear(4, 10)

    def forward(self, x):
        print(x.shape)
        
        x = self.lin1(x)
        x = F.relu(x)
        
        x = self.lin2(x)
        x = F.relu(x)
        
        x = self.out(x)
        x = F.softmax(x)
        
        return x

However I run into the error:

mat1 dim 1 must match mat2 dim 0

for the line
x = self.lin1(x)

I tried flattening x before lin1 or changing the lin1 input size, but nothing worked.
The output of the print statement is:
torch.Size([64, 1, 28, 28])


Problem was solved by flattening (in a different way than i did before) the input.
import torch.nn as nn
import torch.nn.functional as F

class Net(nn.Module):
  def __init__(self):
    super(Net,self).__init__()
    
    self.lin1 = nn.Linear(784,6)
    self.lin2  = nn.Linear(6,4)
    self.out = nn.Linear(4,10)
   

def forward(self,x):
    
    x = torch.flatten(x,start_dim = 1) #This is new
    
    x = self.lin1(x)
    x = F.relu(x)
    
    x = self.lin2(x)
    x = F.relu(x)
    
    x = self.out(x)
    
    return x

