I am trying to use a neural network to do regression on a large 5D dataset, however to try and get a working neural network first i have setup a random set of data points to try with. However I am running into this error and I am not sure why.
Error Code:
predicted = model(data.to(device))
File “C:\Users\Owner\anaconda3\lib\site-packages\torch\nn\modules\module.py”, line 1051, in _call_impl
return forward_call(*input, **kwargs)
File “C:\Users\Owner\anaconda3\lib\site-packages\torch\nn\modules\container.py”, line 139, in forward
input = module(input)
File “C:\Users\Owner\anaconda3\lib\site-packages\torch\nn\modules\module.py”, line 1051, in _call_impl
return forward_call(*input, **kwargs)
File “C:\Users\Owner\anaconda3\lib\site-packages\torch\nn\modules\linear.py”, line 96, in forward
return F.linear(input, self.weight, self.bias)
File “C:\Users\Owner\anaconda3\lib\site-packages\torch\nn\functional.py”, line 1847, in linear
return torch._C._nn.linear(input, weight, bias)
RuntimeError: mat1 and mat2 shapes cannot be multiplied (1x64 and 1x200)
Process finished with exit code 1
I was roughly following a tutorial I found online: Regression with Neural Networks in PyTorch | by Ben Phillips | Medium 1
My Code:
trial_x_data = np.arange(100)
trial_y_data = trial_x_data ** 2 + 5 

model = torch.nn.Sequential(
        torch.nn.Linear(1, 200),
        torch.nn.LeakyReLU(),
        torch.nn.Linear(200, 100),
        torch.nn.LeakyReLU(),
        torch.nn.Linear(100, 1),
    ).to(device)

optimiser = torch.optim.Adam(model.parameters(), lr=0.01)
loss_func = torch.nn.MSELoss()


Batch_size = 64
Max_Epoch = 500

trial_x_data, trial_y_data = torch.tensor(trial_x_data), torch.tensor(trial_y_data)
torch_dataset = Data.TensorDataset(trial_x_data, trial_y_data)

loader = Data.DataLoader(dataset=torch_dataset, batch_size=Batch_size, shuffle=True)

loss_logger = []

for epoch in range(Max_Epoch):
    for idx, (data, expected) in enumerate(loader):
        predicted = model(data.to(device))
        loss = loss_func(predicted, expected.to(device))

        optimiser.zero_grad()
        loss.backward()
        optimiser.step()

        loss_logger.append(loss.item())

    print("Epoch: [%d/%d]" % (epoch + 1, Max_Epoch))

Any help would be greatly appreciated