Buckets:
VAE Image Processor
The VaeImageProcessor provides a unified API for StableDiffusionPipelines 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 accept PIL Image, PyTorch tensor, or NumPy arrays as image inputs and return 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="latent"). 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[[diffusers.image_processor.VaeImageProcessor]]
class diffusers.image_processor.VaeImageProcessordiffusers.image_processor.VaeImageProcessorbool, 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 to8) -- VAE scale factor. Ifdo_resizeisTrue, the image is automatically resized to multiples of this factor. - resample (
str, optional, defaults tolanczos) -- Resampling filter to use when resizing the image. - do_normalize (
bool, optional, defaults toTrue) -- Whether to normalize the image to [-1,1]. - do_binarize (
bool, optional, defaults toFalse) -- Whether to binarize the image to 0/1. - do_convert_rgb (
bool, optional, defaults to beFalse) -- Whether to convert the images to RGB format. - do_convert_grayscale (
bool, optional, defaults to beFalse) -- Whether to convert the images to grayscale format.0
Image processor for VAE.
apply_overlaydiffusers.image_processor.VaeImageProcessor.apply_overlayPIL.Image.Image) --
The mask image that highlights regions to overlay.
- init_image (
PIL.Image.Image) -- The original image to which the overlay is applied. - image (
PIL.Image.Image) -- The image to overlay onto the original. - crop_coords (
Tuple[int, int, int, int], optional) -- Coordinates to crop the image. If provided, the image will be cropped accordingly.0PIL.Image.ImageThe final image with the overlay applied.
Applies an overlay of the mask and the inpainted image on the original image.
binarizediffusers.image_processor.VaeImageProcessor.binarizePIL.Image.Image) --
The image input, should be a PIL image.0PIL.Image.ImageThe binarized image. Values less than 0.5 are set to 0, values greater than 0.5 are set to 1.
Create a mask.
blurdiffusers.image_processor.VaeImageProcessor.blurPIL.Image.Image) --
The PIL image to convert to grayscale.0PIL.Image.ImageThe grayscale-converted PIL image.
Applies Gaussian blur to an image.
convert_to_grayscalediffusers.image_processor.VaeImageProcessor.convert_to_grayscalePIL.Image.Image) --
The input image to convert.0PIL.Image.ImageThe image converted to grayscale.
Converts a given PIL image to grayscale.
convert_to_rgbdiffusers.image_processor.VaeImageProcessor.convert_to_rgbPIL.Image.Image) --
The PIL image to convert to RGB.0PIL.Image.ImageThe RGB-converted PIL image.
Converts a PIL image to RGB format.
denormalizediffusers.image_processor.VaeImageProcessor.denormalizenp.ndarray or torch.Tensor) --
The image array to denormalize.0np.ndarray or torch.TensorThe denormalized image array.
Denormalize an image array to [0,1].
get_crop_regiondiffusers.image_processor.VaeImageProcessor.get_crop_region
- width (int) -- Width of the image to be processed.
- height (int) -- Height of the image to be processed.
- pad (int, optional) -- Padding to be added to the crop region. Defaults to 0.0tuple(x1, y1, x2, y2) represent a rectangular region that contains all masked ares in an image and matches the original aspect ratio.
Finds a rectangular region that contains all masked ares in an image, and expands region to match the aspect ratio of the original image; for example, if user drew mask in a 128x32 region, and the dimensions for processing are 512x512, the region will be expanded to 128x128.
get_default_height_widthdiffusers.image_processor.VaeImageProcessor.get_default_height_widthUnion[PIL.Image.Image, np.ndarray, torch.Tensor]) --
The image input, which can be a PIL image, NumPy array, or PyTorch tensor. If it is a NumPy array, it
should have shape [batch, height, width] or [batch, height, width, channels]. If it is a PyTorch
tensor, it should have shape [batch, channels, height, width].
- height (
Optional[int], optional, defaults toNone) -- The height of the preprocessed image. IfNone, the height of theimageinput will be used. - width (
Optional[int], optional, defaults toNone) -- The width of the preprocessed image. IfNone, the width of theimageinput will be used.0Tuple[int, int]A tuple containing the height and width, both resized to the nearest integer multiple ofvae_scale_factor.
Returns the height and width of the image, downscaled to the next integer multiple of vae_scale_factor.
normalizediffusers.image_processor.VaeImageProcessor.normalizenp.ndarray or torch.Tensor) --
The image array to normalize.0np.ndarray or torch.TensorThe normalized image array.
Normalize an image array to [-1,1].
numpy_to_pildiffusers.image_processor.VaeImageProcessor.numpy_to_pilnp.ndarray) --
The image array to convert to PIL format.0List[PIL.Image.Image]A list of PIL images.
Convert a numpy image or a batch of images to a PIL image.
numpy_to_ptdiffusers.image_processor.VaeImageProcessor.numpy_to_ptnp.ndarray) --
The NumPy image array to convert to PyTorch format.0torch.TensorA PyTorch tensor representation of the images.
Convert a NumPy image to a PyTorch tensor.
pil_to_numpydiffusers.image_processor.VaeImageProcessor.pil_to_numpyPIL.Image.Image or List[PIL.Image.Image]) --
The PIL image or list of images to convert to NumPy format.0np.ndarrayA NumPy array representation of the images.
Convert a PIL image or a list of PIL images to NumPy arrays.
postprocessdiffusers.image_processor.VaeImageProcessor.postprocesstorch.Tensor) --
The image input, should be a pytorch tensor with shape B x C x H x W.
- output_type (
str, optional, defaults topil) -- The output type of the image, can be one ofpil,np,pt,latent. - do_denormalize (
List[bool], optional, defaults toNone) -- Whether to denormalize the image to [0,1]. IfNone, will use the value ofdo_normalizein theVaeImageProcessorconfig.0PIL.Image.Image,np.ndarrayortorch.TensorThe postprocessed image.
Postprocess the image output from tensor to output_type.
preprocessdiffusers.image_processor.VaeImageProcessor.preprocessPipelineImageInput) --
The image input, accepted formats are PIL images, NumPy arrays, PyTorch tensors; Also accept list of
supported formats.
- height (
int, optional) -- The height in preprocessed image. IfNone, will use theget_default_height_width()to get default height. - width (
int, optional) -- The width in preprocessed. IfNone, will use get_default_height_width()` to get the default width. - resize_mode (
str, optional, defaults todefault) -- The resize mode, can be one ofdefaultorfill. Ifdefault, will resize the image to fit within the specified width and height, and it may not maintaining the original aspect ratio. Iffill, will resize the image to fit within the specified width and height, maintaining the aspect ratio, and then center the image within the dimensions, filling empty with data from image. Ifcrop, will resize the image to fit within the specified width and height, maintaining the aspect ratio, and then center the image within the dimensions, cropping the excess. Note that resize_modefillandcropare only supported for PIL image input. - crops_coords (
List[Tuple[int, int, int, int]], optional, defaults toNone) -- The crop coordinates for each image in the batch. IfNone, will not crop the image.0torch.TensorThe preprocessed image.
Preprocess the image input.
pt_to_numpydiffusers.image_processor.VaeImageProcessor.pt_to_numpytorch.Tensor) --
The PyTorch tensor to convert to NumPy format.0np.ndarrayA NumPy array representation of the images.
Convert a PyTorch tensor to a NumPy image.
resizediffusers.image_processor.VaeImageProcessor.resizePIL.Image.Image, np.ndarray or torch.Tensor) --
The image input, can be a PIL image, numpy array or pytorch tensor.
- height (
int) -- The height to resize to. - width (
int) -- The width to resize to. - resize_mode (
str, optional, defaults todefault) -- The resize mode to use, can be one ofdefaultorfill. Ifdefault, will resize the image to fit within the specified width and height, and it may not maintaining the original aspect ratio. Iffill, will resize the image to fit within the specified width and height, maintaining the aspect ratio, and then center the image within the dimensions, filling empty with data from image. Ifcrop, will resize the image to fit within the specified width and height, maintaining the aspect ratio, and then center the image within the dimensions, cropping the excess. Note that resize_modefillandcropare only supported for PIL image input.0PIL.Image.Image,np.ndarrayortorch.TensorThe resized image.
Resize image.
InpaintProcessor[[diffusers.image_processor.InpaintProcessor]]
The InpaintProcessor accepts mask and image inputs and process them together. Optionally, it can accept padding_mask_crop and apply mask overlay.
class diffusers.image_processor.InpaintProcessordiffusers.image_processor.InpaintProcessor
Image processor for inpainting image and mask.
postprocessdiffusers.image_processor.InpaintProcessor.postprocess
Postprocess the image, optionally apply mask overlay
preprocessdiffusers.image_processor.InpaintProcessor.preprocess
Preprocess the image and mask.
VaeImageProcessorLDM3D[[diffusers.image_processor.VaeImageProcessorLDM3D]]
The VaeImageProcessorLDM3D accepts RGB and depth inputs and returns RGB and depth outputs.
class diffusers.image_processor.VaeImageProcessorLDM3Ddiffusers.image_processor.VaeImageProcessorLDM3Dbool, 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 to8) -- VAE scale factor. Ifdo_resizeisTrue, the image is automatically resized to multiples of this factor. - resample (
str, optional, defaults tolanczos) -- Resampling filter to use when resizing the image. - do_normalize (
bool, optional, defaults toTrue) -- Whether to normalize the image to [-1,1].0
Image processor for VAE LDM3D.
depth_pil_to_numpydiffusers.image_processor.VaeImageProcessorLDM3D.depth_pil_to_numpyUnion[List[PIL.Image.Image], PIL.Image.Image]) --
The input image or list of images to be converted.0np.ndarrayA NumPy array of the converted images.
Convert a PIL image or a list of PIL images to NumPy arrays.
numpy_to_depthdiffusers.image_processor.VaeImageProcessorLDM3D.numpy_to_depthnp.ndarray) --
The input NumPy array of depth images, which can be a single image or a batch.0List[PIL.Image.Image]A list of PIL images converted from the input NumPy depth images.
Convert a NumPy depth image or a batch of images to a list of PIL images.
numpy_to_pildiffusers.image_processor.VaeImageProcessorLDM3D.numpy_to_pilnp.ndarray) --
The input NumPy array of images, which can be a single image or a batch.0List[PIL.Image.Image]A list of PIL images converted from the input NumPy array.
Convert a NumPy image or a batch of images to a list of PIL images.
preprocessdiffusers.image_processor.VaeImageProcessorLDM3D.preprocessUnion[torch.Tensor, PIL.Image.Image, np.ndarray]) --
The RGB input image, which can be a single image or a batch.
- depth (
Union[torch.Tensor, PIL.Image.Image, np.ndarray]) -- The depth input image, which can be a single image or a batch. - height (
Optional[int], optional, defaults toNone) -- The desired height of the processed image. IfNone, defaults to the height of the input image. - width (
Optional[int], optional, defaults toNone) -- The desired width of the processed image. IfNone, defaults to the width of the input image. - target_res (
Optional[int], optional, defaults toNone) -- Target resolution for resizing the images. If specified, overrides height and width.0Tuple[torch.Tensor, torch.Tensor]A tuple containing the processed RGB and depth images as PyTorch tensors.
Preprocess the image input. Accepted formats are PIL images, NumPy arrays, or PyTorch tensors.
rgblike_to_depthmapdiffusers.image_processor.VaeImageProcessorLDM3D.rgblike_to_depthmap
Convert an RGB-like depth image to a depth map.
PixArtImageProcessor[[diffusers.image_processor.PixArtImageProcessor]]
class diffusers.image_processor.PixArtImageProcessordiffusers.image_processor.PixArtImageProcessorbool, 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 to8) -- VAE scale factor. Ifdo_resizeisTrue, the image is automatically resized to multiples of this factor. - resample (
str, optional, defaults tolanczos) -- Resampling filter to use when resizing the image. - do_normalize (
bool, optional, defaults toTrue) -- Whether to normalize the image to [-1,1]. - do_binarize (
bool, optional, defaults toFalse) -- Whether to binarize the image to 0/1. - do_convert_rgb (
bool, optional, defaults to beFalse) -- Whether to convert the images to RGB format. - do_convert_grayscale (
bool, optional, defaults to beFalse) -- Whether to convert the images to grayscale format.0
Image processor for PixArt image resize and crop.
classify_height_width_bindiffusers.image_processor.PixArtImageProcessor.classify_height_width_binint) -- The height of the image.
- width (
int) -- The width of the image. - ratios (
dict) -- A dictionary where keys are aspect ratios and values are tuples of (height, width).0Tuple[int, int]The closest binned height and width.
Returns the binned height and width based on the aspect ratio.
resize_and_crop_tensordiffusers.image_processor.PixArtImageProcessor.resize_and_crop_tensortorch.Tensor) --
A tensor of shape (N, C, H, W) where N is the batch size, C is the number of channels, H is the height,
and W is the width.
- new_width (
int) -- The desired width of the output images. - new_height (
int) -- The desired height of the output images.0torch.TensorA tensor containing the resized and cropped images.
Resizes and crops a tensor of images to the specified dimensions.
IPAdapterMaskProcessor[[diffusers.image_processor.IPAdapterMaskProcessor]]
class diffusers.image_processor.IPAdapterMaskProcessordiffusers.image_processor.IPAdapterMaskProcessorbool, 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 to8) -- VAE scale factor. Ifdo_resizeisTrue, the image is automatically resized to multiples of this factor. - resample (
str, optional, defaults tolanczos) -- Resampling filter to use when resizing the image. - do_normalize (
bool, optional, defaults toFalse) -- Whether to normalize the image to [-1,1]. - do_binarize (
bool, optional, defaults toTrue) -- Whether to binarize the image to 0/1. - do_convert_grayscale (
bool, optional, defaults to beTrue) -- Whether to convert the images to grayscale format.0
Image processor for IP Adapter image masks.
downsamplediffusers.image_processor.IPAdapterMaskProcessor.downsampletorch.Tensor) --
The input mask tensor generated with IPAdapterMaskProcessor.preprocess().
- batch_size (
int) -- The batch size. - num_queries (
int) -- The number of queries. - value_embed_dim (
int) -- The dimensionality of the value embeddings.0torch.TensorThe downsampled mask tensor.
Downsamples the provided mask tensor to match the expected dimensions for scaled dot-product attention. If the aspect ratio of the mask does not match the aspect ratio of the output image, a warning is issued.
Xet Storage Details
- Size:
- 35 kB
- Xet hash:
- 80307f772bd637fa955f2e029bf83bd5e6bf270fc891b8b55d9e9d48c10b3e8f
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.