text
stringlengths
1
1.02k
class_index
int64
0
1.38k
source
stringclasses
431 values
Paper](https://arxiv.org/pdf/2205.11487.pdf). Guidance scale is enabled by setting `guidance_scale > 1`. Higher guidance scale encourages to generate images that are closely linked to the text `prompt`, usually at the expense of lower image quality. negative_prompt (`str` or ...
311
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/deepfloyd_if/pipeline_if.py
The width in pixels of the generated image. eta (`float`, *optional*, defaults to 0.0): Corresponds to parameter eta (η) in the DDIM paper: https://arxiv.org/abs/2010.02502. Only applies to [`schedulers.DDIMScheduler`], will be ignored for others. generator (`torc...
311
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/deepfloyd_if/pipeline_if.py
weighting. If not provided, negative_prompt_embeds will be generated from `negative_prompt` input argument. output_type (`str`, *optional*, defaults to `"pil"`): The output format of the generate image. Choose between [PIL](https://pillow.readthedocs.io/en/sta...
311
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/deepfloyd_if/pipeline_if.py
called at every step. clean_caption (`bool`, *optional*, defaults to `True`): Whether or not to clean the caption before creating embeddings. Requires `beautifulsoup4` and `ftfy` to be installed. If the dependencies are not installed, the embeddings will be created from the r...
311
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/deepfloyd_if/pipeline_if.py
Examples: Returns: [`~pipelines.stable_diffusion.IFPipelineOutput`] or `tuple`: [`~pipelines.stable_diffusion.IFPipelineOutput`] if `return_dict` is True, otherwise a `tuple. When returning a tuple, the first element is a list with the generated images, and the second elemen...
311
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/deepfloyd_if/pipeline_if.py
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] device = self._execution_device # here `guidance_scale` is defi...
311
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/deepfloyd_if/pipeline_if.py
# 3. Encode input prompt prompt_embeds, negative_prompt_embeds = self.encode_prompt( prompt, do_classifier_free_guidance, num_images_per_prompt=num_images_per_prompt, device=device, negative_prompt=negative_prompt, prompt_embeds=prompt_embe...
311
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/deepfloyd_if/pipeline_if.py
if hasattr(self.scheduler, "set_begin_index"): self.scheduler.set_begin_index(0) # 5. Prepare intermediate images intermediate_images = self.prepare_intermediate_images( batch_size * num_images_per_prompt, self.unet.config.in_channels, height, ...
311
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/deepfloyd_if/pipeline_if.py
# 7. Denoising loop num_warmup_steps = len(timesteps) - num_inference_steps * self.scheduler.order with self.progress_bar(total=num_inference_steps) as progress_bar: for i, t in enumerate(timesteps): model_input = ( torch.cat([intermediate_images] * 2) if ...
311
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/deepfloyd_if/pipeline_if.py
# perform guidance if do_classifier_free_guidance: noise_pred_uncond, noise_pred_text = noise_pred.chunk(2) noise_pred_uncond, _ = noise_pred_uncond.split(model_input.shape[1], dim=1) noise_pred_text, predicted_variance = noise_pred_text.split(...
311
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/deepfloyd_if/pipeline_if.py
# call the callback, if provided if i == len(timesteps) - 1 or ((i + 1) > num_warmup_steps and (i + 1) % self.scheduler.order == 0): progress_bar.update() if callback is not None and i % callback_steps == 0: callback(i, t, intermediate_imag...
311
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/deepfloyd_if/pipeline_if.py
# 11. Apply watermark if self.watermarker is not None: image = self.watermarker.apply_watermark(image, self.unet.config.sample_size) elif output_type == "pt": nsfw_detected = None watermark_detected = None if hasattr(self, "unet_offload_hook") and...
311
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/deepfloyd_if/pipeline_if.py
class IFImg2ImgPipeline(DiffusionPipeline, StableDiffusionLoraLoaderMixin): tokenizer: T5Tokenizer text_encoder: T5EncoderModel unet: UNet2DConditionModel scheduler: DDPMScheduler feature_extractor: Optional[CLIPImageProcessor] safety_checker: Optional[IFSafetyChecker] watermarker: Option...
312
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/deepfloyd_if/pipeline_if_img2img.py
def __init__( self, tokenizer: T5Tokenizer, text_encoder: T5EncoderModel, unet: UNet2DConditionModel, scheduler: DDPMScheduler, safety_checker: Optional[IFSafetyChecker], feature_extractor: Optional[CLIPImageProcessor], watermarker: Optional[IFWatermarker]...
312
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/deepfloyd_if/pipeline_if_img2img.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 IF license and do not expose unfiltered" " re...
312
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/deepfloyd_if/pipeline_if_img2img.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...
312
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/deepfloyd_if/pipeline_if_img2img.py
@torch.no_grad() def encode_prompt( self, prompt: Union[str, List[str]], do_classifier_free_guidance: bool = True, num_images_per_prompt: int = 1, device: Optional[torch.device] = None, negative_prompt: Optional[Union[str, List[str]]] = None, prompt_embeds: Op...
312
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/deepfloyd_if/pipeline_if_img2img.py
Args: prompt (`str` or `List[str]`, *optional*): prompt to be encoded do_classifier_free_guidance (`bool`, *optional*, defaults to `True`): whether to use classifier free guidance or not num_images_per_prompt (`int`, *optional*, defaults to 1): ...
312
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/deepfloyd_if/pipeline_if_img2img.py
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.Tensor`, *optional*): Pre-generated negative text embeddings. Can b...
312
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/deepfloyd_if/pipeline_if_img2img.py
if device is None: device = self._execution_device 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] ...
312
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/deepfloyd_if/pipeline_if_img2img.py
if untruncated_ids.shape[-1] >= text_input_ids.shape[-1] and not torch.equal( text_input_ids, untruncated_ids ): removed_text = self.tokenizer.batch_decode(untruncated_ids[:, max_length - 1 : -1]) logger.warning( "The following part of your...
312
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/deepfloyd_if/pipeline_if_img2img.py
bs_embed, seq_len, _ = prompt_embeds.shape # duplicate text embeddings for each generation per prompt, using mps friendly method prompt_embeds = prompt_embeds.repeat(1, num_images_per_prompt, 1) prompt_embeds = prompt_embeds.view(bs_embed * num_images_per_prompt, seq_len, -1)
312
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/deepfloyd_if/pipeline_if_img2img.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 isinstance(negative_prompt, str): ...
312
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/deepfloyd_if/pipeline_if_img2img.py
uncond_tokens = self._text_preprocessing(uncond_tokens, clean_caption=clean_caption) max_length = prompt_embeds.shape[1] uncond_input = self.tokenizer( uncond_tokens, padding="max_length", max_length=max_length, truncation=True, ...
312
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/deepfloyd_if/pipeline_if_img2img.py
negative_prompt_embeds = negative_prompt_embeds.to(dtype=dtype, device=device) negative_prompt_embeds = negative_prompt_embeds.repeat(1, num_images_per_prompt, 1) negative_prompt_embeds = negative_prompt_embeds.view(batch_size * num_images_per_prompt, seq_len, -1) # For classifier ...
312
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/deepfloyd_if/pipeline_if_img2img.py
# Copied from diffusers.pipelines.deepfloyd_if.pipeline_if.IFPipeline.run_safety_checker def run_safety_checker(self, image, device, dtype): if self.safety_checker is not None: safety_checker_input = self.feature_extractor(self.numpy_to_pil(image), return_tensors="pt").to(device) ima...
312
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/deepfloyd_if/pipeline_if_img2img.py
# Copied from diffusers.pipelines.deepfloyd_if.pipeline_if.IFPipeline.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 with the DDIMScheduler, it will ...
312
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/deepfloyd_if/pipeline_if_img2img.py
def check_inputs( self, prompt, image, batch_size, callback_steps, negative_prompt=None, prompt_embeds=None, negative_prompt_embeds=None, ): if (callback_steps is None) or ( callback_steps is not None and (not isinstance(callback_st...
312
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/deepfloyd_if/pipeline_if_img2img.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: ...
312
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/deepfloyd_if/pipeline_if_img2img.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...
312
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/deepfloyd_if/pipeline_if_img2img.py
if isinstance(image, list): image_batch_size = len(image) elif isinstance(image, torch.Tensor): image_batch_size = image.shape[0] elif isinstance(image, PIL.Image.Image): image_batch_size = 1 elif isinstance(image, np.ndarray): image_batch_size = i...
312
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/deepfloyd_if/pipeline_if_img2img.py
if clean_caption and not is_ftfy_available(): logger.warning(BACKENDS_MAPPING["ftfy"][-1].format("Setting `clean_caption=True`")) logger.warning("Setting `clean_caption` to False...") clean_caption = False if not isinstance(text, (tuple, list)): text = [text] ...
312
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/deepfloyd_if/pipeline_if_img2img.py
# Copied from diffusers.pipelines.deepfloyd_if.pipeline_if.IFPipeline._clean_caption def _clean_caption(self, caption): caption = str(caption) caption = ul.unquote_plus(caption) caption = caption.strip().lower() caption = re.sub("<person>", "person", caption) # urls: ...
312
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/deepfloyd_if/pipeline_if_img2img.py
# 31C0—31EF CJK Strokes # 31F0—31FF Katakana Phonetic Extensions # 3200—32FF Enclosed CJK Letters and Months # 3300—33FF CJK Compatibility # 3400—4DBF CJK Unified Ideographs Extension A # 4DC0—4DFF Yijing Hexagram Symbols # 4E00—9FFF CJK Unified Ideographs caption...
312
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/deepfloyd_if/pipeline_if_img2img.py
# все виды тире / all types of dash --> "-" caption = re.sub( r"[\u002D\u058A\u05BE\u1400\u1806\u2010-\u2015\u2E17\u2E1A\u2E3A\u2E3B\u2E40\u301C\u3030\u30A0\uFE31\uFE32\uFE58\uFE63\uFF0D]+", # noqa "-", caption, ) # кавычки к одному стандарту caption...
312
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/deepfloyd_if/pipeline_if_img2img.py
# "#123" caption = re.sub(r"#\d{1,3}\b", "", caption) # "#12345.." caption = re.sub(r"#\d{5,}\b", "", caption) # "123456.." caption = re.sub(r"\b\d{6,}\b", "", caption) # filenames: caption = re.sub(r"[\S]+\.(?:png|jpg|jpeg|bmp|webp|eps|pdf|apk|mp4)", "", caption)...
312
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/deepfloyd_if/pipeline_if_img2img.py
caption = re.sub(r"\b[a-zA-Z]{1,3}\d{3,15}\b", "", caption) # jc6640 caption = re.sub(r"\b[a-zA-Z]+\d+[a-zA-Z]+\b", "", caption) # jc6640vc caption = re.sub(r"\b\d+[a-zA-Z]+\d+\b", "", caption) # 6640vc231 caption = re.sub(r"(worldwide\s+)?(free\s+)?shipping", "", caption) caption = ...
312
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/deepfloyd_if/pipeline_if_img2img.py
caption = re.sub(r"^[\"\']([\w\W]+)[\"\']$", r"\1", caption) caption = re.sub(r"^[\'\_,\-\:;]", r"", caption) caption = re.sub(r"[\'\_,\-\:\-\+]$", r"", caption) caption = re.sub(r"^\.\S+$", "", caption) return caption.strip() def preprocess_image(self, image: PIL.Image.Image) -> t...
312
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/deepfloyd_if/pipeline_if_img2img.py
image = new_image image = np.stack(image, axis=0) # to np image = numpy_to_pt(image) # to pt elif isinstance(image[0], np.ndarray): image = np.concatenate(image, axis=0) if image[0].ndim == 4 else np.stack(image, axis=0) image = numpy_to_pt(image) eli...
312
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/deepfloyd_if/pipeline_if_img2img.py
t_start = max(num_inference_steps - init_timestep, 0) 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 ...
312
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/deepfloyd_if/pipeline_if_img2img.py
noise = randn_tensor(shape, generator=generator, device=device, dtype=dtype) image = image.repeat_interleave(num_images_per_prompt, dim=0) image = self.scheduler.add_noise(image, noise, timestep) return image
312
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/deepfloyd_if/pipeline_if_img2img.py
@torch.no_grad() @replace_example_docstring(EXAMPLE_DOC_STRING) def __call__( self, prompt: Union[str, List[str]] = None, image: Union[ PIL.Image.Image, torch.Tensor, np.ndarray, List[PIL.Image.Image], List[torch.Tensor], List[np.ndarray] ] = None, strength: f...
312
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/deepfloyd_if/pipeline_if_img2img.py
cross_attention_kwargs: Optional[Dict[str, Any]] = None, ): """ Function invoked when calling the pipeline for generation.
312
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/deepfloyd_if/pipeline_if_img2img.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. image (`torch.Tensor` or `PIL.Image.Image`): `Image`, or tensor representing an image ba...
312
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/deepfloyd_if/pipeline_if_img2img.py
num_inference_steps (`int`, *optional*, defaults to 80): The number of denoising steps. More denoising steps usually lead to a higher quality image at the expense of slower inference. timesteps (`List[int]`, *optional*): Custom timesteps to use for the denoisi...
312
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/deepfloyd_if/pipeline_if_img2img.py
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`). ...
312
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/deepfloyd_if/pipeline_if_img2img.py
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.Tensor`, *optional*): Pre-generated negative text embeddings. Can b...
312
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/deepfloyd_if/pipeline_if_img2img.py
A function that will be called every `callback_steps` steps during inference. The function will be called with the following arguments: `callback(step: int, timestep: int, latents: torch.Tensor)`. callback_steps (`int`, *optional*, defaults to 1): The frequency at which the `...
312
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/deepfloyd_if/pipeline_if_img2img.py
[diffusers.models.attention_processor](https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/attention_processor.py).
312
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/deepfloyd_if/pipeline_if_img2img.py
Examples: Returns: [`~pipelines.stable_diffusion.IFPipelineOutput`] or `tuple`: [`~pipelines.stable_diffusion.IFPipelineOutput`] if `return_dict` is True, otherwise a `tuple. When returning a tuple, the first element is a list with the generated images, and the second elemen...
312
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/deepfloyd_if/pipeline_if_img2img.py
# 2. Define call parameters device = self._execution_device # 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. ...
312
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/deepfloyd_if/pipeline_if_img2img.py
# 4. Prepare timesteps if timesteps is not None: self.scheduler.set_timesteps(timesteps=timesteps, device=device) timesteps = self.scheduler.timesteps num_inference_steps = len(timesteps) else: self.scheduler.set_timesteps(num_inference_steps, device=devic...
312
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/deepfloyd_if/pipeline_if_img2img.py
# 6. Prepare extra step kwargs. TODO: Logic should ideally just be moved out of the pipeline extra_step_kwargs = self.prepare_extra_step_kwargs(generator, eta) # HACK: see comment in `enable_model_cpu_offload` if hasattr(self, "text_encoder_offload_hook") and self.text_encoder_offload_hook is n...
312
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/deepfloyd_if/pipeline_if_img2img.py
# predict the noise residual noise_pred = self.unet( model_input, t, encoder_hidden_states=prompt_embeds, cross_attention_kwargs=cross_attention_kwargs, return_dict=False, )[0] ...
312
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/deepfloyd_if/pipeline_if_img2img.py
if self.scheduler.config.variance_type not in ["learned", "learned_range"]: noise_pred, _ = noise_pred.split(model_input.shape[1], dim=1) # compute the previous noisy sample x_t -> x_t-1 intermediate_images = self.scheduler.step( noise_pred, t, in...
312
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/deepfloyd_if/pipeline_if_img2img.py
if output_type == "pil": # 8. Post-processing image = (image / 2 + 0.5).clamp(0, 1) image = image.cpu().permute(0, 2, 3, 1).float().numpy() # 9. Run safety checker image, nsfw_detected, watermark_detected = self.run_safety_checker(image, device, prompt_embeds...
312
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/deepfloyd_if/pipeline_if_img2img.py
# 9. Run safety checker image, nsfw_detected, watermark_detected = self.run_safety_checker(image, device, prompt_embeds.dtype) # Offload all models self.maybe_free_model_hooks() if not return_dict: return (image, nsfw_detected, watermark_detected) return IFPipe...
312
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/deepfloyd_if/pipeline_if_img2img.py
class IFSuperResolutionPipeline(DiffusionPipeline, StableDiffusionLoraLoaderMixin): tokenizer: T5Tokenizer text_encoder: T5EncoderModel unet: UNet2DConditionModel scheduler: DDPMScheduler image_noising_scheduler: DDPMScheduler feature_extractor: Optional[CLIPImageProcessor] safety_checker:...
313
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/deepfloyd_if/pipeline_if_superresolution.py
def __init__( self, tokenizer: T5Tokenizer, text_encoder: T5EncoderModel, unet: UNet2DConditionModel, scheduler: DDPMScheduler, image_noising_scheduler: DDPMScheduler, safety_checker: Optional[IFSafetyChecker], feature_extractor: Optional[CLIPImageProcesso...
313
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/deepfloyd_if/pipeline_if_superresolution.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 IF license and do not expose unfiltered" " re...
313
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/deepfloyd_if/pipeline_if_superresolution.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...
313
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/deepfloyd_if/pipeline_if_superresolution.py
self.register_modules( tokenizer=tokenizer, text_encoder=text_encoder, unet=unet, scheduler=scheduler, image_noising_scheduler=image_noising_scheduler, safety_checker=safety_checker, feature_extractor=feature_extractor, wate...
313
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/deepfloyd_if/pipeline_if_superresolution.py
if clean_caption and not is_ftfy_available(): logger.warning(BACKENDS_MAPPING["ftfy"][-1].format("Setting `clean_caption=True`")) logger.warning("Setting `clean_caption` to False...") clean_caption = False if not isinstance(text, (tuple, list)): text = [text] ...
313
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/deepfloyd_if/pipeline_if_superresolution.py
# Copied from diffusers.pipelines.deepfloyd_if.pipeline_if.IFPipeline._clean_caption def _clean_caption(self, caption): caption = str(caption) caption = ul.unquote_plus(caption) caption = caption.strip().lower() caption = re.sub("<person>", "person", caption) # urls: ...
313
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/deepfloyd_if/pipeline_if_superresolution.py
# 31C0—31EF CJK Strokes # 31F0—31FF Katakana Phonetic Extensions # 3200—32FF Enclosed CJK Letters and Months # 3300—33FF CJK Compatibility # 3400—4DBF CJK Unified Ideographs Extension A # 4DC0—4DFF Yijing Hexagram Symbols # 4E00—9FFF CJK Unified Ideographs caption...
313
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/deepfloyd_if/pipeline_if_superresolution.py
# все виды тире / all types of dash --> "-" caption = re.sub( r"[\u002D\u058A\u05BE\u1400\u1806\u2010-\u2015\u2E17\u2E1A\u2E3A\u2E3B\u2E40\u301C\u3030\u30A0\uFE31\uFE32\uFE58\uFE63\uFF0D]+", # noqa "-", caption, ) # кавычки к одному стандарту caption...
313
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/deepfloyd_if/pipeline_if_superresolution.py
# "#123" caption = re.sub(r"#\d{1,3}\b", "", caption) # "#12345.." caption = re.sub(r"#\d{5,}\b", "", caption) # "123456.." caption = re.sub(r"\b\d{6,}\b", "", caption) # filenames: caption = re.sub(r"[\S]+\.(?:png|jpg|jpeg|bmp|webp|eps|pdf|apk|mp4)", "", caption)...
313
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/deepfloyd_if/pipeline_if_superresolution.py
caption = re.sub(r"\b[a-zA-Z]{1,3}\d{3,15}\b", "", caption) # jc6640 caption = re.sub(r"\b[a-zA-Z]+\d+[a-zA-Z]+\b", "", caption) # jc6640vc caption = re.sub(r"\b\d+[a-zA-Z]+\d+\b", "", caption) # 6640vc231 caption = re.sub(r"(worldwide\s+)?(free\s+)?shipping", "", caption) caption = ...
313
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/deepfloyd_if/pipeline_if_superresolution.py
caption = re.sub(r"^[\"\']([\w\W]+)[\"\']$", r"\1", caption) caption = re.sub(r"^[\'\_,\-\:;]", r"", caption) caption = re.sub(r"[\'\_,\-\:\-\+]$", r"", caption) caption = re.sub(r"^\.\S+$", "", caption) return caption.strip() @torch.no_grad() # Copied from diffusers.pipelines....
313
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/deepfloyd_if/pipeline_if_superresolution.py
Args: prompt (`str` or `List[str]`, *optional*): prompt to be encoded do_classifier_free_guidance (`bool`, *optional*, defaults to `True`): whether to use classifier free guidance or not num_images_per_prompt (`int`, *optional*, defaults to 1): ...
313
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/deepfloyd_if/pipeline_if_superresolution.py
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.Tensor`, *optional*): Pre-generated negative text embeddings. Can b...
313
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/deepfloyd_if/pipeline_if_superresolution.py
if device is None: device = self._execution_device 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] ...
313
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/deepfloyd_if/pipeline_if_superresolution.py
if untruncated_ids.shape[-1] >= text_input_ids.shape[-1] and not torch.equal( text_input_ids, untruncated_ids ): removed_text = self.tokenizer.batch_decode(untruncated_ids[:, max_length - 1 : -1]) logger.warning( "The following part of your...
313
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/deepfloyd_if/pipeline_if_superresolution.py
bs_embed, seq_len, _ = prompt_embeds.shape # duplicate text embeddings for each generation per prompt, using mps friendly method prompt_embeds = prompt_embeds.repeat(1, num_images_per_prompt, 1) prompt_embeds = prompt_embeds.view(bs_embed * num_images_per_prompt, seq_len, -1)
313
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/deepfloyd_if/pipeline_if_superresolution.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 isinstance(negative_prompt, str): ...
313
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/deepfloyd_if/pipeline_if_superresolution.py
uncond_tokens = self._text_preprocessing(uncond_tokens, clean_caption=clean_caption) max_length = prompt_embeds.shape[1] uncond_input = self.tokenizer( uncond_tokens, padding="max_length", max_length=max_length, truncation=True, ...
313
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/deepfloyd_if/pipeline_if_superresolution.py
negative_prompt_embeds = negative_prompt_embeds.to(dtype=dtype, device=device) negative_prompt_embeds = negative_prompt_embeds.repeat(1, num_images_per_prompt, 1) negative_prompt_embeds = negative_prompt_embeds.view(batch_size * num_images_per_prompt, seq_len, -1) # For classifier ...
313
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/deepfloyd_if/pipeline_if_superresolution.py
# Copied from diffusers.pipelines.deepfloyd_if.pipeline_if.IFPipeline.run_safety_checker def run_safety_checker(self, image, device, dtype): if self.safety_checker is not None: safety_checker_input = self.feature_extractor(self.numpy_to_pil(image), return_tensors="pt").to(device) ima...
313
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/deepfloyd_if/pipeline_if_superresolution.py
# Copied from diffusers.pipelines.deepfloyd_if.pipeline_if.IFPipeline.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 with the DDIMScheduler, it will ...
313
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/deepfloyd_if/pipeline_if_superresolution.py
def check_inputs( self, prompt, image, batch_size, noise_level, callback_steps, negative_prompt=None, prompt_embeds=None, negative_prompt_embeds=None, ): if (callback_steps is None) or ( callback_steps is not None and (not i...
313
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/deepfloyd_if/pipeline_if_superresolution.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: ...
313
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/deepfloyd_if/pipeline_if_superresolution.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...
313
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/deepfloyd_if/pipeline_if_superresolution.py
if ( not isinstance(check_image_type, torch.Tensor) and not isinstance(check_image_type, PIL.Image.Image) and not isinstance(check_image_type, np.ndarray) ): raise ValueError( "`image` has to be of type `torch.Tensor`, `PIL.Image.Image`, `np.ndarra...
313
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/deepfloyd_if/pipeline_if_superresolution.py
# Copied from diffusers.pipelines.deepfloyd_if.pipeline_if.IFPipeline.prepare_intermediate_images def prepare_intermediate_images(self, batch_size, num_channels, height, width, dtype, device, generator): shape = (batch_size, num_channels, height, width) if isinstance(generator, list) and len(generat...
313
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/deepfloyd_if/pipeline_if_superresolution.py
def preprocess_image(self, image, num_images_per_prompt, device): if not isinstance(image, torch.Tensor) and not isinstance(image, list): image = [image] if isinstance(image[0], PIL.Image.Image): image = [np.array(i).astype(np.float32) / 127.5 - 1.0 for i in image] ...
313
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/deepfloyd_if/pipeline_if_superresolution.py
if dims == 3: image = torch.stack(image, dim=0) elif dims == 4: image = torch.concat(image, dim=0) else: raise ValueError(f"Image must have 3 or 4 dimensions, instead got {dims}") image = image.to(device=device, dtype=self.unet.dtype) ...
313
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/deepfloyd_if/pipeline_if_superresolution.py
@torch.no_grad() @replace_example_docstring(EXAMPLE_DOC_STRING) def __call__( self, prompt: Union[str, List[str]] = None, height: int = None, width: int = None, image: Union[PIL.Image.Image, np.ndarray, torch.Tensor] = None, num_inference_steps: int = 50, ...
313
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/deepfloyd_if/pipeline_if_superresolution.py
clean_caption: bool = True, ): """ Function invoked when calling the pipeline for generation.
313
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/deepfloyd_if/pipeline_if_superresolution.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. height (`int`, *optional*, defaults to None): The height in pixels of the generated imag...
313
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/deepfloyd_if/pipeline_if_superresolution.py
timesteps are used. Must be in descending order. guidance_scale (`float`, *optional*, defaults to 4.0): Guidance scale as defined in [Classifier-Free Diffusion Guidance](https://arxiv.org/abs/2207.12598). `guidance_scale` is defined as `w` of equation 2. of [Imagen ...
313
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/deepfloyd_if/pipeline_if_superresolution.py
The number of images to generate per prompt. eta (`float`, *optional*, defaults to 0.0): Corresponds to parameter eta (η) in the DDIM paper: https://arxiv.org/abs/2010.02502. Only applies to [`schedulers.DDIMScheduler`], will be ignored for others. generator (`tor...
313
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/deepfloyd_if/pipeline_if_superresolution.py
weighting. If not provided, negative_prompt_embeds will be generated from `negative_prompt` input argument. output_type (`str`, *optional*, defaults to `"pil"`): The output format of the generate image. Choose between [PIL](https://pillow.readthedocs.io/en/sta...
313
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/deepfloyd_if/pipeline_if_superresolution.py
called at every step. cross_attention_kwargs (`dict`, *optional*): A kwargs dictionary that if specified is passed along to the `AttentionProcessor` as defined under `self.processor` in [diffusers.models.attention_processor](https://github.com/huggingface/diff...
313
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/deepfloyd_if/pipeline_if_superresolution.py
Examples: Returns: [`~pipelines.stable_diffusion.IFPipelineOutput`] or `tuple`: [`~pipelines.stable_diffusion.IFPipelineOutput`] if `return_dict` is True, otherwise a `tuple. When returning a tuple, the first element is a list with the generated images, and the second elemen...
313
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/deepfloyd_if/pipeline_if_superresolution.py
self.check_inputs( prompt, image, batch_size, noise_level, callback_steps, negative_prompt, prompt_embeds, negative_prompt_embeds, ) # 2. Define call parameters height = height or self.unet.config.s...
313
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/deepfloyd_if/pipeline_if_superresolution.py
# 3. Encode input prompt prompt_embeds, negative_prompt_embeds = self.encode_prompt( prompt, do_classifier_free_guidance, num_images_per_prompt=num_images_per_prompt, device=device, negative_prompt=negative_prompt, prompt_embeds=prompt_embe...
313
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/deepfloyd_if/pipeline_if_superresolution.py
if hasattr(self.scheduler, "set_begin_index"): self.scheduler.set_begin_index(0) # 5. Prepare intermediate images num_channels = self.unet.config.in_channels // 2 intermediate_images = self.prepare_intermediate_images( batch_size * num_images_per_prompt, num_...
313
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/deepfloyd_if/pipeline_if_superresolution.py
noise_level = torch.tensor([noise_level] * upscaled.shape[0], device=upscaled.device) noise = randn_tensor(upscaled.shape, generator=generator, device=upscaled.device, dtype=upscaled.dtype) upscaled = self.image_noising_scheduler.add_noise(upscaled, noise, timesteps=noise_level) if do_classifie...
313
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/deepfloyd_if/pipeline_if_superresolution.py
model_input = torch.cat([model_input] * 2) if do_classifier_free_guidance else model_input model_input = self.scheduler.scale_model_input(model_input, t) # predict the noise residual noise_pred = self.unet( model_input, t, ...
313
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/deepfloyd_if/pipeline_if_superresolution.py
# perform guidance if do_classifier_free_guidance: noise_pred_uncond, noise_pred_text = noise_pred.chunk(2) noise_pred_uncond, _ = noise_pred_uncond.split(model_input.shape[1] // 2, dim=1) noise_pred_text, predicted_variance = noise_pred_text.s...
313
/Users/nielsrogge/Documents/python_projecten/diffusers/src/diffusers/pipelines/deepfloyd_if/pipeline_if_superresolution.py