class_docstr: Utils which encode/decode images.
class_docstr_tok: ["Utils","which","encode\/decode","images","."]
docstr: Convert the given image into a dict convertible to tf example.
docstr_tok: ["Convert","the","given","image","into","a","dict","convertible","to","tf","example","."]
code: def encode_image_or_path(self, image_or_path_or_fobj):
      """Convert the given image into a dict convertible to tf example."""
      if isinstance(image_or_path_or_fobj, np.ndarray):
          encoded_image = self._encode_image(image_or_path_or_fobj)
      elif isinstance(image_or_path_or_fobj, epath.PathLikeCls):
          image_or_path_or_fobj = os.fspath(image_or_path_or_fobj)
          with tf.io.gfile.GFile(
              image_or_path_or_fobj, "rb"
          ) as image_f:
              encoded_image = image_f.read()
      elif isinstance(image_or_path_or_fobj, bytes):
          encoded_image = image_or_path_or_fobj
      elif PIL_Image is not None and isinstance(
          image_or_path_or_fobj, PIL_Image.Image
      ):
          encoded_image = self._encode_pil_image(image_or_path_or_fobj)
      else:
          encoded_image = image_or_path_or_fobj.read()
      # If encoding is explicitly set, should verify that bytes match encoding.
      return encoded_image
  
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 3 for calling the _ImageEncoder obj's underlying member method code with example usage: obj.encode_image_or_path(image_or_path_or_fobj) and returns: encoded_image