code: def _image_bytes_to_numpy_array(
      image_bytes: Union[bytes, np.ndarray]
  ) -> np.ndarray:
      """Read bytes or a numpy scalar of bytes of image and return an ndarray."""
      if isinstance(image_bytes, np.ndarray):
          assert image_bytes.size == 1
          image_bytes = image_bytes.item()
      image = Image.open(io.BytesIO(image_bytes))
      return np.array(image, dtype=np.uint8)
  
file_path: model-analysis/tensorflow_model_analysis/metrics/preprocessors/image_preprocessors.py
imports: import collections
  import io
  from typing import Iterator, Optional, Union
  import numpy
  from PIL import Image
  from tensorflow_model_analysis import constants
  from tensorflow_model_analysis.api import types
  from tensorflow_model_analysis.metrics import metric_types
  from tensorflow_model_analysis.metrics import metric_util
  from tensorflow_model_analysis.utils import util
label_desc: Use image node_id 1 for calling a global function with example usage: _image_bytes_to_numpy_array(image_bytes) and returns: np