hello i’m facing the following error when calculating accuracy against MSELoss function. Following is my code and shapes.
RuntimeError: The size of tensor a (2) must match the size of tensor b (3) at non-singleton dimension 1
    input_var = Variable(data.float())
    target_var = Variable(target.float())

    optimizer.zero_grad()

    output = model(input_var)

    loss = criterion(output, target_var)
    _, preds = torch.max(output.data, 1)
    dice =  dice_coef(output,target)

    loss.backward()


    optimizer.step()

    train_loss += loss.item()*data.size(0)
    train_metric =  dice*data.size(0)

    total_train += target_var.nelement()
    correct_train += preds.eq(target_var.data).sum().item()
    train_acc = 100 * correct_train / total_train
    print("train Acc ",train_acc)

Shapes are
target shape  torch.Size([2, 3, 512, 512])
Output shape  torch.Size([2, 3, 512, 512])
Preds shape  torch.Size([2, 512, 512])