Bootstrap

RuntimeError: 0D or 1D target tensor expected, multi-target not supported解决

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))

;