IndexError Traceback (most recent call last)
<ipython-input-23-4ba7a4acb927> in <module>
19
20 if (epoch+1) % 20 == 0:
---> 21 print('Epoch[{}/{}], loss: {:.6f}'.format(epoch+1, num_epochs, loss.data[0]))
IndexError: invalid index of a 0-dim tensor. Use tensor.item() to convert a 0-dim tensor to a Python number
解决:
将loss.data[0 ] 改成loss.item()