Commit Graph

1 Commits

Author SHA1 Message Date
A. Unique TensorFlower
5aeb2e6531 Add support for WebP in DecodeImage
WebP offers both lossless and lossy compression that can be superior to JPEG or
PNG. Requests for WebP support directly in TF have come up before (e.g.,
https://github.com/tensorflow/tensorflow/issues/18250) but has been kept out of
tree in the TFIO (https://github.com/tensorflow/io/pull/43). Unfortunately, the
TFIO implementation hardcodes channels_ = 4, and doesn't have the same
ShapeInferenceFn style of support that DecodeImage does.

Let's just bring native WebP decode support into TF for tf.data
directly. Animation is supported, and similar to decode_gif, decode_webp
produces a tensor of [num_frames, height, width, channels], even for a still
frame (num_frames = 1). To get 3D tensors instead, use decode_image with
expand_animations = False.

Note: libwebp (and maybe the WebP format?) only supports 4-channel animation, so
channels will always be 4 for animations.
PiperOrigin-RevId: 736966060
2025-03-14 13:40:51 -07:00