IndexError: invalid index of a 0-dim tensor. Use tensor.item() to convert a 0-dim tensor to a Python
程序员文章站
2024-03-17 11:29:16
...
报错原因分析:
train_loss += loss.data[0] 是旧版本的Pytorch版本代码,在Pytorch0.4-0.5中会出现警告,不会报错,
在Pytorch0.5版本以上会报错
IndexError: invalid index of a 0-dim tensor. Use tensor.item() to convert a 0-dim tensor to a Python
解决方法:
可以将:train_loss+=loss.data[0] 修改为:train_loss+=loss.item()
上一篇: 前端基础知识——CSS
推荐阅读
-
IndexError: invalid index of a 0-dim tensor. Use tensor.item() to convert a 0-dim tensor to a 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