Tested the documentation example of nn.CrossEntropyLoss. It doesn't seem to work.
loss = nn.CrossEntropyLoss()
input = torch.randn(3, 5, requires_grad=True)
target = torch.randn(3, 5).softmax(dim=1)
output = loss(input, target)
print(output)
error:
RuntimeError: 1D target tensor expected, multi-target not supported
CodePudding user response:
You might need to upgrade your torch version.
pip install torch --upgrade