Traceback (most recent call last):
File “C:/Users/zzj/Desktop/zzj_battery/venv/test.py”, line 84, in
print(‘Epoch: {}, Loss: {:.5f}’.format(e + 1, loss.data[0]))
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
解决方法
print('Epoch: {}, Loss: {:.5f}'.format(e + 1, loss.data[0]))
将loss.data[0] 改为loss.item()