Diffusers documentation

VAE Image Processor

You are viewing v0.19.2 version. A newer version v0.31.0 is available.
Hugging Face's logo
Join the Hugging Face community

and get access to the augmented documentation experience

to get started

VAE Image Processor

The VaeImageProcessor provides a unified API for StableDiffusionPipeline’s to prepare image inputs for VAE encoding and post-processing outputs once they’re decoded. This includes transformations such as resizing, normalization, and conversion between PIL Image, PyTorch, and NumPy arrays.

All pipelines with VaeImageProcessor accepts PIL Image, PyTorch tensor, or NumPy arrays as image inputs and returns outputs based on the output_type argument by the user. You can pass encoded image latents directly to the pipeline and return latents from the pipeline as a specific output with the output_type argument (for example output_type="pt"). This allows you to take the generated latents from one pipeline and pass it to another pipeline as input without leaving the latent space. It also makes it much easier to use multiple pipelines together by passing PyTorch tensors directly between different pipelines.

VaeImageProcessor

class diffusers.image_processor.VaeImageProcessor

< >

( do_resize: bool = True vae_scale_factor: int = 8 resample: str = 'lanczos' do_normalize: bool = True do_convert_rgb: bool = False )

Parameters

  • 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_convert_rgb (bool, optional, defaults to be False) — Whether to convert the images to RGB format.

Image processor for VAE.

convert_to_rgb

< >

( image: Image )

Converts an image to RGB format.

denormalize

< >

( images )

Denormalize an image array to [0,1].

normalize

< >

( images )

Normalize an image array to [-1,1].

numpy_to_pil

< >

( images: ndarray )

Convert a numpy image or a batch of images to a PIL image.

numpy_to_pt

< >

( images: ndarray )

Convert a NumPy image to a PyTorch tensor.

pil_to_numpy

< >

( images: typing.Union[typing.List[PIL.Image.Image], PIL.Image.Image] )

Convert a PIL image or a list of PIL images to NumPy arrays.

preprocess

< >

( image: typing.Union[torch.FloatTensor, PIL.Image.Image, numpy.ndarray] height: typing.Optional[int] = None width: typing.Optional[int] = None )

Preprocess the image input. Accepted formats are PIL images, NumPy arrays or PyTorch tensors.

pt_to_numpy

< >

( images: FloatTensor )

Convert a PyTorch tensor to a NumPy image.

resize

< >

( image: Image height: typing.Optional[int] = None width: typing.Optional[int] = None )

Resize a PIL image. Both height and width are downscaled to the next integer multiple of vae_scale_factor.

VaeImageProcessorLDM3D

The VaeImageProcessorLDM3D accepts RGB and depth inputs and returns RGB and depth outputs.

class diffusers.image_processor.VaeImageProcessorLDM3D

< >

( do_resize: bool = True vae_scale_factor: int = 8 resample: str = 'lanczos' do_normalize: bool = True )

Parameters

  • do_resize (bool, optional, defaults to True) — Whether to downscale the image’s (height, width) dimensions to multiples of vae_scale_factor.
  • 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].

Image processor for VAE LDM3D.

numpy_to_depth

< >

( images )

Convert a NumPy depth image or a batch of images to a PIL image.

numpy_to_pil

< >

( images )

Convert a NumPy image or a batch of images to a PIL image.

rgblike_to_depthmap

< >

( image )

Returns: depth map