RuntimeError: The size of tensor a (64) must match the size of tensor b (7) at non-singleton dimension 1

I get the following Error

The function:

def test_accuracy(model, test_loader):
acc = 0.0
total = 0.0

with torch.no_grad():
    for data in test_loader:
        images, labels = data
        images ='cuda'))
        labels ='cuda'))
        # run the model on the test set to predict labels
        outputs = model(images)
        # the label with the highest energy will be our prediction
        _, predicted = torch.max(, 1)
        total += labels.size(0)
        acc += (predicted == labels).sum().item()

# compute the accuracy over all test images
acc = (100 * acc / total)
return (acc)

I would really appreciate your help,
thank you in advance


I would suggest printing tensor.shape in before the operations and see if there is any apparent size mismatch.
Also, it will be helpful if you give the line number of the error.