class_docstr: Image processor for VAE.
  
  Args:
      do_resize (`bool`, *optional*, defaults to `True`):
          Whether to downscale the image's (height, width) dimensions to multiples of `vae_scale_factor`. Can accept
          `height` and `width` arguments from [`image_processor.VaeImageProcessor.preprocess`] method.
      vae_scale_factor (`int`, *optional*, defaults to `8`):
          VAE scale factor. If `do_resize` is `True`, the image is automatically resized to multiples of this factor.
      resample (`str`, *optional*, defaults to `lanczos`):
          Resampling filter to use when resizing the image.
      do_normalize (`bool`, *optional*, defaults to `True`):
          Whether to normalize the image to [-1,1].
      do_binarize (`bool`, *optional*, defaults to `False`):
          Whether to binarize the image to 0/1.
      do_convert_rgb (`bool`, *optional*, defaults to be `False`):
          Whether to convert the images to RGB format.
      do_convert_grayscale (`bool`, *optional*, defaults to be `False`):
          Whether to convert the images to grayscale format.
class_docstr_tok: ["Image","processor","for","VAE",".","Args",":","do_resize","(","`","bool","`",",","*","optional","*",",","defaults","to","`","True","`",")",":","Whether","to","downscale","the","image","'s","(","height",",","width",")","dimensions","to","multiples","of","`","vae_scale_factor","`",".","Can","accept","`","height","`","and","`","width","`","arguments","from","[","`","image_processor.VaeImageProcessor.preprocess","`","]","method",".","vae_scale_factor","(","`","int","`",",","*","optional","*",",","defaults","to","`","8","`",")",":","VAE","scale","factor",".","If","`","do_resize","`","is","`","True","`",",","the","image","is","automatically","resized","to","multiples","of","this","factor",".","resample","(","`","str","`",",","*","optional","*",",","defaults","to","`","lanczos","`",")",":","Resampling","filter","to","use","when","resizing","the","image",".","do_normalize","(","`","bool","`",",","*","optional","*",",","defaults","to","`","True","`",")",":","Whether","to","normalize","the","image","to","[","-1,1","]",".","do_binarize","(","`","bool","`",",","*","optional","*",",","defaults","to","`","False","`",")",":","Whether","to","binarize","the","image","to","0\/1",".","do_convert_rgb","(","`","bool","`",",","*","optional","*",",","defaults","to","be","`","False","`",")",":","Whether","to","convert","the","images","to","RGB","format",".","do_convert_grayscale","(","`","bool","`",",","*","optional","*",",","defaults","to","be","`","False","`",")",":","Whether","to","convert","the","images","to","grayscale","format","."]
docstr: Preprocess the image input. Accepted formats are PIL images, NumPy arrays or PyTorch tensors.
docstr_tok: ["Preprocess","the","image","input",".","Accepted","formats","are","PIL","images",",","NumPy","arrays","or","PyTorch","tensors","."]
code: def preprocess(
      self,
      image: Union[torch.FloatTensor, PIL.Image.Image, np.ndarray],
      height: Optional[int] = None,
      width: Optional[int] = None,
  ) -> torch.Tensor:
      """
      Preprocess the image input. Accepted formats are PIL images, NumPy arrays or PyTorch tensors.
      """
      supported_formats = (PIL.Image.Image, np.ndarray, torch.Tensor)
  
      # Expand the missing dimension for 3-dimensional pytorch tensor or numpy array that represents grayscale image
      if (
          self.config.do_convert_grayscale
          and isinstance(image, (torch.Tensor, np.ndarray))
          and image.ndim == 3
      ):
          if isinstance(image, torch.Tensor):
              # if image is a pytorch tensor could have 2 possible shapes:
              #    1. batch x height x width: we should insert the channel dimension at position 1
              #    2. channnel x height x width: we should insert batch dimension at position 0,
              #       however, since both channel and batch dimension has same size 1, it is same to insert at position 1
              #    for simplicity, we insert a dimension of size 1 at position 1 for both cases
              image = image.unsqueeze(1)
          else:
              # if it is a numpy array, it could have 2 possible shapes:
              #   1. batch x height x width: insert channel dimension on last position
              #   2. height x width x channel: insert batch dimension on first position
              if image.shape[-1] == 1:
                  image = np.expand_dims(image, axis=0)
              else:
                  image = np.expand_dims(image, axis=-1)
  
      if isinstance(image, supported_formats):
          image = [image]
      elif not (
          isinstance(image, list)
          and all(isinstance(i, supported_formats) for i in image)
      ):
          raise ValueError(
              f"Input is in incorrect format: {[type(i) for i in image]}. Currently, we only support {', '.join(supported_formats)}"
          )
  
      if isinstance(image[0], PIL.Image.Image):
          if self.config.do_convert_rgb:
              image = [self.convert_to_rgb(i) for i in image]
          elif self.config.do_convert_grayscale:
              image = [self.convert_to_grayscale(i) for i in image]
          if self.config.do_resize:
              height, width = self.get_default_height_width(
                  image[0], height, width
              )
              image = [self.resize(i, height, width) for i in image]
          image = self.pil_to_numpy(image)  # to np
          image = self.numpy_to_pt(image)  # to pt
  
      elif isinstance(image[0], np.ndarray):
          image = (
              np.concatenate(image, axis=0)
              if image[0].ndim == 4
              else np.stack(image, axis=0)
          )
  
          image = self.numpy_to_pt(image)
  
          height, width = self.get_default_height_width(
              image, height, width
          )
          if self.config.do_resize:
              image = self.resize(image, height, width)
  
      elif isinstance(image[0], torch.Tensor):
          image = (
              torch.cat(image, axis=0)
              if image[0].ndim == 4
              else torch.stack(image, axis=0)
          )
  
          if self.config.do_convert_grayscale and image.ndim == 3:
              image = image.unsqueeze(1)
  
          channel = image.shape[1]
          # don't need any preprocess if the image is latents
          if channel == 4:
              return image
  
          height, width = self.get_default_height_width(
              image, height, width
          )
          if self.config.do_resize:
              image = self.resize(image, height, width)
  
      # expected range [0,1], normalize to [-1,1]
      do_normalize = self.config.do_normalize
      if image.min() < 0 and do_normalize:
          warnings.warn(
              "Passing `image` as torch tensor with value range in [-1,1] is deprecated. The expected value range for image tensor is [0,1] "
              f"when passing as pytorch tensor or numpy Array. You passed `image` with value range [{image.min()},{image.max()}]",
              FutureWarning,
          )
          do_normalize = False
  
      if do_normalize:
          image = self.normalize(image)
  
      if self.config.do_binarize:
          image = self.binarize(image)
  
      return image
  
imports: import warnings
  from typing import List, Optional, Union
  import numpy
  import PIL.Image
  import torch
  from PIL import Image
  from .configuration_utils import ConfigMixin, register_to_config
  from .utils import CONFIG_NAME, PIL_INTERPOLATION, deprecate
label_desc: Use image node_id 13 for calling the VaeImageProcessor obj's underlying member method code with example usage: obj.preprocess(image, height, width) and returns: image, image