IndexError: invalid index of a 0-dim tensor. Use tensor.item() to convert a 0-dim tensor to a Python
程序员文章站
2024-03-17 11:24:34
...
错误截图:
解决办法:
报错原因分析:
train_loss += loss.data[0] 是pytorch0.3.1版本代码
在0.4-0.5版本的pytorch会出现警告,不会报错
但是0.5版本以上的pytorch就会报错
总的来说是版本更新问题.
将原语句:train_loss+=loss.data[0]
修改为:train_loss+=loss.item()
上一篇: 原生js实现放大镜效果
下一篇: Python_文件访问与函数式编程入门
推荐阅读
-
IndexError: invalid index of a 0-dim tensor. Use tensor.item() to convert a 0-dim tensor to a Python
-
invalid index of a 0-dim tensor. Use tensor.item() to convert a 0-dim tensor to a python number
-
IndexError: invalid index of a 0-dim tensor. Use tensor.item() to convert a 0-dim tensor to a Python
-
Pytorch报错IndexError: invalid index of a 0-dim tensor. Use tensor.item() to convert a 0-dim tensor to
-
解决IndexError: invalid index of a 0-dim tensor. Use tensor.item() to convert a 0-dim tensor to a Pyth
-
IndexError: invalid index of a 0-dim tensor. Use tensor.item() to convert a 0-dim tensor to a Python