admin管理员组

文章数量:1122850

RuntimeError: 0D or 1D target tensor expected, multi

loss_class = nn.NLLLoss()

loss_class_test = loss_class(class_prd,labels)

报错:RuntimeError: 0D or 1D target tensor expected, multi-target not supported

print class_prd.shape, labels.shape 发现分别为

torch.Size([64, 3]) #三分类问题

torch.Size([64, 1])

labels.shape维度应为[64]

解决:loss_class_test = loss_class(class_prd,labels.squeeze(dim=1))

本文标签: RuntimeError 0D or 1D target tensor expectedMulti