-
Notifications
You must be signed in to change notification settings - Fork 7.1k
ToTensor cannot handle PIL Image with mode '1' #371
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 faced the same problem with image mode 'F'.
Error:
|
I have found an ugly workaround:
|
I'm dealing with this issue working with masks for semantic segmentation. For some reason, some of the masks opened by img = torch.ByteTensor(torch.ByteStorage.from_buffer(pic.tobytes())) Since there's no 1-bit tensor, the only solution I can think of is adding another elif pic.mode == '1':
img = torch.ByteTensor(torch.ByteStorage.from_buffer(pic.convert('L').tobytes())) I'll try to make this change and adjust the tests. |
@arthurml in your case, I'd modify the dataset to always convert the masks to mode |
Thank you, @fmassa! That's exactly what I'm doing right now. |
Fixed via #471 |
vision/torchvision/transforms/functional.py
Line 63 in 080b954
If the image's mode is
1
,image.tobytes
is called to convert image to bytes. However, this will return a Tensor object with element size 8x of the original image, and result in RuntimeError.The text was updated successfully, but these errors were encountered: