-
Notifications
You must be signed in to change notification settings - Fork 7k
transforms.ToTensor() for numpy float array in the range of [0.0, 255.0] #546
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I think I'll be creating an |
or create a universal API to directly read an image in a default format, given the filepath? I am not sure if this will help. I feel we (users) are using different packages to read (PIL, scipy, skimage, opencv etc) images. Hence we have more cases to cover. |
@fmassa This issue really confused me as a beginner in pytorch :) What if we change line 57-62 with: img = torch.from_numpy(pic.transpose((2, 0, 1)))
# backward compatibility
if isinstance(img, torch.ByteTensor):
return img.float().div(255)
else:
img = img.float()
if torch.max(img)<=1.0:
return img
else:
return img.div(255)
|
@ekagra-ranjan we could try doing something like that, but the cost of I think the underlying issue is that |
I found the same bug while loading the moving mnist data. The input is not float but the same bug still exists that the ToTensor() function does not transform the values from 0 to 255 to 0 to 1, it also does not give an any warning, so I found it while debugging my own neural net. |
@Melika-Ayoughi I'm not sure there is a clean solution if we keep the current approach. This is something that I believe should be completely redesigned in my opinion. |
I had come across a debugging scenario where the ToTensor() didn't convert the numpy float array in the range of [0.0, 255.0] to the range [0.0 to 1.0] due to following lines:
https://github.com/pytorch/vision/blob/master/torchvision/transforms/functional.py#L50-L53
Basically, this API assumes that all the float arrays will already be in range [0.0 to 1.0].
Do you think we have to change this behavior?
The text was updated successfully, but these errors were encountered: