Skip to content
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

torchvision/transform.py - to_tensor() - return type is not float #317

Closed
junghoon-kang opened this issue Nov 2, 2017 · 2 comments
Closed

Comments

@junghoon-kang
Copy link

junghoon-kang commented Nov 2, 2017

Hello there,

I was using 'I;16' images to train my network and got the following error.
Input type (Short) and weight type (Float) should be the same

And I was wondering if 'I' and 'I;16' PIL image modes should also be converted into FloatTensor when we apply ToTensor() transform to the image.

I am sorry if this was intended.
I thought this was weird because, in to_tensor() method, every PIL image mode except 'I', and 'I;16' gets converted into FloatTensor.

transform.py
from
78: return img
to
78: return img.float()

Thank you in advance for your time! :)

@alykhantejani
Copy link
Contributor

Hi @junghoon-kang,

support for I and I;16 in the ToTensor transform was added in this PR, the use case was for things like MRI images, where conversion from an int32 image to a float32 representation causes information to be lost. It's also important to note that calling ToTensor on I or I;16 images will also do no rescaling of the range of the images.

one work around, if you want float images is to explicitly call .float on the response, or convert your images after conversion to a pil image. These operations can also be made as a transform inside your Compose

@alykhantejani
Copy link
Contributor

Closing this as a wont-fix for now. If you wish to discuss it further please comment on the issue or open a new one :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants