code: def _decode_image(fobj, session, filename):
      """Reads and decodes an image from a file object as a Numpy array.
  
      The SUN dataset contains images in several formats (despite the fact that
      all of them have .jpg extension). Some of them are:
        - BMP (RGB)
        - PNG (grayscale, RGBA, RGB interlaced)
        - JPEG (RGB)
        - GIF (1-frame RGB)
      Since TFDS assumes that all images have the same number of channels, we
      convert all of them to RGB.
  
      Args:
        fobj: File object to read from.
        session: TF session used to decode the images.
        filename: Filename of the original image in the archive.
  
      Returns:
        Numpy array with shape (height, width, channels).
      """
  
      buf = fobj.read()
      image = tfds.core.lazy_imports.cv2.imdecode(
          np.frombuffer(buf, dtype=np.uint8), flags=3
      )  # Note: Converts to RGB.
      if image is None:
          logging.warning(
              "Image %s could not be decoded by OpenCV, falling back to TF",
              filename,
          )
          try:
              image = tf.image.decode_image(buf, channels=3)
              image = session.run(image)
          except tf.errors.InvalidArgumentError as e:
              raise ValueError(
                  f"{e}. Image {filename} could not be decoded by Tensorflow."
              ) from e
  
      # The GIF images contain a single frame.
      if len(image.shape) == 4:  # rank=4 -> rank=3
          image = image.reshape(image.shape[1:])
  
      return image
  
imports: import io
  import os
  from absl import logging
  import numpy
  from tensorflow_datasets.core import utils
  from tensorflow_datasets.core.utils.lazy_imports_utils import tensorflow
  import tensorflow_datasets.public_api
label_desc: Use image node_id 1 for calling a global function with example usage: _decode_image(fobj, session, filename) and returns: image