text stringlengths 1 1.02k | class_index int64 0 1.38k | source stringclasses 431
values |
|---|---|---|
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline.prepare_ip_adapter_image_embeds
def prepare_ip_adapter_image_embeds(
self, ip_adapter_image, ip_adapter_image_embeds, device, num_images_per_prompt, do_classifier_free_guidance
):
image_embeds = ... | 94 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_union_inpaint_sd_xl.py |
for single_ip_adapter_image, image_proj_layer in zip(
ip_adapter_image, self.unet.encoder_hid_proj.image_projection_layers
):
output_hidden_state = not isinstance(image_proj_layer, ImageProjection)
single_image_embeds, single_negative_image_embeds = self.encod... | 94 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_union_inpaint_sd_xl.py |
ip_adapter_image_embeds = []
for i, single_image_embeds in enumerate(image_embeds):
single_image_embeds = torch.cat([single_image_embeds] * num_images_per_prompt, dim=0)
if do_classifier_free_guidance:
single_negative_image_embeds = torch.cat([negative_image_embeds[i]] * ... | 94 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_union_inpaint_sd_xl.py |
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline.prepare_extra_step_kwargs
def prepare_extra_step_kwargs(self, generator, eta):
# prepare extra kwargs for the scheduler step, since not all schedulers have the same signature
# eta (η) is only used w... | 94 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_union_inpaint_sd_xl.py |
# Copied from diffusers.pipelines.controlnet.pipeline_controlnet_sd_xl.StableDiffusionXLControlNetPipeline.check_image
def check_image(self, image, prompt, prompt_embeds):
image_is_pil = isinstance(image, PIL.Image.Image)
image_is_tensor = isinstance(image, torch.Tensor)
image_is_np = isinst... | 94 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_union_inpaint_sd_xl.py |
if (
not image_is_pil
and not image_is_tensor
and not image_is_np
and not image_is_pil_list
and not image_is_tensor_list
and not image_is_np_list
):
raise TypeError(
f"image must be passed and be one of PIL image... | 94 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_union_inpaint_sd_xl.py |
if image_batch_size != 1 and image_batch_size != prompt_batch_size:
raise ValueError(
f"If image batch size is not 1, image batch size must be same as prompt batch size. image batch size: {image_batch_size}, prompt batch size: {prompt_batch_size}"
) | 94 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_union_inpaint_sd_xl.py |
def check_inputs(
self,
prompt,
prompt_2,
image,
mask_image,
strength,
num_inference_steps,
callback_steps,
output_type,
negative_prompt=None,
negative_prompt_2=None,
prompt_embeds=None,
negative_prompt_embeds=None,
... | 94 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_union_inpaint_sd_xl.py |
raise ValueError(
f"`num_inference_steps` has to be a positive integer but is {num_inference_steps} of type"
f" {type(num_inference_steps)}."
) | 94 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_union_inpaint_sd_xl.py |
if callback_steps is not None and (not isinstance(callback_steps, int) or callback_steps <= 0):
raise ValueError(
f"`callback_steps` has to be a positive integer but is {callback_steps} of type"
f" {type(callback_steps)}."
)
if callback_on_step_end_tensor... | 94 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_union_inpaint_sd_xl.py |
if prompt is not None and prompt_embeds is not None:
raise ValueError(
f"Cannot forward both `prompt`: {prompt} and `prompt_embeds`: {prompt_embeds}. Please make sure to"
" only forward one of the two."
)
elif prompt_2 is not None and prompt_embeds is not ... | 94 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_union_inpaint_sd_xl.py |
elif prompt_2 is not None and (not isinstance(prompt_2, str) and not isinstance(prompt_2, list)):
raise ValueError(f"`prompt_2` has to be of type `str` or `list` but is {type(prompt_2)}") | 94 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_union_inpaint_sd_xl.py |
if negative_prompt is not None and negative_prompt_embeds is not None:
raise ValueError(
f"Cannot forward both `negative_prompt`: {negative_prompt} and `negative_prompt_embeds`:"
f" {negative_prompt_embeds}. Please make sure to only forward one of the two."
)
... | 94 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_union_inpaint_sd_xl.py |
if prompt_embeds is not None and negative_prompt_embeds is not None:
if prompt_embeds.shape != negative_prompt_embeds.shape:
raise ValueError(
"`prompt_embeds` and `negative_prompt_embeds` must have the same shape when passed directly, but"
f" got: `pr... | 94 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_union_inpaint_sd_xl.py |
if padding_mask_crop is not None:
if not isinstance(image, PIL.Image.Image):
raise ValueError(
f"The image should be a PIL image when inpainting mask crop, but is of type" f" {type(image)}."
)
if not isinstance(mask_image, PIL.Image.Image):
... | 94 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_union_inpaint_sd_xl.py |
if negative_prompt_embeds is not None and negative_pooled_prompt_embeds is None:
raise ValueError(
"If `negative_prompt_embeds` are provided, `negative_pooled_prompt_embeds` also have to be passed. Make sure to generate `negative_pooled_prompt_embeds` from the same text encoder that was used... | 94 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_union_inpaint_sd_xl.py |
# Check `image`
is_compiled = hasattr(F, "scaled_dot_product_attention") and isinstance(
self.controlnet, torch._dynamo.eval_frame.OptimizedModule
)
if (
isinstance(self.controlnet, ControlNetModel)
or is_compiled
and isinstance(self.controlnet._or... | 94 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_union_inpaint_sd_xl.py |
# Check `controlnet_conditioning_scale`
if (
isinstance(self.controlnet, ControlNetModel)
or is_compiled
and isinstance(self.controlnet._orig_mod, ControlNetModel)
):
if not isinstance(controlnet_conditioning_scale, float):
raise TypeError(... | 94 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_union_inpaint_sd_xl.py |
if not isinstance(control_guidance_end, (tuple, list)):
control_guidance_end = [control_guidance_end]
if len(control_guidance_start) != len(control_guidance_end):
raise ValueError(
f"`control_guidance_start` has {len(control_guidance_start)} elements, but `control_guidan... | 94 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_union_inpaint_sd_xl.py |
if ip_adapter_image is not None and ip_adapter_image_embeds is not None:
raise ValueError(
"Provide either `ip_adapter_image` or `ip_adapter_image_embeds`. Cannot leave both `ip_adapter_image` and `ip_adapter_image_embeds` defined."
)
if ip_adapter_image_embeds is not No... | 94 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_union_inpaint_sd_xl.py |
# Copied from diffusers.pipelines.controlnet.pipeline_controlnet_inpaint_sd_xl.StableDiffusionXLControlNetInpaintPipeline.prepare_control_image
def prepare_control_image(
self,
image,
width,
height,
batch_size,
num_images_per_prompt,
device,
dtype,
... | 94 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_union_inpaint_sd_xl.py |
if do_classifier_free_guidance and not guess_mode:
image = torch.cat([image] * 2)
return image | 94 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_union_inpaint_sd_xl.py |
# Copied from diffusers.pipelines.controlnet.pipeline_controlnet_inpaint_sd_xl.StableDiffusionXLControlNetInpaintPipeline.prepare_latents
def prepare_latents(
self,
batch_size,
num_channels_latents,
height,
width,
dtype,
device,
generator,
late... | 94 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_union_inpaint_sd_xl.py |
) | 94 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_union_inpaint_sd_xl.py |
if (image is None or timestep is None) and not is_strength_max:
raise ValueError(
"Since strength < 1. initial latents are to be initialised as a combination of Image + Noise."
"However, either the image or the noise timestep has not been provided."
)
if ... | 94 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_union_inpaint_sd_xl.py |
if latents is None and add_noise:
noise = randn_tensor(shape, generator=generator, device=device, dtype=dtype)
# if strength is 1. then initialise the latents to noise, else initial to image + noise
latents = noise if is_strength_max else self.scheduler.add_noise(image_latents, noise... | 94 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_union_inpaint_sd_xl.py |
# Copied from diffusers.pipelines.controlnet.pipeline_controlnet_inpaint_sd_xl.StableDiffusionXLControlNetInpaintPipeline._encode_vae_image
def _encode_vae_image(self, image: torch.Tensor, generator: torch.Generator):
dtype = image.dtype
if self.vae.config.force_upcast:
image = image.flo... | 94 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_union_inpaint_sd_xl.py |
# Copied from diffusers.pipelines.controlnet.pipeline_controlnet_inpaint_sd_xl.StableDiffusionXLControlNetInpaintPipeline.prepare_mask_latents
def prepare_mask_latents(
self, mask, masked_image, batch_size, height, width, dtype, device, generator, do_classifier_free_guidance
):
# resize the mask... | 94 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_union_inpaint_sd_xl.py |
# duplicate mask and masked_image_latents for each generation per prompt, using mps friendly method
if mask.shape[0] < batch_size:
if not batch_size % mask.shape[0] == 0:
raise ValueError(
"The passed mask and the required batch size don't match. Masks are suppose... | 94 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_union_inpaint_sd_xl.py |
masked_image_latents = None
if masked_image is not None:
masked_image = masked_image.to(device=device, dtype=dtype)
masked_image_latents = self._encode_vae_image(masked_image, generator=generator)
if masked_image_latents.shape[0] < batch_size:
if not batch_siz... | 94 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_union_inpaint_sd_xl.py |
masked_image_latents = (
torch.cat([masked_image_latents] * 2) if do_classifier_free_guidance else masked_image_latents
)
# aligning device to prevent device errors when concating it with the latent model input
masked_image_latents = masked_image_latents.to(device=de... | 94 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_union_inpaint_sd_xl.py |
timesteps = self.scheduler.timesteps[t_start * self.scheduler.order :]
if hasattr(self.scheduler, "set_begin_index"):
self.scheduler.set_begin_index(t_start * self.scheduler.order)
return timesteps, num_inference_steps - t_start
else:
# Strength is irrelevan... | 94 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_union_inpaint_sd_xl.py |
num_inference_steps = (self.scheduler.timesteps < discrete_timestep_cutoff).sum().item()
if self.scheduler.order == 2 and num_inference_steps % 2 == 0:
# if the scheduler is a 2nd order scheduler we might have to do +1
# because `num_inference_steps` might be even given that ... | 94 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_union_inpaint_sd_xl.py |
# because t_n+1 >= t_n, we slice the timesteps starting from the end
t_start = len(self.scheduler.timesteps) - num_inference_steps
timesteps = self.scheduler.timesteps[t_start:]
if hasattr(self.scheduler, "set_begin_index"):
self.scheduler.set_begin_index(t_start)
... | 94 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_union_inpaint_sd_xl.py |
def _get_add_time_ids(
self,
original_size,
crops_coords_top_left,
target_size,
aesthetic_score,
negative_aesthetic_score,
dtype,
text_encoder_projection_dim=None,
):
if self.config.requires_aesthetics_score:
add_time_ids = list(ori... | 94 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_union_inpaint_sd_xl.py |
if (
expected_add_embed_dim > passed_add_embed_dim
and (expected_add_embed_dim - passed_add_embed_dim) == self.unet.config.addition_time_embed_dim
):
raise ValueError(
f"Model expects an added time embedding vector of length {expected_add_embed_dim}, but a vec... | 94 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_union_inpaint_sd_xl.py |
f"Model expects an added time embedding vector of length {expected_add_embed_dim}, but a vector of {passed_add_embed_dim} was created. Please make sure to disable `requires_aesthetics_score` with `pipe.register_to_config(requires_aesthetics_score=False)` to make sure `target_size` {target_size} is correctly used by the... | 94 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_union_inpaint_sd_xl.py |
add_time_ids = torch.tensor([add_time_ids], dtype=dtype)
add_neg_time_ids = torch.tensor([add_neg_time_ids], dtype=dtype)
return add_time_ids, add_neg_time_ids
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion_upscale.StableDiffusionUpscalePipeline.upcast_vae
def upc... | 94 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_union_inpaint_sd_xl.py |
@property
def guidance_scale(self):
return self._guidance_scale
@property
def clip_skip(self):
return self._clip_skip
# here `guidance_scale` is defined analog to the guidance weight `w` of equation (2)
# of the Imagen paper: https://arxiv.org/pdf/2205.11487.pdf . `guidance_scale =... | 94 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_union_inpaint_sd_xl.py |
@torch.no_grad()
@replace_example_docstring(EXAMPLE_DOC_STRING)
def __call__(
self,
prompt: Union[str, List[str]] = None,
prompt_2: Optional[Union[str, List[str]]] = None,
image: PipelineImageInput = None,
mask_image: PipelineImageInput = None,
control_image: Pipe... | 94 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_union_inpaint_sd_xl.py |
prompt_embeds: Optional[torch.Tensor] = None,
negative_prompt_embeds: Optional[torch.Tensor] = None,
ip_adapter_image: Optional[PipelineImageInput] = None,
ip_adapter_image_embeds: Optional[List[torch.Tensor]] = None,
pooled_prompt_embeds: Optional[torch.Tensor] = None,
negative_... | 94 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_union_inpaint_sd_xl.py |
aesthetic_score: float = 6.0,
negative_aesthetic_score: float = 2.5,
clip_skip: Optional[int] = None,
callback_on_step_end: Optional[
Union[Callable[[int, int, Dict], None], PipelineCallback, MultiPipelineCallbacks]
] = None,
callback_on_step_end_tensor_inputs: List[s... | 94 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_union_inpaint_sd_xl.py |
Args:
prompt (`str` or `List[str]`, *optional*):
The prompt or prompts to guide the image generation. If not defined, one has to pass `prompt_embeds`.
instead.
prompt_2 (`str` or `List[str]`, *optional*):
The prompt or prompts to be sent to the `to... | 94 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_union_inpaint_sd_xl.py |
to a single channel (luminance) before use. If it's a tensor, it should contain one color channel (L)
instead of 3, so the expected shape would be `(B, H, W, 1)`.
height (`int`, *optional*, defaults to self.unet.config.sample_size * self.vae_scale_factor):
The height in pixel... | 94 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_union_inpaint_sd_xl.py |
on `padding_mask_crop`. The image and mask_image will then be cropped based on the expanded area before
resizing to the original image size for inpainting. This is useful when the masked area is small while
the image is large and contain information irrelevant for inpainting, such as bac... | 94 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_union_inpaint_sd_xl.py |
portion of the reference `image`. Note that in the case of `denoising_start` being declared as an
integer, the value of `strength` will be ignored.
num_inference_steps (`int`, *optional*, defaults to 50):
The number of denoising steps. More denoising steps usually lead to a h... | 94 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_union_inpaint_sd_xl.py |
is integrated into a "Mixture of Denoisers" multi-pipeline setup, as detailed in [**Refining the Image
Output**](https://huggingface.co/docs/diffusers/api/pipelines/stable_diffusion/stable_diffusion_xl#refining-the-image-output).
denoising_end (`float`, *optional*):
When spec... | 94 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_union_inpaint_sd_xl.py |
Output**](https://huggingface.co/docs/diffusers/api/pipelines/stable_diffusion/stable_diffusion_xl#refining-the-image-output).
guidance_scale (`float`, *optional*, defaults to 7.5):
Guidance scale as defined in [Classifier-Free Diffusion Guidance](https://arxiv.org/abs/2207.12598).
... | 94 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_union_inpaint_sd_xl.py |
negative_prompt_2 (`str` or `List[str]`, *optional*):
The prompt or prompts not to guide the image generation to be sent to `tokenizer_2` and
`text_encoder_2`. If not defined, `negative_prompt` is used in both text-encoders
prompt_embeds (`torch.Tensor`, *optional*):
... | 94 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_union_inpaint_sd_xl.py |
ip_adapter_image_embeds (`List[torch.Tensor]`, *optional*):
Pre-generated image embeddings for IP-Adapter. It should be a list of length same as number of
IP-adapters. Each element should be a tensor of shape `(batch_size, num_images, emb_dim)`. It should
contain the nega... | 94 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_union_inpaint_sd_xl.py |
weighting. If not provided, pooled negative_prompt_embeds will be generated from `negative_prompt`
input argument.
num_images_per_prompt (`int`, *optional*, defaults to 1):
The number of images to generate per prompt.
eta (`float`, *optional*, defaults to 0.0):
... | 94 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_union_inpaint_sd_xl.py |
generation. Can be used to tweak the same generation with different prompts. If not provided, a latents
tensor will ge generated by sampling using the supplied random `generator`.
output_type (`str`, *optional*, defaults to `"pil"`):
The output format of the generate image. C... | 94 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_union_inpaint_sd_xl.py |
original_size (`Tuple[int]`, *optional*, defaults to (1024, 1024)):
If `original_size` is not the same as `target_size` the image will appear to be down- or upsampled.
`original_size` defaults to `(width, height)` if not specified. Part of SDXL's micro-conditioning as
exp... | 94 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_union_inpaint_sd_xl.py |
target_size (`Tuple[int]`, *optional*, defaults to (1024, 1024)):
For most cases, `target_size` should be set to the desired height and width of the generated image. If
not specified it will default to `(width, height)`. Part of SDXL's micro-conditioning as explained in
s... | 94 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_union_inpaint_sd_xl.py |
[https://huggingface.co/papers/2307.01952](https://huggingface.co/papers/2307.01952). Can be used to
simulate an aesthetic score of the generated image by influencing the negative text condition.
clip_skip (`int`, *optional*):
Number of layers to be skipped from CLIP while co... | 94 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_union_inpaint_sd_xl.py |
list of all tensors as specified by `callback_on_step_end_tensor_inputs`.
callback_on_step_end_tensor_inputs (`List`, *optional*):
The list of tensor inputs for the `callback_on_step_end` function. The tensors specified in the list
will be passed as `callback_kwargs` argument... | 94 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_union_inpaint_sd_xl.py |
Examples:
Returns:
[`~pipelines.stable_diffusion.StableDiffusionXLPipelineOutput`] or `tuple`:
[`~pipelines.stable_diffusion.StableDiffusionXLPipelineOutput`] if `return_dict` is True, otherwise a
`tuple. `tuple. When returning a tuple, the first element is a list with the g... | 94 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_union_inpaint_sd_xl.py |
if isinstance(callback_on_step_end, (PipelineCallback, MultiPipelineCallbacks)):
callback_on_step_end_tensor_inputs = callback_on_step_end.tensor_inputs
controlnet = self.controlnet._orig_mod if is_compiled_module(self.controlnet) else self.controlnet
# align format for control guidance
... | 94 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_union_inpaint_sd_xl.py |
# 0.1 align format for control guidance
if not isinstance(control_guidance_start, list) and isinstance(control_guidance_end, list):
control_guidance_start = len(control_guidance_end) * [control_guidance_start]
elif not isinstance(control_guidance_end, list) and isinstance(control_guidance_st... | 94 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_union_inpaint_sd_xl.py |
# 1. Check inputs
control_type = [0 for _ in range(num_control_type)]
for _image, control_idx in zip(control_image, control_mode):
control_type[control_idx] = 1
self.check_inputs(
prompt,
prompt_2,
_image,
mask_image... | 94 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_union_inpaint_sd_xl.py |
control_type = torch.Tensor(control_type)
self._guidance_scale = guidance_scale
self._clip_skip = clip_skip
self._cross_attention_kwargs = cross_attention_kwargs
self._interrupt = False
# 2. Define call parameters
if prompt is not None and isinstance(prompt, str):
... | 94 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_union_inpaint_sd_xl.py |
(
prompt_embeds,
negative_prompt_embeds,
pooled_prompt_embeds,
negative_pooled_prompt_embeds,
) = self.encode_prompt(
prompt=prompt,
prompt_2=prompt_2,
device=device,
num_images_per_prompt=num_images_per_prompt,
... | 94 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_union_inpaint_sd_xl.py |
# 3.1 Encode ip_adapter_image
if ip_adapter_image is not None or ip_adapter_image_embeds is not None:
image_embeds = self.prepare_ip_adapter_image_embeds(
ip_adapter_image,
ip_adapter_image_embeds,
device,
batch_size * num_images_per_pr... | 94 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_union_inpaint_sd_xl.py |
self.scheduler.set_timesteps(num_inference_steps, device=device)
timesteps, num_inference_steps = self.get_timesteps(
num_inference_steps,
strength,
device,
denoising_start=denoising_start if denoising_value_valid(denoising_start) else None,
)
# ch... | 94 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_union_inpaint_sd_xl.py |
is_strength_max = strength == 1.0
self._num_timesteps = len(timesteps) | 94 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_union_inpaint_sd_xl.py |
# 5. Preprocess mask and image - resizes image and mask w.r.t height and width
# 5.1 Prepare init image
if padding_mask_crop is not None:
height, width = self.image_processor.get_default_height_width(image, height, width)
crops_coords = self.mask_processor.get_crop_region(mask_im... | 94 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_union_inpaint_sd_xl.py |
# 5.2 Prepare control images
for idx, _ in enumerate(control_image):
control_image[idx] = self.prepare_control_image(
image=control_image[idx],
width=width,
height=height,
batch_size=batch_size * num_images_per_prompt,
n... | 94 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_union_inpaint_sd_xl.py |
# 6. Prepare latent variables
num_channels_latents = self.vae.config.latent_channels
num_channels_unet = self.unet.config.in_channels
return_image_latents = num_channels_unet == 4
add_noise = True if denoising_start is None else False
latents_outputs = self.prepare_latents(
... | 94 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_union_inpaint_sd_xl.py |
# 7. Prepare mask latent variables
mask, _ = self.prepare_mask_latents(
mask,
masked_image,
batch_size * num_images_per_prompt,
height,
width,
prompt_embeds.dtype,
device,
generator,
self.do_classifier_fr... | 94 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_union_inpaint_sd_xl.py |
# 8.2 Create tensor stating which controlnets to keep
controlnet_keep = []
for i in range(len(timesteps)):
controlnet_keep.append(
1.0
- float(i / len(timesteps) < control_guidance_start or (i + 1) / len(timesteps) > control_guidance_end)
)
... | 94 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_union_inpaint_sd_xl.py |
# 10. Prepare added time ids & embeddings
add_text_embeds = pooled_prompt_embeds
if self.text_encoder_2 is None:
text_encoder_projection_dim = int(pooled_prompt_embeds.shape[-1])
else:
text_encoder_projection_dim = self.text_encoder_2.config.projection_dim
add_ti... | 94 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_union_inpaint_sd_xl.py |
if self.do_classifier_free_guidance:
prompt_embeds = torch.cat([negative_prompt_embeds, prompt_embeds], dim=0)
add_text_embeds = torch.cat([negative_pooled_prompt_embeds, add_text_embeds], dim=0)
add_neg_time_ids = add_neg_time_ids.repeat(batch_size * num_images_per_prompt, 1)
... | 94 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_union_inpaint_sd_xl.py |
if (
denoising_end is not None
and denoising_start is not None
and denoising_value_valid(denoising_end)
and denoising_value_valid(denoising_start)
and denoising_start >= denoising_end
):
raise ValueError(
f"`denoising_start`... | 94 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_union_inpaint_sd_xl.py |
control_type = (
control_type.reshape(1, -1)
.to(device, dtype=prompt_embeds.dtype)
.repeat(batch_size * num_images_per_prompt * 2, 1)
)
with self.progress_bar(total=num_inference_steps) as progress_bar:
for i, t in enumerate(timesteps):
if... | 94 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_union_inpaint_sd_xl.py |
# controlnet(s) inference
if guess_mode and self.do_classifier_free_guidance:
# Infer ControlNet only for the conditional batch.
control_model_input = latents
control_model_input = self.scheduler.scale_model_input(control_model_input, t)
... | 94 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_union_inpaint_sd_xl.py |
if isinstance(controlnet_keep[i], list):
cond_scale = [c * s for c, s in zip(controlnet_conditioning_scale, controlnet_keep[i])]
else:
controlnet_cond_scale = controlnet_conditioning_scale
if isinstance(controlnet_cond_scale, list):
... | 94 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_union_inpaint_sd_xl.py |
down_block_res_samples, mid_block_res_sample = self.controlnet(
control_model_input,
t,
encoder_hidden_states=controlnet_prompt_embeds,
controlnet_cond=control_image,
control_type=control_type,
contro... | 94 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_union_inpaint_sd_xl.py |
if guess_mode and self.do_classifier_free_guidance:
# Inferred ControlNet only for the conditional batch.
# To apply the output of ControlNet to both the unconditional and conditional batches,
# add 0 to the unconditional batch to keep it unchanged.
... | 94 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_union_inpaint_sd_xl.py |
# predict the noise residual
noise_pred = self.unet(
latent_model_input,
t,
encoder_hidden_states=prompt_embeds,
cross_attention_kwargs=self.cross_attention_kwargs,
down_block_additional_residuals=down_bl... | 94 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_union_inpaint_sd_xl.py |
if self.do_classifier_free_guidance and guidance_rescale > 0.0:
# Based on 3.4. in https://arxiv.org/pdf/2305.08891.pdf
noise_pred = rescale_noise_cfg(noise_pred, noise_pred_text, guidance_rescale=guidance_rescale)
# compute the previous noisy sample x_t -> x_t-1... | 94 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_union_inpaint_sd_xl.py |
if callback_on_step_end is not None:
callback_kwargs = {}
for k in callback_on_step_end_tensor_inputs:
callback_kwargs[k] = locals()[k]
callback_outputs = callback_on_step_end(self, i, t, callback_kwargs)
latents = ... | 94 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_union_inpaint_sd_xl.py |
if XLA_AVAILABLE:
xm.mark_step()
# make sure the VAE is in float32 mode, as it overflows in float16
if self.vae.dtype == torch.float16 and self.vae.config.force_upcast:
self.upcast_vae()
latents = latents.to(next(iter(self.vae.post_quant_conv.parameters())).d... | 94 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_union_inpaint_sd_xl.py |
image = self.image_processor.postprocess(image, output_type=output_type)
if padding_mask_crop is not None:
image = [self.image_processor.apply_overlay(mask_image, original_image, i, crops_coords) for i in image]
# Offload all models
self.maybe_free_model_hooks()
if not ret... | 94 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_union_inpaint_sd_xl.py |
class FlaxStableDiffusionControlNetPipeline(FlaxDiffusionPipeline):
r"""
Flax-based pipeline for text-to-image generation using Stable Diffusion with ControlNet Guidance.
This model inherits from [`FlaxDiffusionPipeline`]. Check the superclass documentation for the generic methods
implemented for all p... | 95 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_flax_controlnet.py |
Args:
vae ([`FlaxAutoencoderKL`]):
Variational Auto-Encoder (VAE) model to encode and decode images to and from latent representations.
text_encoder ([`~transformers.FlaxCLIPTextModel`]):
Frozen text-encoder ([clip-vit-large-patch14](https://huggingface.co/openai/clip-vit-large-p... | 95 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_flax_controlnet.py |
safety_checker ([`FlaxStableDiffusionSafetyChecker`]):
Classification module that estimates whether generated images could be considered offensive or harmful.
Please refer to the [model card](https://huggingface.co/stable-diffusion-v1-5/stable-diffusion-v1-5) for
more details about a... | 95 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_flax_controlnet.py |
def __init__(
self,
vae: FlaxAutoencoderKL,
text_encoder: FlaxCLIPTextModel,
tokenizer: CLIPTokenizer,
unet: FlaxUNet2DConditionModel,
controlnet: FlaxControlNetModel,
scheduler: Union[
FlaxDDIMScheduler, FlaxPNDMScheduler, FlaxLMSDiscreteScheduler, Fl... | 95 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_flax_controlnet.py |
if safety_checker is None:
logger.warning(
f"You have disabled the safety checker for {self.__class__} by passing `safety_checker=None`. Ensure"
" that you abide to the conditions of the Stable Diffusion license and do not expose unfiltered"
" results in servi... | 95 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_flax_controlnet.py |
self.register_modules(
vae=vae,
text_encoder=text_encoder,
tokenizer=tokenizer,
unet=unet,
controlnet=controlnet,
scheduler=scheduler,
safety_checker=safety_checker,
feature_extractor=feature_extractor,
)
sel... | 95 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_flax_controlnet.py |
def prepare_image_inputs(self, image: Union[Image.Image, List[Image.Image]]):
if not isinstance(image, (Image.Image, list)):
raise ValueError(f"image has to be of type `PIL.Image.Image` or list but is {type(image)}")
if isinstance(image, Image.Image):
image = [image]
pr... | 95 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_flax_controlnet.py |
if jit:
features = shard(features)
has_nsfw_concepts = _p_get_has_nsfw_concepts(self, features, safety_model_params)
has_nsfw_concepts = unshard(has_nsfw_concepts)
safety_model_params = unreplicate(safety_model_params)
else:
has_nsfw_concepts = self._g... | 95 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_flax_controlnet.py |
return images, has_nsfw_concepts
def _generate(
self,
prompt_ids: jnp.ndarray,
image: jnp.ndarray,
params: Union[Dict, FrozenDict],
prng_seed: jax.Array,
num_inference_steps: int,
guidance_scale: float,
latents: Optional[jnp.ndarray] = None,
n... | 95 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_flax_controlnet.py |
max_length = prompt_ids.shape[-1]
if neg_prompt_ids is None:
uncond_input = self.tokenizer(
[""] * batch_size, padding="max_length", max_length=max_length, return_tensors="np"
).input_ids
else:
uncond_input = neg_prompt_ids
negative_prompt_emb... | 95 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_flax_controlnet.py |
def loop_body(step, args):
latents, scheduler_state = args
# For classifier free guidance, we need to do two forward passes.
# Here we concatenate the unconditional and text embeddings into a single batch
# to avoid doing two forward passes
latents_input = jnp... | 95 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_flax_controlnet.py |
down_block_res_samples, mid_block_res_sample = self.controlnet.apply(
{"params": params["controlnet"]},
jnp.array(latents_input),
jnp.array(timestep, dtype=jnp.int32),
encoder_hidden_states=context,
controlnet_cond=image,
co... | 95 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_flax_controlnet.py |
# perform guidance
noise_pred_uncond, noise_prediction_text = jnp.split(noise_pred, 2, axis=0)
noise_pred = noise_pred_uncond + guidance_scale * (noise_prediction_text - noise_pred_uncond)
# compute the previous noisy sample x_t -> x_t-1
latents, scheduler_state = self.s... | 95 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_flax_controlnet.py |
if DEBUG:
# run with python for loop
for i in range(num_inference_steps):
latents, scheduler_state = loop_body(i, (latents, scheduler_state))
else:
latents, _ = jax.lax.fori_loop(0, num_inference_steps, loop_body, (latents, scheduler_state))
# scale a... | 95 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_flax_controlnet.py |
@replace_example_docstring(EXAMPLE_DOC_STRING)
def __call__(
self,
prompt_ids: jnp.ndarray,
image: jnp.ndarray,
params: Union[Dict, FrozenDict],
prng_seed: jax.Array,
num_inference_steps: int = 50,
guidance_scale: Union[float, jnp.ndarray] = 7.5,
laten... | 95 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_flax_controlnet.py |
Args:
prompt_ids (`jnp.ndarray`):
The prompt or prompts to guide the image generation.
image (`jnp.ndarray`):
Array representing the ControlNet input condition to provide guidance to the `unet` for generation.
params (`Dict` or `FrozenDict`):
... | 95 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_flax_controlnet.py |
latents (`jnp.ndarray`, *optional*):
Pre-generated noisy latents sampled from a Gaussian distribution, to be used as inputs for image
generation. Can be used to tweak the same generation with different prompts. If not provided, a latents
array is generated by sampling usi... | 95 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_flax_controlnet.py |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.