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.io.read_image support processing EXIF information in JPEG file #7977

Closed
kero-ly opened this issue Sep 19, 2023 · 7 comments · Fixed by #8279
Closed

torchvision.io.read_image support processing EXIF information in JPEG file #7977

kero-ly opened this issue Sep 19, 2023 · 7 comments · Fixed by #8279

Comments

@kero-ly
Copy link

kero-ly commented Sep 19, 2023

🚀 The feature

In #7947, I found that torchvision.io.read_image will not process the EXIF information in JPEG file.
I'm wondering if PyTorch will consider supporting processing EXIF information in the future versions?

Motivation, pitch

I have millions of images in my project, some JPEG files have orientation tag in EXIF information. If I use torchvision.io.read_image to read them directly, the model accuracy seems not good enough since some images have the wrong orientation.

I want to ask if PyTorch will provide a convenient way to process the orientation tag?

Alternatives

No response

Additional context

No response

@NicolasHug
Copy link
Member

Thanks for opening this issue @kero-ly .

From #7947 (comment) it looks like PIL and torchvision provide the same output dimensions (they agree on H and W, despite different conventions) and seem to ignore the EXIF information.

I guess we could add support for that... as a bug fix? But the fact that PIL ignores it as well makes me wonder whether there's something we're missing here. Any thought @pmeier @vfdev-5 ?

@pmeier
Copy link
Collaborator

pmeier commented Sep 25, 2023

the fact that PIL ignores it as well makes me wonder whether there's something we're missing here

Maybe this is intentional on PILs side? If so, we should not "fix" this behavior on our side since we align with PIL. I'm ok with adding a flag like process_exif: bool = False to read_image to enable this if the user wants it.

@Zekrom-7780
Copy link

@pmeier @NicolasHug , can I try to work on this? (i.e. adding a flag like process_exif: bool = False to read_image to enable this if the user wants it ?)

@pmeier
Copy link
Collaborator

pmeier commented Nov 7, 2023

Sure, go ahead @Zekrom-7780!

@gau-nernst
Copy link
Contributor

Hello, are there updates regarding this feature? I recently switched to torchvision.io.read_image() from PIL to take advantage of libjpeg-turbo (making PIL to use libjpeg-turbo instead of libjpeg is not so straightforward). With PIL, I could use ImageOps.exif_transpose() to apply EXIF orientation info, but this is currently not possible with torchvision. This feature would be very useful for me.
FYI, OpenCV will apply EXIF orientation by default.

@vfdev-5
Copy link
Collaborator

vfdev-5 commented Jan 29, 2024

@gau-nernst @kero-ly I'll be working on this feature, could you please provide few examples with exif data with defined orientation to test on. Thanks.

@vfdev-5 vfdev-5 self-assigned this Jan 29, 2024
@gau-nernst
Copy link
Contributor

@vfdev-5 I found some samples here: https://github.com/recurser/exif-orientation-examples

For example, the one below needs to be rotated clock-wise.

wget https://raw.githubusercontent.com/recurser/exif-orientation-examples/master/Landscape_6.jpg

For testing against PIL, I use this

from PIL import Image, ImageOps

img = Image.open("path.jpg")
img = ImageOps.exif_transpose(img)

My browser (Edge) also seems to display all the samples from https://github.com/recurser/exif-orientation-examples correctly.

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

Successfully merging a pull request may close this issue.

6 participants