On this page
tf.io.decode_image
Function for decode_bmp
, decode_gif
, decode_jpeg
, and decode_png
.
tf.io.decode_image(
contents, channels=None, dtype=tf.dtypes.uint8, name=None,
expand_animations=True
)
Detects whether an image is a BMP, GIF, JPEG, or PNG, and performs the appropriate operation to convert the input bytes string
into a Tensor
of type dtype
.
Note:decode_gif
returns a 4-D array[num_frames, height, width, 3]
, as opposed todecode_bmp
,decode_jpeg
anddecode_png
, which return 3-D arrays[height, width, num_channels]
. Make sure to take this into account when constructing your graph if you are intermixing GIF files with BMP, JPEG, and/or PNG files. Alternately, set theexpand_animations
argument of this function toFalse
, in which case the op will return 3-dimensional tensors and will truncate animated GIF files to the first frame.
Args | |
---|---|
contents |
0-D string . The encoded image bytes. |
channels |
An optional int . Defaults to 0 . Number of color channels for the decoded image. |
dtype |
The desired DType of the returned Tensor . |
name |
A name for the operation (optional) |
expand_animations |
Controls the shape of the returned op's output. If True , the returned op will produce a 3-D tensor for PNG, JPEG, and BMP files; and a 4-D tensor for all GIFs, whether animated or not. If, False , the returned op will produce a 3-D tensor for all file types and will truncate animated GIFs to the first frame. |
Returns | |
---|---|
Tensor with type dtype and a 3- or 4-dimensional shape, depending on the file type and the value of the expand_animations parameter. |
Raises | |
---|---|
ValueError |
On incorrect number of channels. |
© 2020 The TensorFlow Authors. All rights reserved.
Licensed under the Creative Commons Attribution License 3.0.
Code samples licensed under the Apache 2.0 License.
https://www.tensorflow.org/versions/r2.3/api_docs/python/tf/io/decode_image