tensorflow
tensorflow copied to clipboard
Request: webp support
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
@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!
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
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
Hi @Lunatik00, The .webp image format is available for tfio.image.decode_webp(). Please take a look at this link. Thank you!
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.
Related issue in TFDS: https://github.com/tensorflow/datasets/issues/3345
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!
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.
@ianstenbit , cc: @fchollet
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)