text
stringlengths 0
5.54k
|
---|
overall image to the prompt argument to help guide the inverse latent sampling process. In most cases, the |
source concept is sufficiently descriptive to yield good results, but feel free to explore alternatives. When calling the pipeline to generate the final edited image, assign the source concept to negative_prompt |
and the target concept to prompt. Taking the above example, you simply have to set the embeddings related to |
the phrases including βcatβ to negative_prompt and βdogβ to prompt. If you wanted to reverse the direction in the example above, i.e., βdog -> catβ, then itβs recommended to:Swap the source_prompt and target_prompt in the arguments to generate_mask. Change the input prompt in invert() to include βdogβ. Swap the prompt and negative_prompt in the arguments to call the pipeline to generate the final edited image. The source and target prompts, or their corresponding embeddings, can also be automatically generated. Please refer to the DiffEdit guide for more details. StableDiffusionDiffEditPipeline class diffusers.StableDiffusionDiffEditPipeline < source > ( vae: AutoencoderKL text_encoder: CLIPTextModel tokenizer: CLIPTokenizer unet: UNet2DConditionModel scheduler: KarrasDiffusionSchedulers safety_checker: StableDiffusionSafetyChecker feature_extractor: CLIPImageProcessor inverse_scheduler: DDIMInverseScheduler requires_safety_checker: bool = True ) Parameters vae (AutoencoderKL) β |
Variational Auto-Encoder (VAE) model to encode and decode images to and from latent representations. text_encoder (CLIPTextModel) β |
Frozen text-encoder (clip-vit-large-patch14). tokenizer (CLIPTokenizer) β |
A CLIPTokenizer to tokenize text. unet (UNet2DConditionModel) β |
A UNet2DConditionModel to denoise the encoded image latents. scheduler (SchedulerMixin) β |
A scheduler to be used in combination with unet to denoise the encoded image latents. inverse_scheduler (DDIMInverseScheduler) β |
A scheduler to be used in combination with unet to fill in the unmasked part of the input latents. safety_checker (StableDiffusionSafetyChecker) β |
Classification module that estimates whether generated images could be considered offensive or harmful. |
Please refer to the model card for more details |
about a modelβs potential harms. feature_extractor (CLIPImageProcessor) β |
A CLIPImageProcessor to extract features from generated images; used as inputs to the safety_checker. This is an experimental feature! Pipeline for text-guided image inpainting using Stable Diffusion and DiffEdit. This model inherits from DiffusionPipeline. Check the superclass documentation for the generic methods |
implemented for all pipelines (downloading, saving, running on a particular device, etc.). The pipeline also inherits the following loading and saving methods: load_textual_inversion() for loading textual inversion embeddings load_lora_weights() for loading LoRA weights save_lora_weights() for saving LoRA weights generate_mask < source > ( image: Union = None target_prompt: Union = None target_negative_prompt: Union = None target_prompt_embeds: Optional = None target_negative_prompt_embeds: Optional = None source_prompt: Union = None source_negative_prompt: Union = None source_prompt_embeds: Optional = None source_negative_prompt_embeds: Optional = None num_maps_per_mask: Optional = 10 mask_encode_strength: Optional = 0.5 mask_thresholding_ratio: Optional = 3.0 num_inference_steps: int = 50 guidance_scale: float = 7.5 generator: Union = None output_type: Optional = 'np' cross_attention_kwargs: Optional = None ) β List[PIL.Image.Image] or np.array Parameters image (PIL.Image.Image) β |
Image or tensor representing an image batch to be used for computing the mask. target_prompt (str or List[str], optional) β |
The prompt or prompts to guide semantic mask generation. If not defined, you need to pass |
prompt_embeds. target_negative_prompt (str or List[str], optional) β |
The prompt or prompts to guide what to not include in image generation. If not defined, you need to |
pass negative_prompt_embeds instead. Ignored when not using guidance (guidance_scale < 1). target_prompt_embeds (torch.FloatTensor, 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 argument. target_negative_prompt_embeds (torch.FloatTensor, optional) β |
Pre-generated negative text embeddings. Can be used to easily tweak text inputs (prompt weighting). If |
not provided, negative_prompt_embeds are generated from the negative_prompt input argument. source_prompt (str or List[str], optional) β |
The prompt or prompts to guide semantic mask generation using DiffEdit. If not defined, you need to |
pass source_prompt_embeds or source_image instead. source_negative_prompt (str or List[str], optional) β |
The prompt or prompts to guide semantic mask generation away from using DiffEdit. If not defined, you |
need to pass source_negative_prompt_embeds or source_image instead. source_prompt_embeds (torch.FloatTensor, optional) β |
Pre-generated text embeddings to guide the semantic mask generation. Can be used to easily tweak text |
inputs (prompt weighting). If not provided, text embeddings are generated from source_prompt input |
argument. source_negative_prompt_embeds (torch.FloatTensor, optional) β |
Pre-generated text embeddings to negatively guide the semantic mask generation. Can be used to easily |
tweak text inputs (prompt weighting). If not provided, text embeddings are generated from |
source_negative_prompt input argument. num_maps_per_mask (int, optional, defaults to 10) β |
The number of noise maps sampled to generate the semantic mask using DiffEdit. mask_encode_strength (float, optional, defaults to 0.5) β |
The strength of the noise maps sampled to generate the semantic mask using DiffEdit. Must be between 0 |
and 1. mask_thresholding_ratio (float, optional, defaults to 3.0) β |
The maximum multiple of the mean absolute difference used to clamp the semantic guidance map before |
mask binarization. num_inference_steps (int, optional, defaults to 50) β |
The number of denoising steps. More denoising steps usually lead to a higher quality image at the |
expense of slower inference. guidance_scale (float, optional, defaults to 7.5) β |
A higher guidance scale value encourages the model to generate images closely linked to the text |
prompt at the expense of lower image quality. Guidance scale is enabled when guidance_scale > 1. generator (torch.Generator or List[torch.Generator], optional) β |
A torch.Generator to make |
generation deterministic. output_type (str, optional, defaults to "pil") β |
The output format of the generated image. Choose between PIL.Image or np.array. cross_attention_kwargs (dict, optional) β |
A kwargs dictionary that if specified is passed along to the |
AttnProcessor as defined in |
self.processor. Returns |
List[PIL.Image.Image] or np.array |
When returning a List[PIL.Image.Image], the list consists of a batch of single-channel binary images |
with dimensions (height // self.vae_scale_factor, width // self.vae_scale_factor). If itβs |
np.array, the shape is (batch_size, height // self.vae_scale_factor, width // self.vae_scale_factor). |
Generate a latent mask given a mask prompt, a target prompt, and an image. Copied >>> import PIL |
>>> import requests |
>>> import torch |
>>> from io import BytesIO |
>>> from diffusers import StableDiffusionDiffEditPipeline |
>>> def download_image(url): |
... response = requests.get(url) |
... return PIL.Image.open(BytesIO(response.content)).convert("RGB") |
>>> img_url = "https://github.com/Xiang-cd/DiffEdit-stable-diffusion/raw/main/assets/origin.png" |
>>> init_image = download_image(img_url).resize((768, 768)) |
>>> pipe = StableDiffusionDiffEditPipeline.from_pretrained( |
... "stabilityai/stable-diffusion-2-1", torch_dtype=torch.float16 |
... ) |
>>> pipe = pipe.to("cuda") |
>>> pipeline.scheduler = DDIMScheduler.from_config(pipeline.scheduler.config) |
>>> pipeline.inverse_scheduler = DDIMInverseScheduler.from_config(pipeline.scheduler.config) |
>>> pipeline.enable_model_cpu_offload() |
>>> mask_prompt = "A bowl of fruits" |
>>> prompt = "A bowl of pears" |
>>> mask_image = pipe.generate_mask(image=init_image, source_prompt=prompt, target_prompt=mask_prompt) |
>>> image_latents = pipe.invert(image=init_image, prompt=mask_prompt).latents |
>>> image = pipe(prompt=prompt, mask_image=mask_image, image_latents=image_latents).images[0] invert < source > ( prompt: Union = None image: Union = None num_inference_steps: int = 50 inpaint_strength: float = 0.8 guidance_scale: float = 7.5 negative_prompt: Union = None generator: Union = None prompt_embeds: Optional = None negative_prompt_embeds: Optional = None decode_latents: bool = False output_type: Optional = 'pil' return_dict: bool = True callback: Optional = None callback_steps: Optional = 1 cross_attention_kwargs: Optional = None lambda_auto_corr: float = 20.0 lambda_kl: float = 20.0 num_reg_steps: int = 0 num_auto_corr_rolls: int = 5 ) Parameters prompt (str or List[str], optional) β |
The prompt or prompts to guide image generation. If not defined, you need to pass prompt_embeds. image (PIL.Image.Image) β |
Image or tensor representing an image batch to produce the inverted latents guided by prompt. inpaint_strength (float, optional, defaults to 0.8) β |
Indicates extent of the noising process to run latent inversion. Must be between 0 and 1. When |
inpaint_strength is 1, the inversion process is run for the full number of iterations specified in |
num_inference_steps. image is used as a reference for the inversion process, and adding more noise |
increases inpaint_strength. If inpaint_strength is 0, no inpainting occurs. num_inference_steps (int, optional, defaults to 50) β |
The number of denoising steps. More denoising steps usually lead to a higher quality image at the |
expense of slower inference. guidance_scale (float, optional, defaults to 7.5) β |
A higher guidance scale value encourages the model to generate images closely linked to the text |
prompt at the expense of lower image quality. Guidance scale is enabled when guidance_scale > 1. negative_prompt (str or List[str], optional) β |
The prompt or prompts to guide what to not include in image generation. If not defined, you need to |
pass negative_prompt_embeds instead. Ignored when not using guidance (guidance_scale < 1). generator (torch.Generator, optional) β |
A torch.Generator to make |
generation deterministic. prompt_embeds (torch.FloatTensor, optional) β |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.