code: def to_channel_dimension_format(
      image: np.ndarray, channel_dim: Union[ChannelDimension, str]
  ) -> np.ndarray:
      """
      Converts `image` to the channel dimension format specified by `channel_dim`.
  
      Args:
          image (`numpy.ndarray`):
              The image to have its channel dimension set.
          channel_dim (`ChannelDimension`):
              The channel dimension format to use.
  
      Returns:
          `np.ndarray`: The image with the channel dimension set to `channel_dim`.
      """
      if not isinstance(image, np.ndarray):
          raise ValueError(
              f"Input image must be of type np.ndarray, got {type(image)}"
          )
  
      current_channel_dim = infer_channel_dimension_format(image)
      target_channel_dim = ChannelDimension(channel_dim)
      if current_channel_dim == target_channel_dim:
          return image
  
      if target_channel_dim == ChannelDimension.FIRST:
          image = image.transpose((2, 0, 1))
      elif target_channel_dim == ChannelDimension.LAST:
          image = image.transpose((1, 2, 0))
      else:
          raise ValueError(
              "Unsupported channel dimension format: {}".format(
                  channel_dim
              )
          )
  
      return 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 1 for calling a global function with example usage: to_channel_dimension_format(image, channel_dim) and returns: image, image