报错原因分析:

train_loss += loss.data[0] 是pytorch0.3.1版本代码,在0.4-0.5版本的pytorch会出现警告,不会报错,但是0.5版本以上的pytorch就会报错,总的来说是版本更新问题.

解决方法:

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

 

 

将datra[0]换成item() 即可

 

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

 

 

相关文章:

  • 2021-08-08
  • 2021-12-20
  • 2021-11-27
  • 2022-12-23
  • 2021-12-16
  • 2021-11-30
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-08-26
  • 2022-12-23
  • 2021-03-28
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案