The size of tensor a (70) must match the size of tensor b (10) at non-singleton dimension 0

Viewed 137

I'm trying to put a tensor at the training model, but it's returning this error:

Exception has occurred: RuntimeError
The size of tensor a (70) must match the size of tensor b (10) at non-singleton dimension 0

I'd try to change the criterion, but the error persists

Importantly Code: training_input = torch.FloatTensor(x[:70]) training_output = torch.FloatTensor(y[:70])

input_size = training_input.size()[1]
hidden_size = 10
model = Net(input_size, hidden_size)

criterion = torch.nn.MSELoss()

optimizer = torch.optim.SGD(model.parameters(), 0.09, 0.03)

for param in model.parameters():
    pass

model.train()
epochs = 100
errors = []
for epoch in range(epochs):
  optimizer.zero_grad()
  # Fazer o forward
  y_pred = model(training_input)
  loss = criterion(y_pred.squeeze(), training_output)
  errors.append(loss.item())
  if epoch % 1000 == 0:
    print(f'Epoch: {epoch}. Train loss: {loss.item()}.')
  loss.backward()
  optimizer.step()
0 Answers
Related