UserWarning: invalid index of a 0-dim tensor.
UserWarning: invalid index of a 0-dim tensor. This will be an error in PyTorch 0.5. Use tensor.item() to convert a 0-dim tensor to a Python number
.format(epoch+1, num_epochs, loss.data[0]))
将loss.data[0] 改为loss.item()
本文探讨了PyTorch中常见的警告与错误,特别是关于0维张量的无效索引问题,这在PyTorch0.5版本中将被视为错误。文章详细解释了如何通过使用.tensor.item()方法将0维张量转换为Python数字,从而解决这一问题。
4963

被折叠的 条评论
为什么被折叠?



