pytorch 交叉熵损失计算时报错了:
1D target tensor expected, multi-target not supported
if __name__ == '__main__':
import torch
loss_fn = torch.nn.CrossEntropyLoss(reduce=True, weight=None)
input = torch.Tensor([[0, 0, 0],[ 1, 2, 4],[0.1,0.2,0.3]])
target = torch.LongTensor([[1],[5],[2]])
print(input.size(),target.size())
loss = loss_fn(input, target)
print(loss)
报错:
D:\ProgramData\Miniconda3\python.exe G:/project/reid/halonet-pytorch/halonet_pytorch/__init__.py
D:\ProgramData\Miniconda3\lib\site-packages\torch\nn\_reduction.py:44: UserWarning: size_average and reduce args will be deprecated, please use reduction='mean' instead.
warnings.warn(warning.format(ret))
torch.Size([3, 3]) torch.Size([3, 1])
Traceback (most recent call last):
File "G:/project/reid/halonet-pytorch/halonet_pytorch/__i