Skip to content
Advertisement

IndexError: tensors used as indices must be long, byte or bool tensors

I am getting this error only during the testing phase, but I do not face any problem in the training and validation phase.

JavaScript

I get this error for the last line in the given code snippet.

The code snippet looks like the one below,

JavaScript

The “lab” is a tensor value and prints out the range in such a way,

JavaScript

(Note*: the length of this lab tensor can be of length ‘n’ based on the value of ElementsPerClass)

Advertisement

Answer

Yes it works when I provide a dtype=long to the label tensor and leaving rest of the tensors with default dtypes. thanks!

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement