class_docstr: Utils which encode/decode images.
class_docstr_tok: ["Utils","which","encode\/decode","images","."]
docstr: Returns np_image encoded as jpeg or png.
docstr_tok: ["Returns","np_image","encoded","as","jpeg","or","png","."]
code: def _encode_image(self, np_image: np.ndarray) -> bytes:
      """Returns np_image encoded as jpeg or png."""
      _validate_np_array(
          np_image, shape=self.shape, dtype=self.np_dtype
      )
  
      # When encoding isn't defined, default to PNG.
      # Should we be more strict about explicitly define the encoding (raise
      # error / warning instead) ?
      # It has created subtle issues for imagenet_corrupted: images are read as
      # JPEG images to apply some processing, but final image saved as PNG
      # (default) rather than JPEG.
      return self._runner.run(
          _ENCODE_FN[self.encoding_format or "png"](), np_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 4 for calling the _ImageEncoder obj's underlying member method code with example usage: obj._encode_image(np_image) and returns: self