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

Add support for CMYK -> RGB in decode_jpeg() #6538

Closed
NicolasHug opened this issue Sep 5, 2022 · 1 comment · Fixed by #7741
Closed

Add support for CMYK -> RGB in decode_jpeg() #6538

NicolasHug opened this issue Sep 5, 2022 · 1 comment · Fixed by #7741

Comments

@NicolasHug
Copy link
Member

NicolasHug commented Sep 5, 2022

Asking for a CYMK jpeg file to be converted to RGB by decode_jpeg() currently results in the following error:

from torchvision.io import read_file, decode_jpeg, ImageReadMode

path = "test/assets/fakedata/logos/cmyk_pytorch.jpg"
decode_jpeg(read_file(path), mode=ImageReadMode.RGB)  # ImageReadMode.UNCHANGED would work
RuntimeError: Unsupported color conversion request

This is an important feature to support because the ImageNet dataset has ~20 CMYK images, which means we currently cannot decode ImageNet files with decode_jpeg(): we have to rely on PIL.

According to this comment in our code there should be a way to support this:

/*
* Libjpeg does not support converting from CMYK to grayscale etc. There
* is a way to do this but it involves converting it manually to RGB:
* https://github.com/tensorflow/tensorflow/blob/86871065265b04e0db8ca360c046421efb2bdeb4/tensorflow/core/lib/jpeg/jpeg_mem.cc#L284-L313
*/

@tmabraham
Copy link

bumping this, had this issue with imagenet just now

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

Successfully merging a pull request may close this issue.

2 participants