Hello, I am new to pytorch, hope you can help me. Thanks!
My class is a binary class.
For the loss,
criterion = nn.CrossEntropyLoss()
loss = criterion(outputs, y)
The shapes of my output and target are (100L, 2L) and (100L,).
However, if I change to “criterion = nn.BCELoss()”, I got some error,
Traceback (most recent call last):
File “lstm-lzd-gpu.py”, line 111, in
loss = criterion(outputs, y) # cross entropy loss
File “/usr/local/lib/python2.7/dist-packages/torch/nn/modules/module.py”, line 206, in call
result = self.forward(*input, **kwargs)
File “/usr/local/lib/python2.7/dist-packages/torch/nn/modules/loss.py”, line 36, in forward
return backend_fn(self.size_average, weight=self.weight)(input, target)
File “/usr/local/lib/python2.7/dist-packages/torch/nn/_functions/thnn/loss.py”, line 22, in forward
assert input.nelement() == target.nelement()
Can anyone help? Thank you very much.