A question about torchvision.transforms.ToTensor

Hello Everyone.
I have a question about torchvision.transforms.ToTensor.
In the Documentation of this Command has said that :
Converts a PIL Image or numpy.ndarray (H x W x C) in the range [0, 255] to a torch.FloatTensor of shape (C x H x W) in the range [0.0, 1.0].

My question is How to this command scale the values in the range [0, 255] to the range of [0.0, 1.0] ?

You can find the code here. Basically, you divide by 255.

1 Like

Thanks a lot for your answer.

What if I want to convert an image into a tensor but not in the range [0, 1]? Is there any solution to that?

You could most likely use torch.from_numpy, as most libraries load images as numpy arrays.