Pytorch报错IndexError: invalid index of a 0-dim tensor. Use tensor.item() to convert a 0-dim tensor to
程序员文章站
2024-03-17 11:24:46
...
IndexError Traceback (most recent call last)
<ipython-input-23-4ba7a4acb927> in <module>
19
20 if (epoch+1) % 20 == 0:
---> 21 print('Epoch[{}/{}], loss: {:.6f}'.format(epoch+1, num_epochs, loss.data[0]))
IndexError: invalid index of a 0-dim tensor. Use tensor.item() to convert a 0-dim tensor to a Python number
解决:
将loss.data[0 ] 改成loss.item()
上一篇: 原生js轮播图实现
下一篇: 原生JS 实现放大镜
推荐阅读
-
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