diffengine.models.editors.stable_diffusion_inpaint

Submodules

Package Contents

Classes

SDInpaintDataPreprocessor

SDInpaintDataPreprocessor.

StableDiffusionInpaint

Stable Diffusion Inpaint.

class diffengine.models.editors.stable_diffusion_inpaint.SDInpaintDataPreprocessor(non_blocking=False)[source]

Bases: mmengine.model.base_model.data_preprocessor.BaseDataPreprocessor

SDInpaintDataPreprocessor.

Parameters:

non_blocking (Optional[bool]) –

forward(data, training=False)[source]

Preprocesses the data into the model input format.

After the data pre-processing of cast_data(), forward will stack the input tensor list to a batch tensor at the first dimension.

Args:

data (dict): Data returned by dataloader training (bool): Whether to enable training time augmentation.

Returns:

dict or list: Data in the same format as the model input.

Parameters:
  • data (dict) –

  • training (bool) –

Return type:

dict | list

class diffengine.models.editors.stable_diffusion_inpaint.StableDiffusionInpaint(*args, model='runwayml/stable-diffusion-inpainting', data_preprocessor=None, **kwargs)[source]

Bases: diffengine.models.editors.stable_diffusion.StableDiffusion

Stable Diffusion Inpaint.

Args:

model (str): pretrained model name of stable diffusion.

Defaults to ‘runwayml/stable-diffusion-v1-5’.

data_preprocessor (dict, optional): The pre-process config of

SDInpaintDataPreprocessor.

prepare_model()[source]

Prepare model for training.

Disable gradient for some models.

Return type:

None

infer(prompt, image, mask, negative_prompt=None, height=None, width=None, num_inference_steps=50, output_type='pil', **kwargs)[source]

Inference function.

Args:
prompt (List[str]):

The prompt or prompts to guide the image generation.

image (List[Union[str, Image.Image]]):

The image for inpainting.

mask (List[Union[str, Image.Image]]):

The mask for inpainting.

negative_prompt (Optional[str]):

The prompt or prompts to guide the image generation. Defaults to None.

height (int, optional):

The height in pixels of the generated image. Defaults to None.

width (int, optional):

The width in pixels of the generated image. Defaults to None.

num_inference_steps (int): Number of inference steps.

Defaults to 50.

output_type (str): The output format of the generate image.

Choose between ‘pil’ and ‘latent’. Defaults to ‘pil’.

**kwargs: Other arguments.

Parameters:
  • prompt (list[str]) –

  • image (list[str | PIL.Image.Image]) –

  • mask (list[str | PIL.Image.Image]) –

  • negative_prompt (str | None) –

  • height (int | None) –

  • width (int | None) –

  • num_inference_steps (int) –

  • output_type (str) –

Return type:

list[numpy.ndarray]

forward(inputs, data_samples=None, mode='loss')[source]

Forward function.

Args:

inputs (dict): The input dict. data_samples (Optional[list], optional): The data samples.

Defaults to None.

mode (str, optional): The mode. Defaults to “loss”.

Returns:

dict: The loss dict.

Parameters:
  • inputs (dict) –

  • data_samples (Optional[list]) –

  • mode (str) –

Return type:

dict

Parameters:
  • model (str) –

  • data_preprocessor (dict | torch.nn.Module | None) –