RuntimeError: mat1 and mat2 shapes cannot be multiplied

I get the error below

RuntimeError: mat1 and mat2 shapes cannot be multiplied (1x256 and 3x256)

for this line of my code x = F.relu(self.linear1(c))
from snippet below:

class Test(nn.Module):
    def __init__(self, input_size, hidden_size, output_size):
        super(Test, self).__init__()
        self.linear1 = nn.Linear(input_size, hidden_size)
        self.linear2 = nn.Linear(hidden_size, hidden_size)
        self.linear3 = nn.Linear(hidden_size, output_size)

    def forward(self, c):
        x = F.relu(self.linear1(c))
        x = F.relu(self.linear2(x))
        x = torch.tanh(self.linear3(x))

        return x

Can anyone give me a clue how to solve this?

I believe this is due to the dimensions of the tensors in the linear calculation – c.view(c.size(0),-1) looks to be instantiating a (1x256 tensor) tensor. If you want to keep the input_size, hidden_size as 3 and 256 respectively, you will need to modify the view function so that the tensor is (256x1)