报错的时候,是因为loss.data[0]
修改后变为loss.item()
IndexError: invalid index of a 0-dim tensor. Use `tensor.item()` in Python or `tensor.item<T>()` in C++ to convert a 0-dim tensor to a number
原文:https://www.cnblogs.com/hao-lingguang19/p/14692631.html