RuntimeError: 0D or 1D target tensor expected, multi-target not supported
报错截图如下:
出错的相关代码:
loss = nn.CrossEntropyLoss()(output.narrow(0, 0, data_source.size(0)), label_source)
出错原因:第二个参数应该降维
更正:(在label_source后方添加函数.squeeze())
loss = nn.CrossEntropyLoss()(output.narrow(0, 0, data_source.size(0)), label_source.squeeze(dim=1))
本段代码更正后报错截图:
那就在此段代码前面加上:
label_source =label_source.to(torch.int64)
成功运行