Is there a reason for torchvision.transforms.ToTensor() to convert an nd.array to a LongTensor instead of FloatTensor when the dtype of the array is int64?It took me a while to figure out why my dataloader was returning LongTensors for target AND x. When i convert my image array into float64, everything works as expected. Is there an expectation that image arrays should be normalized and thus have to be float64?

Thanks, sorry if this is something obvious I am missing.

int64 is equivalent to long. Therefore the ToTensor() transform simply returns a tensor of the same dtype as the given array. If you convert your image to float64 the returned type should be a DoubleTensor. If you don’t need the double precision I would recommend using float32 which leads to FloatTensor as return type. They are much more efficient in computation, use less memory and you don’t have to convert your model to double since weight and bias are usually FloatTensors as well.

2 Likes