I am working on a binary classification problem. My batch_y
and y_pred
do not have the same shape, yet I get no warnings/errors when I compute the loss with nn.BCELoss(y_pred, batch_y)
:
batch_y.shape: torch.Size([10, 1, 1])
tensor([[[0.]],
[[1.]],
[[0.]],
[[0.]],
[[0.]],
[[1.]],
[[1.]],
[[1.]],
[[1.]],
[[0.]]], device='cuda:0')
y_pred.shape: torch.Size([10, 1])
tensor([[0.5170],
[0.5114],
[0.5103],
[0.4971],
[0.4974],
[0.5024],
[0.5008],
[0.4954],
[0.5035],
[0.4987]], device='cuda:0', grad_fn=<SigmoidBackward>)
A more extreme version of this occurs when I do classification with three classes instead of two. Here again, I get no warnings/errors when I compute the loss with nn.CrossEntropyLoss(y_pred, batch_y)
:
batch_y.shape: torch.Size([3])
tensor([1, 2, 0], device='cuda:0')
y_pred.shape: torch.Size([3, 3])
tensor([[-0.0718, -0.1237, -0.1143],
[-0.0757, -0.1294, -0.1150],
[-0.0792, -0.1128, -0.1106]],
device='cuda:0', grad_fn=<ThAddmmBackward>)
Any ideas why this might be the case? Could this potentially (negatively) impact training?