code: def to_pil_image(
      image: Union[
          np.ndarray,
          PIL.Image.Image,
          "torch.Tensor",
          "tf.Tensor",
          "jnp.Tensor",
      ],
      do_rescale: Optional[bool] = None,
  ) -> PIL.Image.Image:
      """
      Converts `image` to a PIL Image. Optionally rescales it and puts the channel dimension back as the last axis if
      needed.
  
      Args:
          image (`PIL.Image.Image` or `numpy.ndarray` or `torch.Tensor` or `tf.Tensor`):
              The image to convert to the `PIL.Image` format.
          do_rescale (`bool`, *optional*):
              Whether or not to apply the scaling factor (to make pixel values integers between 0 and 255). Will default
              to `True` if the image type is a floating type, `False` otherwise.
  
      Returns:
          `PIL.Image.Image`: The converted image.
      """
      if isinstance(image, PIL.Image.Image):
          return image
  
      # Convert all tensors to numpy arrays before converting to PIL image
      if is_torch_tensor(image) or is_tf_tensor(image):
          image = image.numpy()
      elif is_jax_tensor(image):
          image = np.array(image)
      elif not isinstance(image, np.ndarray):
          raise ValueError(
              "Input image type not supported: {}".format(type(image))
          )
  
      # If the channel as been moved to first dim, we put it back at the end.
      image = to_channel_dimension_format(image, ChannelDimension.LAST)
  
      # PIL.Image can only store uint8 values, so we rescale the image to be between 0 and 255 if needed.
      do_rescale = (
          isinstance(image.flat[0], float)
          if do_rescale is None
          else do_rescale
      )
      if do_rescale:
          image = rescale(image, 255)
      image = image.astype(np.uint8)
      return PIL.Image.fromarray(image)
  
file_path: H2O/h2o_flexgen/benchmark/third_party/transformers/src/transformers/image_transforms.py
imports: import warnings
  from typing import TYPE_CHECKING, Iterable, List, Optional, Tuple, Union
  import numpy
  from transformers.image_utils import PILImageResampling
  from transformers.utils.import_utils import is_flax_available, is_tf_available, is_torch_available, is_vision_available
label_desc: Use image node_id 3 for calling a global function with example usage: to_pil_image(image, do_rescale) and returns: PIL, image