class_docstr: `FeatureConnector` for images.
  
  During `_generate_examples`, the feature connector accept as input any of:
  
    * `str`: path to a {bmp,gif,jpeg,png} image (ex: `/path/to/img.png`).
    * `np.array`: 3d `np.uint8` array representing an image.
    * A file object containing the png or jpeg encoded image string (ex:
      `io.BytesIO(encoded_img_bytes)`)
    * A `PIL.Image.Image`: PIL Image object.
  
  Output:
  
    `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 `tfds.core.DatasetInfo` object:
  
    ```python
    features=features.FeaturesDict({
        'input': features.Image(),
        'target': features.Image(shape=(None, None, 1), encoding_format='png'),
    })
    ```
  
    * During generation:
  
    ```python
    yield {
        'input': 'path/to/img.jpg',
        'target': np.ones(shape=(64, 64, 1), dtype=np.uint8),
    }
    ```
class_docstr_tok: ["`","FeatureConnector","`","for","images",".","During","`","_generate_examples","`",",","the","feature","connector","accept","as","input","any","of",":","*","`","str","`",":","path","to","a","{","bmp",",","gif",",","jpeg",",","png","}","image","(","ex",":","`","\/path\/to\/img.png","`",")",".","*","`","np.array","`",":","3d","`","np.uint8","`","array","representing","an","image",".","*","A","file","object","containing","the","png","or","jpeg","encoded","image","string","(","ex",":","`","io.BytesIO","(","encoded_img_bytes",")","`",")","*","A","`","PIL.Image.Image","`",":","PIL","Image","object",".","Output",":","`","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","`","tfds.core.DatasetInfo","`","object",":","``","`","python","features=features.FeaturesDict","(","{","'input","'",":","features.Image","(",")",",","'target","'",":","features.Image","(","shape=","(","None",",","None",",","1",")",",","encoding_format='png","'",")",",","}",")","``","`","*","During","generation",":","``","`","python","yield","{","'input","'",":","'path\/to\/img.jpg","'",",","'target","'",":","np.ones","(","shape=","(","64",",","64",",","1",")",",","dtype=np.uint8",")",",","}","``","`"]
docstr: 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).
    dtype: `np.uint8` (default), `np.uint16` or `np.float32`. * `np.uint16`
      requires png encoding_format. * `np.float32` only supports
      single-channel image. Internally float images are bitcasted to
      4-channels `np.uint8` and saved as PNG.
    encoding_format: 'jpeg' or 'png'. Format to serialize `np.ndarray` images
      on disk. If None, encode images as PNG. If image is loaded from
      {bmg,gif,jpeg,png} file, this parameter is ignored, and file original
      encoding is used.
    use_colormap: Only used for gray-scale images. If `True`,
      `tfds.as_dataframe` will display each value in the image with a
      different color.
    doc: Documentation of this feature (e.g. description).
  
  Raises:
    ValueError: If the shape is invalid
docstr_tok: ["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",")",".","dtype",":","`","np.uint8","`","(","default",")",",","`","np.uint16","`","or","`","np.float32","`",".","*","`","np.uint16","`","requires","png","encoding_format",".","*","`","np.float32","`","only","supports","single-channel","image",".","Internally","float","images","are","bitcasted","to","4-channels","`","np.uint8","`","and","saved","as","PNG",".","encoding_format",":","'jpeg","'","or","'png","'",".","Format","to","serialize","`","np.ndarray","`","images","on","disk",".","If","None",",","encode","images","as","PNG",".","If","image","is","loaded","from","{","bmg",",","gif",",","jpeg",",","png","}","file",",","this","parameter","is","ignored",",","and","file","original","encoding","is","used",".","use_colormap",":","Only","used","for","gray-scale","images",".","If","`","True","`",",","`","tfds.as_dataframe","`","will","display","each","value","in","the","image","with","a","different","color",".","doc",":","Documentation","of","this","feature","(","e.g",".","description",")",".","Raises",":","ValueError",":","If","the","shape","is","invalid"]
code: def __init__(
      self,
      *,
      shape: Optional[utils.Shape] = None,
      dtype: Optional[type_utils.TfdsDType] = None,
      encoding_format: Optional[str] = None,
      use_colormap: bool = False,
      doc: feature_lib.DocArg = 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).
        dtype: `np.uint8` (default), `np.uint16` or `np.float32`. * `np.uint16`
          requires png encoding_format. * `np.float32` only supports
          single-channel image. Internally float images are bitcasted to
          4-channels `np.uint8` and saved as PNG.
        encoding_format: 'jpeg' or 'png'. Format to serialize `np.ndarray` images
          on disk. If None, encode images as PNG. If image is loaded from
          {bmg,gif,jpeg,png} file, this parameter is ignored, and file original
          encoding is used.
        use_colormap: Only used for gray-scale images. If `True`,
          `tfds.as_dataframe` will display each value in the image with a
          different color.
        doc: Documentation of this feature (e.g. description).
  
      Raises:
        ValueError: If the shape is invalid
      """
      super().__init__(doc=doc)
      # Set and validate values
      shape = shape or (None, None, 3)
      dtype = dtype_utils.cast_to_numpy(dtype or np.uint8)
      self._encoding_format = get_and_validate_encoding(encoding_format)
      self._shape = get_and_validate_shape(shape, self._encoding_format)
      self._dtype = get_and_validate_dtype(dtype, self._encoding_format)
      self._use_colormap = _get_and_validate_colormap(
          use_colormap, self._shape, self._dtype, self._encoding_format
      )
  
      if (
          self._dtype == np.float32
      ):  # Float images encoded as 4-channels uint8
          self._image_encoder = _FloatImageEncoder(
              shape=self._shape,
              encoding_format=self._encoding_format,
          )
      else:
          self._image_encoder = _ImageEncoder(
              shape=self._shape,
              dtype=self._dtype,
              encoding_format=self._encoding_format,
          )
  
imports: from __future__ import annotations
  import dataclasses
  import functools
  import io
  import os
  import tempfile
  from typing import Any, List, Optional, Type, Union
  from absl import logging
  from etils import epath
  import numpy
  from tensorflow_datasets.core import lazy_imports_lib
  from tensorflow_datasets.core import utils
  from tensorflow_datasets.core.features import feature
  from tensorflow_datasets.core.proto import feature_pb2
  from tensorflow_datasets.core.utils import dtype_utils
  from tensorflow_datasets.core.utils import py_utils
  from tensorflow_datasets.core.utils import type_utils
  from tensorflow_datasets.core.utils.lazy_imports_utils import tensorflow
label_desc: Use image node_id 1 to create a new Image object from inherited base classes: feature_lib with example: obj = Image()