首页 > 编程语言 > 详细

报错:invalid index of a 0-dim tensor. Use tensor.item() to convert a 0-dim tensor to a Python number

时间:2019-11-04 12:23:26      阅读:1043      评论:0      收藏:0      [点我收藏+]

报错:invalid index of a 0-dim tensor. Use tensor.item() to convert a 0-dim tensor to a Python number

解决方法:

That‘s because in PyTorch>=0.5, the index of 0-dim tensor is invalid. The master branch is designed for PyTorch 0.4.1, loss_val.data[0] works well.

Try to change

total_loss += loss_val.data[0]
loss_values = [v.data[0] for v in losses]

to

total_loss += loss_val.data
loss_values = [v.data for v in losses]

might fix the problem.

 

报错:invalid index of a 0-dim tensor. Use tensor.item() to convert a 0-dim tensor to a Python number

原文:https://www.cnblogs.com/Bella2017/p/11791186.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!