Getting error IndexError: invalid index of a 0-dim tensor. Use tensor.item() to convert a 0-dim tensor to a Python numbe

Hi All,

Can someone please help with the below error.
I am using Python 2.7 in Google colab with Pytorch 1.0.1.
I guess it is version issue, but i cannot find the exact issue.
The code is very long so I can’t paste here, so I have given my Github link

I am getting the below error

IndexError: invalid index of a 0-dim tensor. Use tensor.item() to convert a 0-dim tensor to a Python number

Literally follow the instructions. You write loss.data[0] and need loss.item() instead. It’s been a long while since loss.data[0] was a good thing to write, see the 0.4 migration guide on how to update ancient (:wink: ) code.

Best regards

Thomas

2 Likes

Thanks tom so much for your help