tfds.features.Image

Class Image

Inherits From: FeatureConnector

Defined in core/features/image_feature.py.

FeatureConnector for images.

Input: The image connector accepts as input: * path to a {bmp,gif,jpeg,png} image. * uint8 array representing an image.

Output: image: tf.Tensor of type tf.uint8 and shape [height, width, num_channels] for BMP, JPEG, and PNG images and shape [num_frames, height, width, 3] for GIF images.

Example: * In the DatasetInfo object: features=features.FeatureDict({ 'input': features.Image(), 'target': features.Image(shape=(None, None, 1), encoding_format='png'), })

  • During generation: yield { 'input': 'path/to/img.jpg', 'target': np.ones(shape=(64, 64, 1), dtype=np.uint8), }

__init__

__init__(
    shape=None,
    encoding_format=None
)

Construct the connector.

Args:

  • shape: tuple of ints or None, the shape of decoded image. For GIF images: (num_frames, height, width, channels=3). num_frames, height and width can be None. For other images: (height, width, channels). height and width can be None. See tf.image.encode_* for doc on channels parameter. Defaults to (None, None, 3).
  • encoding_format: 'jpeg' or 'png' (default). Format to serialize np.ndarray images on disk. If image is loaded from {bmg,gif,jpeg,png} file, this parameter is ignored, and file original encoding is used.

Raises:

  • ValueError: If the shape is invalid

Properties

dtype

Return the dtype (or dict of dtype) of this FeatureConnector.

serialized_keys

List of the flattened feature keys after serialization.

shape

Return the shape (or dict of shape) of this FeatureConnector.

Methods

decode_example

decode_example(example)

Reconstruct the image from the tf example.

encode_example

encode_example(image_or_path_or_fobj)

Convert the given image into a dict convertible to tf example.

get_serialized_info

get_serialized_info()

get_tensor_info

get_tensor_info()

load_metadata

load_metadata(
    data_dir,
    feature_name=None
)

See base class for details.

save_metadata

save_metadata(
    data_dir,
    feature_name=None
)

See base class for details.

set_encoding_format

set_encoding_format(encoding_format)

Update the encoding format.

set_shape

set_shape(shape)

Update the shape.