RePaint
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
( unetscheduler )
Parameters
unet (UNet2DModel) — A
UNet2DModel
to denoise the encoded image latents.scheduler (RePaintScheduler) — A
RePaintScheduler
to be used in combination withunet
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__
( image: typing.Union[torch.Tensor, PIL.Image.Image]mask_image: typing.Union[torch.Tensor, PIL.Image.Image]num_inference_steps: int = 250eta: float = 0.0jump_length: int = 10jump_n_sample: int = 10generator: typing.Union[torch._C.Generator, typing.List[torch._C.Generator], NoneType] = Noneoutput_type: typing.Optional[str] = 'pil'return_dict: bool = True ) → ImagePipelineOutput or tuple
Parameters
image (
torch.FloatTensor
orPIL.Image.Image
) — The original image to inpaint on.mask_image (
torch.FloatTensor
orPIL.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) — Atorch.Generator
to make generation deterministic.output_type (
str
,optional
, defaults to"pil"
) — The output format of the generated image. Choose betweenPIL.Image
ornp.array
.return_dict (
bool
, optional, defaults toTrue
) — 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
ImagePipelineOutput
class diffusers.ImagePipelineOutput
( images: typing.Union[typing.List[PIL.Image.Image], numpy.ndarray] )
Parameters
images (
List[PIL.Image.Image]
ornp.ndarray
) — List of denoised PIL images of lengthbatch_size
or NumPy array of shape(batch_size, height, width, num_channels)
.
Output class for image pipelines.
Last updated