Hi Guys,
Could anyone help me solve this error ? Writing pytorch code for the first time for my image classification.
for epoch in range(1, 31):
train_loss, valid_loss = [], []
model.train()
for data, target in train_loader:
print(data,target)
optimizer.zero_grad()
output = model(data)
print(output.shape)
print(target.shape)
loss = loss_function(output, target)
loss.backward()
optimizer.step()
train_loss.append(loss.item())
RuntimeError: invalid argument 3: only batches of spatial targets supported (3D tensors) but got targets of dimension: 1 at /pytorch/aten/src/THNN/generic/SpatialClassNLLCriterion.c:59 q
Its failing at the loss_function. I have printed the shape of my arguments for the loss_functions.
Output : torch.Size([10, 16, 56, 2])
Target : torch.Size([10])
Batchsize is 10