text
stringlengths
0
5.54k
>>> pipeline.enable_model_cpu_offload()
>>> mask_prompt = "A bowl of fruits"
>>> prompt = "A bowl of pears"
>>> mask_image = pipe.generate_mask(image=init_image, source_prompt=prompt, target_prompt=mask_prompt)
>>> image_latents = pipe.invert(image=init_image, prompt=mask_prompt).latents
>>> image = pipe(prompt=prompt, mask_image=mask_image, image_latents=image_latents).images[0] encode_prompt < source > ( prompt device num_images_per_prompt do_classifier_free_guidance negative_prompt = None prompt_embeds: Optional = None negative_prompt_embeds: Optional = None lora_scale: Optional = None clip_skip: Optional = None ) Parameters prompt (str or List[str], optional) β€”
prompt to be encoded
device β€” (torch.device):
torch device num_images_per_prompt (int) β€”
number of images that should be generated per prompt do_classifier_free_guidance (bool) β€”
whether to use classifier free guidance or not negative_prompt (str or List[str], optional) β€”
The prompt or prompts not to guide the image generation. If not defined, one has to pass
negative_prompt_embeds instead. Ignored when not using guidance (i.e., ignored if guidance_scale is
less than 1). prompt_embeds (torch.FloatTensor, optional) β€”
Pre-generated text embeddings. Can be used to easily tweak text inputs, e.g. prompt weighting. If not
provided, text embeddings will be generated from prompt input argument. negative_prompt_embeds (torch.FloatTensor, optional) β€”
Pre-generated negative text embeddings. Can be used to easily tweak text inputs, e.g. prompt
weighting. If not provided, negative_prompt_embeds will be generated from negative_prompt input
argument. lora_scale (float, optional) β€”
A LoRA scale that will be applied to all LoRA layers of the text encoder if LoRA layers are loaded. clip_skip (int, optional) β€”
Number of layers to be skipped from CLIP while computing the prompt embeddings. A value of 1 means that
the output of the pre-final layer will be used for computing the prompt embeddings. Encodes the prompt into text encoder hidden states. StableDiffusionPipelineOutput class diffusers.pipelines.stable_diffusion.StableDiffusionPipelineOutput < source > ( images: Union nsfw_content_detected: Optional ) Parameters images (List[PIL.Image.Image] or np.ndarray) β€”
List of denoised PIL images of length batch_size or NumPy array of shape (batch_size, height, width, num_channels). nsfw_content_detected (List[bool]) β€”
List indicating whether the corresponding generated image contains β€œnot-safe-for-work” (nsfw) content or
None if safety checking could not be performed. Output class for Stable Diffusion pipelines.
LMSDiscreteScheduler LMSDiscreteScheduler is a linear multistep scheduler for discrete beta schedules. The scheduler is ported from and created by Katherine Crowson, and the original implementation can be found at crowsonkb/k-diffusion. LMSDiscreteScheduler class diffusers.LMSDiscreteScheduler < source > ( num_train_timesteps: int = 1000 beta_start: float = 0.0001 beta_end: float = 0.02 beta_schedule: str = 'linear' trained_betas: Union = None use_karras_sigmas: Optional = False prediction_type: str = 'epsilon' timestep_spacing: str = 'linspace' steps_offset: int = 0 ) Parameters num_train_timesteps (int, defaults to 1000) β€”
The number of diffusion steps to train the model. beta_start (float, defaults to 0.0001) β€”
The starting beta value of inference. beta_end (float, defaults to 0.02) β€”
The final beta value. beta_schedule (str, defaults to "linear") β€”
The beta schedule, a mapping from a beta range to a sequence of betas for stepping the model. Choose from
linear or scaled_linear. trained_betas (np.ndarray, optional) β€”
Pass an array of betas directly to the constructor to bypass beta_start and beta_end. use_karras_sigmas (bool, optional, defaults to False) β€”
Whether to use Karras sigmas for step sizes in the noise schedule during the sampling process. If True,
the sigmas are determined according to a sequence of noise levels {Οƒi}. prediction_type (str, defaults to epsilon, optional) β€”
Prediction type of the scheduler function; can be epsilon (predicts the noise of the diffusion process),
sample (directly predicts the noisy sample) or v_prediction` (see section 2.4 of Imagen
Video paper). timestep_spacing (str, defaults to "linspace") β€”
The way the timesteps should be scaled. Refer to Table 2 of the Common Diffusion Noise Schedules and
Sample Steps are Flawed for more information. steps_offset (int, defaults to 0) β€”
An offset added to the inference steps. You can use a combination of offset=1 and
set_alpha_to_one=False to make the last step use step 0 for the previous alpha product like in Stable
Diffusion. A linear multistep scheduler for discrete beta schedules. This model inherits from SchedulerMixin and ConfigMixin. Check the superclass documentation for the generic
methods the library implements for all schedulers such as loading and saving. get_lms_coefficient < source > ( order t current_order ) Parameters order () β€” t () β€” current_order () β€” Compute the linear multistep coefficient. scale_model_input < source > ( sample: FloatTensor timestep: Union ) β†’ torch.FloatTensor Parameters sample (torch.FloatTensor) β€”
The input sample. timestep (float or torch.FloatTensor) β€”
The current timestep in the diffusion chain. Returns
torch.FloatTensor
A scaled input sample.
Ensures interchangeability with schedulers that need to scale the denoising model input depending on the
current timestep. set_timesteps < source > ( num_inference_steps: int device: Union = None ) Parameters num_inference_steps (int) β€”
The number of diffusion steps used when generating samples with a pre-trained model. device (str or torch.device, optional) β€”
The device to which the timesteps should be moved to. If None, the timesteps are not moved. Sets the discrete timesteps used for the diffusion chain (to be run before inference). step < source > ( model_output: FloatTensor timestep: Union sample: FloatTensor order: int = 4 return_dict: bool = True ) β†’ SchedulerOutput or tuple Parameters model_output (torch.FloatTensor) β€”
The direct output from learned diffusion model. timestep (float or torch.FloatTensor) β€”
The current discrete timestep in the diffusion chain. sample (torch.FloatTensor) β€”
A current instance of a sample created by the diffusion process. order (int, defaults to 4) β€”
The order of the linear multistep method. return_dict (bool, optional, defaults to True) β€”
Whether or not to return a SchedulerOutput or tuple. Returns
SchedulerOutput or tuple
If return_dict is True, SchedulerOutput is returned, otherwise a
tuple is returned where the first element is the sample tensor.
Predict the sample from the previous timestep by reversing the SDE. This function propagates the diffusion
process from the learned model outputs (most often the predicted noise). LMSDiscreteSchedulerOutput class diffusers.schedulers.scheduling_lms_discrete.LMSDiscreteSchedulerOutput < source > ( prev_sample: FloatTensor pred_original_sample: Optional = None ) Parameters prev_sample (torch.FloatTensor of shape (batch_size, num_channels, height, width) for images) β€”
Computed sample (x_{t-1}) of previous timestep. prev_sample should be used as next model input in the
denoising loop. pred_original_sample (torch.FloatTensor of shape (batch_size, num_channels, height, width) for images) β€”
The predicted denoised sample (x_{0}) based on the model output from the current timestep.
pred_original_sample can be used to preview progress or for guidance. Output class for the scheduler’s step function output.
RePaint RePaint: Inpainting using Denoising Diffusion Probabilistic Models is by Andreas Lugmayr, Martin Danelljan, Andres Romero, Fisher Yu, Radu Timofte, Luc Van Gool. The abstract from the paper is: Free-form inpainting is the task of adding new content to an image in the regions specified by an arbitrary binary mask. Most existing approaches train for a certain distribution of masks, which limits their generalization capabilities to unseen mask types. Furthermore, training with pixel-wise and perceptual losses often leads to simple textural extensions towards the missing areas instead of semantically meaningful generation. In this work, we propose RePaint: A Denoising Diffusion Probabilistic Model (DDPM) based inpainting approach that is applicable to even extreme masks. We employ a pretrained unconditional DDPM as the generative prior. To condition the generation process, we only alter the reverse diffusion iterations by sampling the unmasked regions using the given image information. Since this technique does not modify or condition the original DDPM network itself, the model produces high-quality and diverse output images for any inpainting form. We validate our method for both faces and general-purpose image inpainting using standard and extreme masks.
RePaint outperforms state-of-the-art Autoregressive, and GAN approaches for at least five out of six mask distributions. The original codebase can be found at andreas128/RePaint. Make sure to check out the Schedulers guide to learn how to explore the tradeoff between scheduler speed and quality, and see the reuse components across pipelines section to learn how to efficiently load the same components into multiple pipelines. RePaintPipeline class diffusers.RePaintPipeline < source > ( unet scheduler ) Parameters unet (UNet2DModel) β€”
A UNet2DModel to denoise the encoded image latents. scheduler (RePaintScheduler) β€”
A RePaintScheduler to be used in combination with unet to denoise the encoded image. Pipeline for image inpainting using RePaint. This model inherits from DiffusionPipeline. Check the superclass documentation for the generic methods
implemented for all pipelines (downloading, saving, running on a particular device, etc.). __call__ < source > ( image: typing.Union[torch.Tensor, PIL.Image.Image] mask_image: typing.Union[torch.Tensor, PIL.Image.Image] num_inference_steps: int = 250 eta: float = 0.0 jump_length: int = 10 jump_n_sample: int = 10 generator: typing.Union[torch._C.Generator, typing.List[torch._C.Generator], NoneType] = None output_type: typing.Optional[str] = 'pil' return_dict: bool = True ) β†’ ImagePipelineOutput or tuple Parameters image (torch.FloatTensor or PIL.Image.Image) β€”
The original image to inpaint on. mask_image (torch.FloatTensor or PIL.Image.Image) β€”
The mask_image where 0.0 define which part of the original image to inpaint. num_inference_steps (int, optional, defaults to 1000) β€”
The number of denoising steps. More denoising steps usually lead to a higher quality image at the
expense of slower inference. eta (float) β€”
The weight of the added noise in a diffusion step. Its value is between 0.0 and 1.0; 0.0 corresponds to
DDIM and 1.0 is the DDPM scheduler. jump_length (int, optional, defaults to 10) β€”
The number of steps taken forward in time before going backward in time for a single jump (β€œj” in
RePaint paper). Take a look at Figure 9 and 10 in the paper. jump_n_sample (int, optional, defaults to 10) β€”
The number of times to make a forward time jump for a given chosen time sample. Take a look at Figure 9
and 10 in the paper. generator (torch.Generator, optional) β€”
A torch.Generator to make
generation deterministic. output_type (str, optional, defaults to "pil") β€”
The output format of the generated image. Choose between PIL.Image or np.array. return_dict (bool, optional, defaults to True) β€”
Whether or not to return a ImagePipelineOutput instead of a plain tuple. Returns
ImagePipelineOutput or tuple
If return_dict is True, ImagePipelineOutput is returned, otherwise a tuple is
returned where the first element is a list with the generated images.
The call function to the pipeline for generation. Example: Copied >>> from io import BytesIO
>>> import torch
>>> import PIL
>>> import requests
>>> from diffusers import RePaintPipeline, RePaintScheduler
>>> def download_image(url):