class_docstr: Constructs a GLPN image processor.
  
  Args:
      do_resize (`bool`, *optional*, defaults to `True`):
          Set the class default for the `do_resize` parameter. Controls whether to resize the image's (height, width)
          dimensions, rounding them down to the closest multiple of `size_divisor`.
      size_divisor (`int`, *optional*, defaults to 32):
          Set the class default for the `size_divisor` parameter. When `do_resize` is `True`, images are resized so
          their height and width are rounded down to the closest multiple of `size_divisor`.
      resample (`PIL.Image` resampling filter, *optional*, defaults to `PIL.Image.Resampling.BILINEAR`):
          Set the class default for `resample`. Defines the resampling filter to use if resizing the image.
      do_rescale (`bool`, *optional*, defaults to `True`):
          Set the class default for the `do_rescale` parameter. Controls whether or not to apply the scaling factor
          (to make pixel values floats between 0. and 1.).
docstr: Preprocess the given images.
  
  Args:
      images (`PIL.Image.Image` or `TensorType` or `List[np.ndarray]` or `List[TensorType]`):
          The image or images to preprocess.
      do_resize (`bool`, *optional*, defaults to `self.do_resize`):
          Whether to resize the input such that the (height, width) dimensions are a multiple of `size_divisor`.
      size_divisor (`int`, *optional*, defaults to `self.size_divisor`):
          When `do_resize` is `True`, images are resized so their height and width are rounded down to the
          closest multiple of `size_divisor`.
      resample (`PIL.Image` resampling filter, *optional*, defaults to `self.resample`):
          `PIL.Image` resampling filter to use if resizing the image e.g. `PIL.Image.Resampling.BILINEAR`. Only
          has an effect if `do_resize` is set to `True`.
      do_rescale (`bool`, *optional*, defaults to `self.do_rescale`):
          Whether or not to apply the scaling factor (to make pixel values floats between 0. and 1.).
      return_tensors (`str`, *optional*):
          The type of tensors to return. Can be one of:
              - `None`: Return a list of `np.ndarray`.
              - `TensorType.TENSORFLOW` or `'tf'`: Return a batch of type `tf.Tensor`.
              - `TensorType.PYTORCH` or `'pt'`: Return a batch of type `torch.Tensor`.
              - `TensorType.NUMPY` or `'np'`: Return a batch of type `np.ndarray`.
              - `TensorType.JAX` or `'jax'`: Return a batch of type `jax.numpy.ndarray`.
      data_format (`ChannelDimension`, *optional*, defaults to `ChannelDimension.FIRST`):
          The channel dimension format for the output image. Can be one of:
              - `ChannelDimension.FIRST`: image in (num_channels, height, width) format.
              - `ChannelDimension.LAST`: image in (height, width, num_channels) format.
docstr_tok: ["Preprocess","the","given","images",".","Args",":","images","(","`","PIL.Image.Image","`","or","`","TensorType","`","or","`","List","[","np.ndarray","]","`","or","`","List","[","TensorType","]","`",")",":","The","image","or","images","to","preprocess",".","do_resize","(","`","bool","`",",","*","optional","*",",","defaults","to","`","self.do_resize","`",")",":","Whether","to","resize","the","input","such","that","the","(","height",",","width",")","dimensions","are","a","multiple","of","`","size_divisor","`",".","size_divisor","(","`","int","`",",","*","optional","*",",","defaults","to","`","self.size_divisor","`",")",":","When","`","do_resize","`","is","`","True","`",",","images","are","resized","so","their","height","and","width","are","rounded","down","to","the","closest","multiple","of","`","size_divisor","`",".","resample","(","`","PIL.Image","`","resampling","filter",",","*","optional","*",",","defaults","to","`","self.resample","`",")",":","`","PIL.Image","`","resampling","filter","to","use","if","resizing","the","image","e.g",".","`","PIL.Image.Resampling.BILINEAR","`",".","Only","has","an","effect","if","`","do_resize","`","is","set","to","`","True","`",".","do_rescale","(","`","bool","`",",","*","optional","*",",","defaults","to","`","self.do_rescale","`",")",":","Whether","or","not","to","apply","the","scaling","factor","(","to","make","pixel","values","floats","between","0.","and","1.",")",".","return_tensors","(","`","str","`",",","*","optional","*",")",":","The","type","of","tensors","to","return",".","Can","be","one","of",":","-","`","None","`",":","Return","a","list","of","`","np.ndarray","`",".","-","`","TensorType.TENSORFLOW","`","or","`","'tf","'","`",":","Return","a","batch","of","type","`","tf.Tensor","`",".","-","`","TensorType.PYTORCH","`","or","`","'pt","'","`",":","Return","a","batch","of","type","`","torch.Tensor","`",".","-","`","TensorType.NUMPY","`","or","`","'np","'","`",":","Return","a","batch","of","type","`","np.ndarray","`",".","-","`","TensorType.JAX","`","or","`","'jax","'","`",":","Return","a","batch","of","type","`","jax.numpy.ndarray","`",".","data_format","(","`","ChannelDimension","`",",","*","optional","*",",","defaults","to","`","ChannelDimension.FIRST","`",")",":","The","channel","dimension","format","for","the","output","image",".","Can","be","one","of",":","-","`","ChannelDimension.FIRST","`",":","image","in","(","num_channels",",","height",",","width",")","format",".","-","`","ChannelDimension.LAST","`",":","image","in","(","height",",","width",",","num_channels",")","format","."]
code: def preprocess(
      self,
      images: Union[
          "PIL.Image.Image",
          TensorType,
          List["PIL.Image.Image"],
          List[TensorType],
      ],
      do_resize: Optional[bool] = None,
      size_divisor: Optional[int] = None,
      resample=None,
      do_rescale: Optional[bool] = None,
      return_tensors: Optional[Union[TensorType, str]] = None,
      data_format: ChannelDimension = ChannelDimension.FIRST,
      **kwargs,
  ) -> BatchFeature:
      """
      Preprocess the given images.
  
      Args:
          images (`PIL.Image.Image` or `TensorType` or `List[np.ndarray]` or `List[TensorType]`):
              The image or images to preprocess.
          do_resize (`bool`, *optional*, defaults to `self.do_resize`):
              Whether to resize the input such that the (height, width) dimensions are a multiple of `size_divisor`.
          size_divisor (`int`, *optional*, defaults to `self.size_divisor`):
              When `do_resize` is `True`, images are resized so their height and width are rounded down to the
              closest multiple of `size_divisor`.
          resample (`PIL.Image` resampling filter, *optional*, defaults to `self.resample`):
              `PIL.Image` resampling filter to use if resizing the image e.g. `PIL.Image.Resampling.BILINEAR`. Only
              has an effect if `do_resize` is set to `True`.
          do_rescale (`bool`, *optional*, defaults to `self.do_rescale`):
              Whether or not to apply the scaling factor (to make pixel values floats between 0. and 1.).
          return_tensors (`str`, *optional*):
              The type of tensors to return. Can be one of:
                  - `None`: Return a list of `np.ndarray`.
                  - `TensorType.TENSORFLOW` or `'tf'`: Return a batch of type `tf.Tensor`.
                  - `TensorType.PYTORCH` or `'pt'`: Return a batch of type `torch.Tensor`.
                  - `TensorType.NUMPY` or `'np'`: Return a batch of type `np.ndarray`.
                  - `TensorType.JAX` or `'jax'`: Return a batch of type `jax.numpy.ndarray`.
          data_format (`ChannelDimension`, *optional*, defaults to `ChannelDimension.FIRST`):
              The channel dimension format for the output image. Can be one of:
                  - `ChannelDimension.FIRST`: image in (num_channels, height, width) format.
                  - `ChannelDimension.LAST`: image in (height, width, num_channels) format.
      """
      do_resize = do_resize if do_resize is not None else self.do_resize
      do_rescale = (
          do_rescale if do_rescale is not None else self.do_rescale
      )
      size_divisor = (
          size_divisor
          if size_divisor is not None
          else self.size_divisor
      )
      resample = resample if resample is not None else self.resample
  
      if do_resize and size_divisor is None:
          raise ValueError("size_divisor is required for resizing")
  
      if not is_batched(images):
          images = [images]
  
      if not valid_images(images):
          raise ValueError("Invalid image(s)")
  
      # All transformations expect numpy arrays.
      images = [to_numpy_array(img) for img in images]
  
      if do_resize:
          images = [
              self.resize(
                  image, size_divisor=size_divisor, resample=resample
              )
              for image in images
          ]
  
      if do_rescale:
          images = [
              self.rescale(image, scale=1 / 255) for image in images
          ]
  
      images = [
          to_channel_dimension_format(image, data_format)
          for image in images
      ]
  
      data = {"pixel_values": images}
      return BatchFeature(data=data, tensor_type=return_tensors)
  
file_path: H2O/h2o_flexgen/benchmark/third_party/transformers/src/transformers/models/glpn/image_processing_glpn.py
imports: from typing import List, Optional, Union
  import numpy
  import PIL.Image
  from transformers.image_utils import PILImageResampling
  from transformers.utils.generic import TensorType
  from ...image_processing_utils import BaseImageProcessor, BatchFeature
  from ...image_transforms import rescale, resize, to_channel_dimension_format
  from ...image_utils import ChannelDimension, get_image_size, is_batched, to_numpy_array, valid_images
  from ...utils import logging
label_desc: Use image node_id 4 for calling the GLPNImageProcessor obj's underlying member method code with example usage: obj.preprocess(images, do_resize, size_divisor, resample, do_rescale, return_tensors, data_format) and returns: BatchFeature