RuntimeError: Could not infer dtype of numpy.int64

(Wangjiawei) #1

I have a line of code: label_tensor = torch.tensor(self.label [item]).long ()when I train on Google colab, it’s not wrong, but when I train on another server, it gets an error. I am very confused. How to solve this problem?

#2

Are you using the same PyTorch version in both setups?
Also, could you try to use torch.from_numpy(self.label[item])?

(Wangjiawei) #3

Thank you very much! I modify it to label_tensor = torch.tensor(int(self.label [item])).long (),then it is correct.