Diffusers documentation

Utilities

You are viewing main version, which requires installation from source. If you'd like regular pip install, checkout the latest stable version (v0.31.0).
Hugging Face's logo
Join the Hugging Face community

and get access to the augmented documentation experience

to get started

Utilities

Utility and helper functions for working with 🤗 Diffusers.

numpy_to_pil

diffusers.utils.numpy_to_pil

< >

( images )

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

pt_to_pil

diffusers.utils.pt_to_pil

< >

( images )

Convert a torch image to a PIL image.

load_image

diffusers.utils.load_image

< >

( image: typing.Union[str, PIL.Image.Image] convert_method: typing.Optional[typing.Callable[[PIL.Image.Image], PIL.Image.Image]] = None ) PIL.Image.Image

Parameters

  • image (str or PIL.Image.Image) — The image to convert to the PIL Image format.
  • convert_method (Callable[[PIL.Image.Image], PIL.Image.Image], optional) — A conversion method to apply to the image after loading it. When set to None the image will be converted “RGB”.

Returns

PIL.Image.Image

A PIL Image.

Loads image to a PIL Image.

export_to_gif

diffusers.utils.export_to_gif

< >

( image: typing.List[PIL.Image.Image] output_gif_path: str = None fps: int = 10 )

export_to_video

diffusers.utils.export_to_video

< >

( video_frames: typing.Union[typing.List[numpy.ndarray], typing.List[PIL.Image.Image]] output_video_path: str = None fps: int = 10 )

make_image_grid

diffusers.utils.make_image_grid

< >

( images: typing.List[PIL.Image.Image] rows: int cols: int resize: int = None )

Prepares a single grid of images. Useful for visualization purposes.

randn_tensor

diffusers.utils.torch_utils.randn_tensor

< >

( shape: typing.Union[typing.Tuple, typing.List] generator: typing.Union[typing.List[ForwardRef('torch.Generator')], ForwardRef('torch.Generator'), NoneType] = None device: typing.Optional[ForwardRef('torch.device')] = None dtype: typing.Optional[ForwardRef('torch.dtype')] = None layout: typing.Optional[ForwardRef('torch.layout')] = None )

A helper function to create random tensors on the desired device with the desired dtype. When passing a list of generators, you can seed each batch size individually. If CPU generators are passed, the tensor is always created on the CPU.

< > Update on GitHub