[go: nahoru, domu]

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

Request: webp support #57647

Open
Lunatik00 opened this issue Sep 8, 2022 · 10 comments
Open

Request: webp support #57647

Lunatik00 opened this issue Sep 8, 2022 · 10 comments
Assignees
Labels
comp:apis Highlevel API related issues stat:awaiting tensorflower Status - Awaiting response from tensorflower TF 2.10 type:feature Feature requests

Comments

@Lunatik00
Copy link
Lunatik00 commented Sep 8, 2022
Click to expand!

Issue Type

Feature Request

Source

binary

Tensorflow Version

2.10.0

Custom Code

No

OS Platform and Distribution

Archlinux

Mobile device

No response

Python version

3.9

Bazel version

No response

GCC/Compiler version

No response

CUDA/cuDNN version

No response

GPU model and memory

No response

Current Behaviour?

The .webp image format is not available for tf.keras.preprocessing.image.ImageDataGenerator().flow_from_directory()

The use of the .webp format is at least desirable, due to their lower size and better compression over .jpeg and the fact it can be loseless like .png while keeping the lower file size

Standalone code to reproduce the issue

For what i see there is no support currently for .webp, not even in the io module. (I wrote this part here because it ask for something even if I am just making a feature request)

Relevant log output

No response

@google-ml-butler google-ml-butler bot added the type:feature Feature requests label Sep 8, 2022
@tiruk007 tiruk007 added TF 2.10 comp:keras Keras related issues labels Sep 12, 2022
@tiruk007
Copy link
Contributor
tiruk007 commented Sep 12, 2022

@Lunatik00
In tf version 2.10, tf.keras.preprocessing.image.ImageDataGenerator() is deprecated, please use tf.keras.utils.image_dataset_from_directory( ) instead as mentioned here and This issue seems more related to Keras. Please post this issue on keras-team/keras repo. All issues and PRs related to keras will be addressed in that repo.
To know more see;
https://discuss.tensorflow.org/t/keras-project-moved-to-new-repository-in-https-github-com-keras-team-keras/1999.

Thank you!

@tiruk007 tiruk007 added the stat:awaiting response Status - Awaiting response from author label Sep 12, 2022
@Lunatik00
Copy link
Author
Lunatik00 commented Sep 13, 2022

ok, I found tf.keras.utils.image_dataset_from_directory( ) function after, the official tutorials i saw ( https://www.tensorflow.org/guide/data ) use the tf.keras.preprocessing.image.ImageDataGenerator() function, i will post in the keras repo also, but the lack of webp support is also in the tf.io module

@google-ml-butler google-ml-butler bot removed the stat:awaiting response Status - Awaiting response from author label Sep 13, 2022
@Lunatik00
Copy link
Author

Aparently there is some advance already made in the IO repository, there is a decode webp function, but it is not integrated in tf.io , is only available in tensorflow_io ( https://github.com/tensorflow/io/blob/master/tensorflow_io/python/ops/image_ops.py ), I checked the function and it works fine with my images, but it should be added to the main tf.io library and integrated to the rest of the functions to have a good compatibility

@tiruk007 tiruk007 assigned gadagashwini and unassigned tiruk007 Sep 14, 2022
@gadagashwini
Copy link
Contributor

Hi @Lunatik00, The .webp image format is available for tfio.image.decode_webp(). Please take a look at this link. Thank you!

@gadagashwini gadagashwini added the stat:awaiting response Status - Awaiting response from author label Sep 14, 2022
@Lunatik00
Copy link
Author

What I said is that, yes, it is there, the decode works using another package besides tensorflow directly, it is in tfio but not in tf.io and it is not integrated with the rest of the tf package, I can use that for reading individual images, but it doesn't help when I need to use it for a dataset, since it is not integrated with the rest of the package, not to mention that even when there is a decode there is not an encode, don't you find odd that a format that was developed by google is not available as default in another project developed by google? and that I can't save images using that format with the package from google but I would need to use another package like opencv to save them?, the decode is available in a related project, but it is not in the main project, the encode, I haven't found it, the use of webp from other functions that are to read batches of images, non existent, I tried to seek where in the package was the reading part when loading a batch, I haven't found it, but I only use this package, I have only a superficial knowledge of where everything is, I was seeking if at least I could have the batch available for webp when tfio is installed, is not, so, there is no support from other functions even if i install tfio, is not the individual images the problem that I think should be solved, is everything else down the line, the function you mentioned is the one I already pointed out as what I see as the starting point, not the finish line.

@google-ml-butler google-ml-butler bot removed the stat:awaiting response Status - Awaiting response from author label Sep 14, 2022
@ianstenbit
Copy link
Contributor

Related issue in TFDS: tensorflow/datasets#3345

@ianstenbit
Copy link
Contributor
ianstenbit commented Sep 15, 2022

Hi @Lunatik00,

On the Keras side:

If you're interested in contributing support for webp decoding to keras.utils.image_dataset_from_directory, feel free to send a PR to the Keras repo.

With respect to using this for a dataset, as a workaround you can load the webp-encoded images into a dataset and decode them using a call to dataset.map using tfio.image.decode_webp()

Thanks!

@sachinprasadhs sachinprasadhs added the stat:awaiting response Status - Awaiting response from author label Sep 19, 2022
@Lunatik00
Copy link
Author
Lunatik00 commented Sep 20, 2022

thanks for the workaround, i will test it, to have a TLDR for whoever resolves the root issue, it is adding webp to the main branch, my specific problem can be solved in a general way only after it is added to io.decode_image()

To have a few bulletpoints about what I tested:

  • add ".webp" to the ALLOWLIST_FORMATS variable in keras.utils.image_dataset
  • changing the decode image to decode_webp reads the image, but it reads rgba, the image is rgb causing other issues in the long run, that function is in keras.utils.image_dataset and is called load_image(), it ended up as tfio.image.decode_webp(img,channels=num_channels) and not using the expand_animations=False kwarg
  • Given the lack of the channels kwarg I added that to the decode_webp function so it read rgba if 4, converts rgba to rgb if 3 and converts rgba to rgb to grayscale if it is 1 (I didn't found a rgba to grayscale function), but that lacks the 0 option that reads the channels in the image because I have no idea how to implement that, so I didn't pushed the change. It was in tensorflow_io.python.ops.image_ops

With those changes I was able to load and use the dataset, that is why I know the main issue is with the decode_image() function and to have this as a solution is not viable because it drops the support for every other format and I can't expect the rest of the group to add it to their environments. After it is added to the decode_image function then the keras side only needs to add it to the list of supported formats in the code.

@google-ml-butler google-ml-butler bot removed the stat:awaiting response Status - Awaiting response from author label Sep 20, 2022
@sachinprasadhs
Copy link
Contributor

@ianstenbit , cc: @fchollet

@sachinprasadhs sachinprasadhs added the stat:awaiting tensorflower Status - Awaiting response from tensorflower label Sep 20, 2022
@ianstenbit
Copy link
Contributor

From my understanding, it looks like this is a functionality request for core TF, and once it's supported a simple Keras change will be needed to utilize it. So I think this should be routed through the appropriate TF (not Keras) triage @sachinprasadhs (please let me know if I've misunderstood)

@sachinprasadhs sachinprasadhs added the comp:apis Highlevel API related issues label Sep 21, 2022
@gowthamkpr gowthamkpr removed the comp:keras Keras related issues label Sep 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
comp:apis Highlevel API related issues stat:awaiting tensorflower Status - Awaiting response from tensorflower TF 2.10 type:feature Feature requests
Projects
None yet
Development

No branches or pull requests

8 participants