"RuntimeError: size mismatch, got 10, 10x10,1"

This is probably a very basic question, but here I go anyway.

I’m trying to create a DeepNet of a series of Linear layers. Here is a class called ‘NeuralNet’:

class NeuralNet(nn.Module):
    

        
    def __init__(self, weights, bias):
        
        super(NeuralNet, self).__init__()
        
        self.weights = weights
        self.bias = bias
        
        self.nn = nn.Sequential(
            nn.Linear(10, 10),
            nn.ReLU(inplace = True),
            nn.Linear(10, 10),
            nn.ReLU(inplace = True),
            nn.Linear(10, 10),
            nn.ReLU(inplace = True),
            nn.Linear(10, 3),
            nn.ReLU(inplace = True),
        )



    def forward(self, a, b, c):
        
        a = torch.flatten(a)
        b = torch.flatten(b)
        c = torch.flatten(c)
        
        print(a.shape, b.shape, c.shape)
        
        a1 = self.nn(a)
        b1 = self.nn(b)
        c1 = self.nn(c)
        
        a1 = self.nn(s1)
        b1 = self.nn(b1)
        c1 = self.nn(ep1)
        
        a1 = self.nn(a1)
        b1 = self.nn(b1)
        c1 = self.nn(c1)
        
        a1 = self.nn(a1)
        b1 = self.nn(b1)
        c1 = self.nn(c1)
        
        y = torch.cat((a1, b1, c1))

        return y


The randomized tensors a, b, c all have a shape of (10, 1).

I’ve figured the issue out. It turns out that you have to call the neural net just once in the method forward. Sorry for the trouble.

Thanks.