text stringlengths 1 1.02k | class_index int64 0 1.38k | source stringclasses 431
values |
|---|---|---|
if safety_checker is not None and feature_extractor is None:
raise ValueError(
"Make sure to define a feature extractor when loading {self.__class__} if you want to use the safety"
" checker. If you do not want to use the safety checker, you can pass `'safety_checker=None'` i... | 87 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_inpaint.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,
image_enc... | 87 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_inpaint.py |
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline._encode_prompt
def _encode_prompt(
self,
prompt,
device,
num_images_per_prompt,
do_classifier_free_guidance,
negative_prompt=None,
prompt_embeds: Optional[torc... | 87 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_inpaint.py |
prompt_embeds_tuple = self.encode_prompt(
prompt=prompt,
device=device,
num_images_per_prompt=num_images_per_prompt,
do_classifier_free_guidance=do_classifier_free_guidance,
negative_prompt=negative_prompt,
prompt_embeds=prompt_embeds,
... | 87 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_inpaint.py |
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline.encode_prompt
def encode_prompt(
self,
prompt,
device,
num_images_per_prompt,
do_classifier_free_guidance,
negative_prompt=None,
prompt_embeds: Optional[torch.... | 87 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_inpaint.py |
Args:
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 (`b... | 87 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_inpaint.py |
negative_prompt_embeds (`torch.Tensor`, *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... | 87 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_inpaint.py |
# dynamically adjust the LoRA scale
if not USE_PEFT_BACKEND:
adjust_lora_scale_text_encoder(self.text_encoder, lora_scale)
else:
scale_lora_layers(self.text_encoder, lora_scale)
if prompt is not None and isinstance(prompt, str):
batch_size = 1... | 87 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_inpaint.py |
text_inputs = self.tokenizer(
prompt,
padding="max_length",
max_length=self.tokenizer.model_max_length,
truncation=True,
return_tensors="pt",
)
text_input_ids = text_inputs.input_ids
untruncated_ids = sel... | 87 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_inpaint.py |
if hasattr(self.text_encoder.config, "use_attention_mask") and self.text_encoder.config.use_attention_mask:
attention_mask = text_inputs.attention_mask.to(device)
else:
attention_mask = None | 87 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_inpaint.py |
if clip_skip is None:
prompt_embeds = self.text_encoder(text_input_ids.to(device), attention_mask=attention_mask)
prompt_embeds = prompt_embeds[0]
else:
prompt_embeds = self.text_encoder(
text_input_ids.to(device), attention_mask=attention_... | 87 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_inpaint.py |
prompt_embeds = self.text_encoder.text_model.final_layer_norm(prompt_embeds) | 87 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_inpaint.py |
if self.text_encoder is not None:
prompt_embeds_dtype = self.text_encoder.dtype
elif self.unet is not None:
prompt_embeds_dtype = self.unet.dtype
else:
prompt_embeds_dtype = prompt_embeds.dtype
prompt_embeds = prompt_embeds.to(dtype=prompt_embeds_dtype, devic... | 87 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_inpaint.py |
# get unconditional embeddings for classifier free guidance
if do_classifier_free_guidance and negative_prompt_embeds is None:
uncond_tokens: List[str]
if negative_prompt is None:
uncond_tokens = [""] * batch_size
elif prompt is not None and type(prompt) is no... | 87 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_inpaint.py |
" the batch size of `prompt`."
)
else:
uncond_tokens = negative_prompt | 87 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_inpaint.py |
# textual inversion: process multi-vector tokens if necessary
if isinstance(self, TextualInversionLoaderMixin):
uncond_tokens = self.maybe_convert_prompt(uncond_tokens, self.tokenizer)
max_length = prompt_embeds.shape[1]
uncond_input = self.tokenizer(
... | 87 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_inpaint.py |
if do_classifier_free_guidance:
# duplicate unconditional embeddings for each generation per prompt, using mps friendly method
seq_len = negative_prompt_embeds.shape[1]
negative_prompt_embeds = negative_prompt_embeds.to(dtype=prompt_embeds_dtype, device=device)
negative... | 87 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_inpaint.py |
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline.encode_image
def encode_image(self, image, device, num_images_per_prompt, output_hidden_states=None):
dtype = next(self.image_encoder.parameters()).dtype
if not isinstance(image, torch.Tensor):
... | 87 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_inpaint.py |
image = image.to(device=device, dtype=dtype)
if output_hidden_states:
image_enc_hidden_states = self.image_encoder(image, output_hidden_states=True).hidden_states[-2]
image_enc_hidden_states = image_enc_hidden_states.repeat_interleave(num_images_per_prompt, dim=0)
uncond_imag... | 87 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_inpaint.py |
# 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 = ... | 87 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_inpaint.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... | 87 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_inpaint.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]] * ... | 87 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_inpaint.py |
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline.run_safety_checker
def run_safety_checker(self, image, device, dtype):
if self.safety_checker is None:
has_nsfw_concept = None
else:
if torch.is_tensor(image):
... | 87 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_inpaint.py |
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline.decode_latents
def decode_latents(self, latents):
deprecation_message = "The decode_latents method is deprecated and will be removed in 1.0.0. Please use VaeImageProcessor.postprocess(...) instead"
d... | 87 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_inpaint.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... | 87 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_inpaint.py |
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion_img2img.StableDiffusionImg2ImgPipeline.get_timesteps
def get_timesteps(self, num_inference_steps, strength, device):
# get the original timestep using init_timestep
init_timestep = min(int(num_inference_steps * strength), n... | 87 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_inpaint.py |
def check_inputs(
self,
prompt,
image,
mask_image,
height,
width,
callback_steps,
output_type,
negative_prompt=None,
prompt_embeds=None,
negative_prompt_embeds=None,
ip_adapter_image=None,
ip_adapter_image_embeds=Non... | 87 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_inpaint.py |
if callback_on_step_end_tensor_inputs is not None and not all(
k in self._callback_tensor_inputs for k in callback_on_step_end_tensor_inputs
):
raise ValueError(
f"`callback_on_step_end_tensor_inputs` has to be in {self._callback_tensor_inputs}, but found {[k for k in cal... | 87 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_inpaint.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 is None and prompt_embeds is None:
... | 87 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_inpaint.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... | 87 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_inpaint.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):
... | 87 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_inpaint.py |
# `prompt` needs more sophisticated handling when there are multiple
# conditionings.
if isinstance(self.controlnet, MultiControlNetModel):
if isinstance(prompt, list):
logger.warning(
f"You have {len(self.controlnet.nets)} ControlNets and you have passed ... | 87 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_inpaint.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... | 87 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_inpaint.py |
# When `image` is a nested list:
# (e.g. [[canny_image_1, pose_image_1], [canny_image_2, pose_image_2]])
elif any(isinstance(i, list) for i in image):
raise ValueError("A single batch of multiple conditionings are supported at the moment.")
elif len(image) != len(self... | 87 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_inpaint.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(... | 87 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_inpaint.py |
raise ValueError(
"For multiple controlnets: When `controlnet_conditioning_scale` is specified as `list`, it must have"
" the same length as the number of controlnets"
)
else:
assert False | 87 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_inpaint.py |
if len(control_guidance_start) != len(control_guidance_end):
raise ValueError(
f"`control_guidance_start` has {len(control_guidance_start)} elements, but `control_guidance_end` has {len(control_guidance_end)} elements. Make sure to provide the same number of elements to each list."
... | 87 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_inpaint.py |
for start, end in zip(control_guidance_start, control_guidance_end):
if start >= end:
raise ValueError(
f"control guidance start: {start} cannot be larger or equal to control guidance end: {end}."
)
if start < 0.0:
raise ValueEr... | 87 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_inpaint.py |
if ip_adapter_image_embeds is not None:
if not isinstance(ip_adapter_image_embeds, list):
raise ValueError(
f"`ip_adapter_image_embeds` has to be of type `list` but is {type(ip_adapter_image_embeds)}"
)
elif ip_adapter_image_embeds[0].ndim not ... | 87 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_inpaint.py |
# Copied from diffusers.pipelines.controlnet.pipeline_controlnet.StableDiffusionControlNetPipeline.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 = isinstance(ima... | 87 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_inpaint.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... | 87 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_inpaint.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}"
)
def prepare_control_image... | 87 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_inpaint.py |
image = image.repeat_interleave(repeat_by, dim=0)
image = image.to(device=device, dtype=dtype)
if do_classifier_free_guidance and not guess_mode:
image = torch.cat([image] * 2)
return image | 87 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_inpaint.py |
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion_inpaint.StableDiffusionInpaintPipeline.prepare_latents
def prepare_latents(
self,
batch_size,
num_channels_latents,
height,
width,
dtype,
device,
generator,
latents=No... | 87 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_inpaint.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 ... | 87 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_inpaint.py |
if latents is None:
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, timestep)
... | 87 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_inpaint.py |
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion_inpaint.StableDiffusionInpaintPipeline.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 to la... | 87 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_inpaint.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... | 87 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_inpaint.py |
f" to a total batch size of {batch_size}, but {masked_image_latents.shape[0]} images were passed."
" Make sure the number of images that you pass is divisible by the total requested batch size."
)
masked_image_latents = masked_image_latents.repeat(batch_size // masked_ima... | 87 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_inpaint.py |
mask = torch.cat([mask] * 2) if do_classifier_free_guidance else mask
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
... | 87 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_inpaint.py |
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion_inpaint.StableDiffusionInpaintPipeline._encode_vae_image
def _encode_vae_image(self, image: torch.Tensor, generator: torch.Generator):
if isinstance(generator, list):
image_latents = [
retrieve_latents(s... | 87 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_inpaint.py |
# 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 = 1`
# corresponds to doing no classifier free guidance.
@property
def do_classifier_free_guidance(self):
return self._guidance_scale... | 87 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_inpaint.py |
@torch.no_grad()
@replace_example_docstring(EXAMPLE_DOC_STRING)
def __call__(
self,
prompt: Union[str, List[str]] = None,
image: PipelineImageInput = None,
mask_image: PipelineImageInput = None,
control_image: PipelineImageInput = None,
height: Optional[int] = Non... | 87 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_inpaint.py |
ip_adapter_image_embeds: Optional[List[torch.Tensor]] = None,
output_type: Optional[str] = "pil",
return_dict: bool = True,
cross_attention_kwargs: Optional[Dict[str, Any]] = None,
controlnet_conditioning_scale: Union[float, List[float]] = 0.5,
guess_mode: bool = False,
c... | 87 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_inpaint.py |
Args:
prompt (`str` or `List[str]`, *optional*):
The prompt or prompts to guide image generation. If not defined, you need to pass `prompt_embeds`.
image (`torch.Tensor`, `PIL.Image.Image`, `np.ndarray`, `List[torch.Tensor]`,
`List[PIL.Image.Image]`, or `List[... | 87 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_inpaint.py |
`List[PIL.Image.Image]`, or `List[np.ndarray]`):
`Image`, NumPy array or tensor representing an image batch to mask `image`. White pixels in the mask
are repainted while black pixels are preserved. If `mask_image` is a PIL image, it is converted to a
single channel (lumin... | 87 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_inpaint.py |
specified as `torch.Tensor`, it is passed to ControlNet as is. `PIL.Image.Image` can also be accepted
as an image. The dimensions of the output image defaults to `image`'s dimensions. If height and/or
width are passed, `image` is resized accordingly. If multiple ControlNets are specified... | 87 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_inpaint.py |
The size of margin in the crop to be applied to the image and masking. If `None`, no crop is applied to
image and mask_image. If `padding_mask_crop` is not `None`, it will first find a rectangular region
with the same aspect ration of the image and contains all masked area, and then expa... | 87 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_inpaint.py |
on the amount of noise initially added. When `strength` is 1, added noise is maximum and the denoising
process runs for the full number of iterations specified in `num_inference_steps`. A value of 1
essentially ignores `image`.
num_inference_steps (`int`, *optional*, defaults... | 87 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_inpaint.py |
pass `negative_prompt_embeds` instead. Ignored when not using guidance (`guidance_scale < 1`).
num_images_per_prompt (`int`, *optional*, defaults to 1):
The number of images to generate per prompt.
eta (`float`, *optional*, defaults to 0.0):
Corresponds to paramet... | 87 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_inpaint.py |
tensor is generated by sampling using the supplied random `generator`.
prompt_embeds (`torch.Tensor`, *optional*):
Pre-generated text embeddings. Can be used to easily tweak text inputs (prompt weighting). If not
provided, text embeddings are generated from the `prompt` input... | 87 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_inpaint.py |
IP-adapters. Each element should be a tensor of shape `(batch_size, num_images, emb_dim)`. It should
contain the negative image embedding if `do_classifier_free_guidance` is set to `True`. If not
provided, embeddings are computed from the `ip_adapter_image` input argument.
ou... | 87 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_inpaint.py |
controlnet_conditioning_scale (`float` or `List[float]`, *optional*, defaults to 0.5):
The outputs of the ControlNet are multiplied by `controlnet_conditioning_scale` before they are added
to the residual in the original `unet`. If multiple ControlNets are specified in `init`, you can se... | 87 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_inpaint.py |
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.
callback_on_step_end (`Callable`, `PipelineCallback`, `Mu... | 87 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_inpaint.py |
will be passed as `callback_kwargs` argument. You will only be able to include variables listed in the
`._callback_tensor_inputs` attribute of your pipeline class. | 87 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_inpaint.py |
Examples:
Returns:
[`~pipelines.stable_diffusion.StableDiffusionPipelineOutput`] or `tuple`:
If `return_dict` is `True`, [`~pipelines.stable_diffusion.StableDiffusionPipelineOutput`] is returned,
otherwise a `tuple` is returned where the first element is a list with ... | 87 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_inpaint.py |
if callback is not None:
deprecate(
"callback",
"1.0.0",
"Passing `callback` as an input argument to `__call__` is deprecated, consider using `callback_on_step_end`",
)
if callback_steps is not None:
deprecate(
"... | 87 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_inpaint.py |
# 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_start,... | 87 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_inpaint.py |
# 1. Check inputs. Raise error if not correct
self.check_inputs(
prompt,
control_image,
mask_image,
height,
width,
callback_steps,
output_type,
negative_prompt,
prompt_embeds,
negative_prompt_... | 87 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_inpaint.py |
# 2. Define call parameters
if prompt is not None and isinstance(prompt, str):
batch_size = 1
elif prompt is not None and isinstance(prompt, list):
batch_size = len(prompt)
else:
batch_size = prompt_embeds.shape[0]
if padding_mask_crop is not None:
... | 87 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_inpaint.py |
global_pool_conditions = (
controlnet.config.global_pool_conditions
if isinstance(controlnet, ControlNetModel)
else controlnet.nets[0].config.global_pool_conditions
)
guess_mode = guess_mode or global_pool_conditions | 87 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_inpaint.py |
# 3. Encode input prompt
text_encoder_lora_scale = (
self.cross_attention_kwargs.get("scale", None) if self.cross_attention_kwargs is not None else None
)
prompt_embeds, negative_prompt_embeds = self.encode_prompt(
prompt,
device,
num_images_per_pr... | 87 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_inpaint.py |
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_prompt,
self.do_classifi... | 87 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_inpaint.py |
# 4. Prepare image
if isinstance(controlnet, ControlNetModel):
control_image = self.prepare_control_image(
image=control_image,
width=width,
height=height,
batch_size=batch_size * num_images_per_prompt,
num_images_per_pr... | 87 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_inpaint.py |
for control_image_ in control_image:
control_image_ = self.prepare_control_image(
image=control_image_,
width=width,
height=height,
batch_size=batch_size * num_images_per_prompt,
num_images_per_prompt=num... | 87 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_inpaint.py |
# 4.1 Preprocess mask and image - resizes image and mask w.r.t height and width
original_image = image
init_image = self.image_processor.preprocess(
image, height=height, width=width, crops_coords=crops_coords, resize_mode=resize_mode
)
init_image = init_image.to(dtype=torch.... | 87 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_inpaint.py |
# 5. Prepare timesteps
self.scheduler.set_timesteps(num_inference_steps, device=device)
timesteps, num_inference_steps = self.get_timesteps(
num_inference_steps=num_inference_steps, strength=strength, device=device
)
# at which timestep to set the initial noise (n.b. 50% if s... | 87 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_inpaint.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
latents_outputs = self.prepare_latents(
batch_size * num_images_per_prompt,
num_chan... | 87 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_inpaint.py |
# 7. Prepare mask latent variables
mask, masked_image_latents = self.prepare_mask_latents(
mask,
masked_image,
batch_size * num_images_per_prompt,
height,
width,
prompt_embeds.dtype,
device,
generator,
se... | 87 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_inpaint.py |
# 7.2 Create tensor stating which controlnets to keep
controlnet_keep = []
for i in range(len(timesteps)):
keeps = [
1.0 - float(i / len(timesteps) < s or (i + 1) / len(timesteps) > e)
for s, e in zip(control_guidance_start, control_guidance_end)
]... | 87 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_inpaint.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)
... | 87 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_inpaint.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,
conditioning_scale=cond_scale,
gu... | 87 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_inpaint.py |
# predict the noise residual
if num_channels_unet == 9:
latent_model_input = torch.cat([latent_model_input, mask, masked_image_latents], dim=1)
noise_pred = self.unet(
latent_model_input,
t,
encoder_hidden_s... | 87 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_inpaint.py |
# compute the previous noisy sample x_t -> x_t-1
latents = self.scheduler.step(noise_pred, t, latents, **extra_step_kwargs, return_dict=False)[0]
if num_channels_unet == 4:
init_latents_proper = image_latents
if self.do_classifier_free_guidance:
... | 87 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_inpaint.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 = ... | 87 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_inpaint.py |
if XLA_AVAILABLE:
xm.mark_step()
# If we do sequential model offloading, let's offload unet and controlnet
# manually for max memory savings
if hasattr(self, "final_offload_hook") and self.final_offload_hook is not None:
self.unet.to("cpu")
self.contr... | 87 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_inpaint.py |
image = self.image_processor.postprocess(image, output_type=output_type, do_denormalize=do_denormalize)
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_mo... | 87 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet_inpaint.py |
class StableDiffusionControlNetPipeline(
DiffusionPipeline,
StableDiffusionMixin,
TextualInversionLoaderMixin,
StableDiffusionLoraLoaderMixin,
IPAdapterMixin,
FromSingleFileMixin,
):
r"""
Pipeline for text-to-image generation using Stable Diffusion with ControlNet guidance.
This mod... | 88 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet.py |
The pipeline also inherits the following loading methods:
- [`~loaders.TextualInversionLoaderMixin.load_textual_inversion`] for loading textual inversion embeddings
- [`~loaders.StableDiffusionLoraLoaderMixin.load_lora_weights`] for loading LoRA weights
- [`~loaders.StableDiffusionLoraLoaderMixi... | 88 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet.py |
Args:
vae ([`AutoencoderKL`]):
Variational Auto-Encoder (VAE) model to encode and decode images to and from latent representations.
text_encoder ([`~transformers.CLIPTextModel`]):
Frozen text-encoder ([clip-vit-large-patch14](https://huggingface.co/openai/clip-vit-large-patch14))... | 88 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet.py |
[`DDIMScheduler`], [`LMSDiscreteScheduler`], or [`PNDMScheduler`].
safety_checker ([`StableDiffusionSafetyChecker`]):
Classification module that estimates whether generated images could be considered offensive or harmful.
Please refer to the [model card](https://huggingface.co/stable-dif... | 88 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet.py |
model_cpu_offload_seq = "text_encoder->image_encoder->unet->vae"
_optional_components = ["safety_checker", "feature_extractor", "image_encoder"]
_exclude_from_cpu_offload = ["safety_checker"]
_callback_tensor_inputs = ["latents", "prompt_embeds", "negative_prompt_embeds"]
def __init__(
self,
... | 88 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet.py |
if safety_checker is None and requires_safety_checker:
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"
... | 88 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet.py |
if safety_checker is not None and feature_extractor is None:
raise ValueError(
"Make sure to define a feature extractor when loading {self.__class__} if you want to use the safety"
" checker. If you do not want to use the safety checker, you can pass `'safety_checker=None'` i... | 88 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_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,
image_enc... | 88 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet.py |
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline._encode_prompt
def _encode_prompt(
self,
prompt,
device,
num_images_per_prompt,
do_classifier_free_guidance,
negative_prompt=None,
prompt_embeds: Optional[torc... | 88 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet.py |
prompt_embeds_tuple = self.encode_prompt(
prompt=prompt,
device=device,
num_images_per_prompt=num_images_per_prompt,
do_classifier_free_guidance=do_classifier_free_guidance,
negative_prompt=negative_prompt,
prompt_embeds=prompt_embeds,
... | 88 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet.py |
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline.encode_prompt
def encode_prompt(
self,
prompt,
device,
num_images_per_prompt,
do_classifier_free_guidance,
negative_prompt=None,
prompt_embeds: Optional[torch.... | 88 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet.py |
Args:
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 (`b... | 88 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet.py |
negative_prompt_embeds (`torch.Tensor`, *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... | 88 | /Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/controlnet/pipeline_controlnet.py |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.