IndexError: invalid index of a 0-dim tensor.解决办法

转自:https://blog.csdn.net/weixin_41797117/article/details/80237179

运行PSM-Net的finetune.py时报错如下:

return loss.data[0]
IndexError: invalid index of a 0-dim tensor. Use tensor.item() to convert a 0-dim tensor to a Python number

修改方法如下:

#原语句:
train_loss+=loss.data[0]
#修改后:
train_loss+=loss.item()

就ok啦

猜你喜欢

转载自blog.csdn.net/qq_40710634/article/details/86548941
今日推荐