pytorch报错:UserWarning: invalid index of a 0-dim tensor. This will be an error in PyTorch 0.5.。。原因

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/xckkcxxck/article/details/82978963

UserWarning: invalid index of a 0-dim tensor. This will be an error in PyTorch 0.5. Use tensor.item() to convert a 0-dim tensor to a Python number

当报这个错的一般会有两个原因,一个是这种写法:

loss.data[0]   

应该改成loss.item()

还有就是这种写法:

im = Variable(im.cuda(),volatile=True)

应该改成im = Variable(im.cuda()) 

猜你喜欢

转载自blog.csdn.net/xckkcxxck/article/details/82978963