Python IndexError: invalid index of a 0-dim tensor. Use `tensor.item()` in Python or `tensor.item()` in C++ to convert a 0-dim tensor to a number

When the error was reported, it was because of loss.data[0]

 

After modification, it becomes loss.item()

Read More:

Leave a Reply

Your email address will not be published. Required fields are marked *