class_docstr: Constructs a Swin2SR image processor.
  
  Args:
      do_rescale (`bool`, *optional*, defaults to `True`):
          Whether to rescale the image by the specified scale `rescale_factor`. Can be overridden by the `do_rescale`
          parameter in the `preprocess` method.
      rescale_factor (`int` or `float`, *optional*, defaults to `1/255`):
          Scale factor to use if rescaling the image. Can be overridden by the `rescale_factor` parameter in the
          `preprocess` method.
class_docstr_tok: ["Constructs","a","Swin2SR","image","processor",".","Args",":","do_rescale","(","`","bool","`",",","*","optional","*",",","defaults","to","`","True","`",")",":","Whether","to","rescale","the","image","by","the","specified","scale","`","rescale_factor","`",".","Can","be","overridden","by","the","`","do_rescale","`","parameter","in","the","`","preprocess","`","method",".","rescale_factor","(","`","int","`","or","`","float","`",",","*","optional","*",",","defaults","to","`","1\/255","`",")",":","Scale","factor","to","use","if","rescaling","the","image",".","Can","be","overridden","by","the","`","rescale_factor","`","parameter","in","the","`","preprocess","`","method","."]
docstr: Preprocess an image or batch of images.
  
  Args:
      images (`ImageInput`):
          Image to preprocess. Expects a single or batch of images with pixel values ranging from 0 to 255. If
          passing in images with pixel values between 0 and 1, set `do_rescale=False`.
      do_rescale (`bool`, *optional*, defaults to `self.do_rescale`):
          Whether to rescale the image values between [0 - 1].
      rescale_factor (`float`, *optional*, defaults to `self.rescale_factor`):
          Rescale factor to rescale the image by if `do_rescale` is set to `True`.
      do_pad (`bool`, *optional*, defaults to `True`):
          Whether to pad the image to make the height and width divisible by `window_size`.
      pad_size (`int`, *optional*, defaults to 32):
          The size of the sliding window for the local attention.
      return_tensors (`str` or `TensorType`, *optional*):
          The type of tensors to return. Can be one of:
          - Unset: Return a list of `np.ndarray`.
          - `TensorType.TENSORFLOW` or `'tf'`: Return a batch of typ, input_data_format=input_data_formate
            `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` or `str`, *optional*, defaults to `ChannelDimension.FIRST`):
          The channel dimension format for the output image. Can be one of:
          - `"channels_first"` or `ChannelDimension.FIRST`: image in (num_channels, height, width) format.
          - `"channels_last"` or `ChannelDimension.LAST`: image in (height, width, num_channels) format.
          - Unset: Use the channel dimension format of the input image.
      input_data_format (`ChannelDimension` or `str`, *optional*):
          The channel dimension format for the input image. If unset, the channel dimension format is inferred
          from the input image. Can be one of:
          - `"channels_first"` or `ChannelDimension.FIRST`: image in (num_channels, height, width) format.
          - `"channels_last"` or `ChannelDimension.LAST`: image in (height, width, num_channels) format.
          - `"none"` or `ChannelDimension.NONE`: image in (height, width) format.
docstr_tok: ["Preprocess","an","image","or","batch","of","images",".","Args",":","images","(","`","ImageInput","`",")",":","Image","to","preprocess",".","Expects","a","single","or","batch","of","images","with","pixel","values","ranging","from","0","to","255",".","If","passing","in","images","with","pixel","values","between","0","and","1",",","set","`","do_rescale=False","`",".","do_rescale","(","`","bool","`",",","*","optional","*",",","defaults","to","`","self.do_rescale","`",")",":","Whether","to","rescale","the","image","values","between","[","0","-","1","]",".","rescale_factor","(","`","float","`",",","*","optional","*",",","defaults","to","`","self.rescale_factor","`",")",":","Rescale","factor","to","rescale","the","image","by","if","`","do_rescale","`","is","set","to","`","True","`",".","do_pad","(","`","bool","`",",","*","optional","*",",","defaults","to","`","True","`",")",":","Whether","to","pad","the","image","to","make","the","height","and","width","divisible","by","`","window_size","`",".","pad_size","(","`","int","`",",","*","optional","*",",","defaults","to","32",")",":","The","size","of","the","sliding","window","for","the","local","attention",".","return_tensors","(","`","str","`","or","`","TensorType","`",",","*","optional","*",")",":","The","type","of","tensors","to","return",".","Can","be","one","of",":","-","Unset",":","Return","a","list","of","`","np.ndarray","`",".","-","`","TensorType.TENSORFLOW","`","or","`","'tf","'","`",":","Return","a","batch","of","typ",",","input_data_format=input_data_formate","`","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","`","or","`","str","`",",","*","optional","*",",","defaults","to","`","ChannelDimension.FIRST","`",")",":","The","channel","dimension","format","for","the","output","image",".","Can","be","one","of",":","-","`","``","channels_first","''","`","or","`","ChannelDimension.FIRST","`",":","image","in","(","num_channels",",","height",",","width",")","format",".","-","`","``","channels_last","''","`","or","`","ChannelDimension.LAST","`",":","image","in","(","height",",","width",",","num_channels",")","format",".","-","Unset",":","Use","the","channel","dimension","format","of","the","input","image",".","input_data_format","(","`","ChannelDimension","`","or","`","str","`",",","*","optional","*",")",":","The","channel","dimension","format","for","the","input","image",".","If","unset",",","the","channel","dimension","format","is","inferred","from","the","input","image",".","Can","be","one","of",":","-","`","``","channels_first","''","`","or","`","ChannelDimension.FIRST","`",":","image","in","(","num_channels",",","height",",","width",")","format",".","-","`","``","channels_last","''","`","or","`","ChannelDimension.LAST","`",":","image","in","(","height",",","width",",","num_channels",")","format",".","-","`","``","none","''","`","or","`","ChannelDimension.NONE","`",":","image","in","(","height",",","width",")","format","."]
code: def preprocess(
      self,
      images: ImageInput,
      do_rescale: Optional[bool] = None,
      rescale_factor: Optional[float] = None,
      do_pad: Optional[bool] = None,
      pad_size: Optional[int] = None,
      return_tensors: Optional[Union[str, TensorType]] = None,
      data_format: Union[
          str, ChannelDimension
      ] = ChannelDimension.FIRST,
      input_data_format: Optional[Union[str, ChannelDimension]] = None,
      **kwargs,
  ):
      """
      Preprocess an image or batch of images.
  
      Args:
          images (`ImageInput`):
              Image to preprocess. Expects a single or batch of images with pixel values ranging from 0 to 255. If
              passing in images with pixel values between 0 and 1, set `do_rescale=False`.
          do_rescale (`bool`, *optional*, defaults to `self.do_rescale`):
              Whether to rescale the image values between [0 - 1].
          rescale_factor (`float`, *optional*, defaults to `self.rescale_factor`):
              Rescale factor to rescale the image by if `do_rescale` is set to `True`.
          do_pad (`bool`, *optional*, defaults to `True`):
              Whether to pad the image to make the height and width divisible by `window_size`.
          pad_size (`int`, *optional*, defaults to 32):
              The size of the sliding window for the local attention.
          return_tensors (`str` or `TensorType`, *optional*):
              The type of tensors to return. Can be one of:
              - Unset: Return a list of `np.ndarray`.
              - `TensorType.TENSORFLOW` or `'tf'`: Return a batch of typ, input_data_format=input_data_formate
                `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` or `str`, *optional*, defaults to `ChannelDimension.FIRST`):
              The channel dimension format for the output image. Can be one of:
              - `"channels_first"` or `ChannelDimension.FIRST`: image in (num_channels, height, width) format.
              - `"channels_last"` or `ChannelDimension.LAST`: image in (height, width, num_channels) format.
              - Unset: Use the channel dimension format of the input image.
          input_data_format (`ChannelDimension` or `str`, *optional*):
              The channel dimension format for the input image. If unset, the channel dimension format is inferred
              from the input image. Can be one of:
              - `"channels_first"` or `ChannelDimension.FIRST`: image in (num_channels, height, width) format.
              - `"channels_last"` or `ChannelDimension.LAST`: image in (height, width, num_channels) format.
              - `"none"` or `ChannelDimension.NONE`: image in (height, width) format.
      """
      do_rescale = (
          do_rescale if do_rescale is not None else self.do_rescale
      )
      rescale_factor = (
          rescale_factor
          if rescale_factor is not None
          else self.rescale_factor
      )
      do_pad = do_pad if do_pad is not None else self.do_pad
      pad_size = pad_size if pad_size is not None else self.pad_size
  
      images = make_list_of_images(images)
  
      if not valid_images(images):
          raise ValueError(
              "Invalid image type. Must be of type PIL.Image.Image, numpy.ndarray, "
              "torch.Tensor, tf.Tensor or jax.ndarray."
          )
  
      if do_rescale and rescale_factor is None:
          raise ValueError(
              "Rescale factor must be specified if do_rescale is True."
          )
  
      # All transformations expect numpy arrays.
      images = [to_numpy_array(image) for image in images]
  
      if is_scaled_image(images[0]) and do_rescale:
          logger.warning_once(
              "It looks like you are trying to rescale already rescaled images. If the input"
              " images have pixel values between 0 and 1, set `do_rescale=False` to avoid rescaling them again."
          )
  
      if input_data_format is None:
          # We assume that all images have the same channel dimension format.
          input_data_format = infer_channel_dimension_format(images[0])
  
      if do_rescale:
          images = [
              self.rescale(
                  image=image,
                  scale=rescale_factor,
                  input_data_format=input_data_format,
              )
              for image in images
          ]
  
      if do_pad:
          images = [
              self.pad(
                  image,
                  size=pad_size,
                  input_data_format=input_data_format,
              )
              for image in images
          ]
  
      images = [
          to_channel_dimension_format(
              image, data_format, input_channel_dim=input_data_format
          )
          for image in images
      ]
  
      data = {"pixel_values": images}
      return BatchFeature(data=data, tensor_type=return_tensors)
  
file_path: transformers/src/transformers/models/swin2sr/image_processing_swin2sr.py
imports: from typing import Optional, Union
  import numpy
  from ...image_processing_utils import BaseImageProcessor, BatchFeature
  from ...image_transforms import get_image_size, pad, to_channel_dimension_format
  from ...image_utils import ChannelDimension, ImageInput, infer_channel_dimension_format, is_scaled_image, make_list_of_images, to_numpy_array, valid_images
  from ...utils import TensorType, logging
label_desc: Use image node_id 3 for calling the Swin2SRImageProcessor obj's underlying member method code with example usage: obj.preprocess(images, do_rescale, rescale_factor, do_pad, pad_size, return_tensors, data_format, input_data_format) and returns: BatchFeature