text
stringlengths 0
5.54k
|
---|
>>> 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] disable_vae_slicing < source > ( ) Disable sliced VAE decoding. If enable_vae_slicing was previously enabled, this method will go back to |
computing decoding in one step. disable_vae_tiling < source > ( ) Disable tiled VAE decoding. If enable_vae_tiling was previously enabled, this method will go back to |
computing decoding in one step. enable_vae_slicing < source > ( ) Enable sliced VAE decoding. When this option is enabled, the VAE will split the input tensor in slices to |
compute decoding in several steps. This is useful to save some memory and allow larger batch sizes. enable_vae_tiling < source > ( ) Enable tiled VAE decoding. When this option is enabled, the VAE will split the input tensor into tiles to |
compute decoding and encoding in several steps. This is useful for saving a large amount of memory and to allow |
processing larger images. encode_prompt < source > ( prompt device num_images_per_prompt do_classifier_free_guidance negative_prompt = None prompt_embeds: Optional = None negative_prompt_embeds: Optional = None lora_scale: Optional = None clip_skip: Optional = None ) Parameters 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 (bool) β |
whether to use classifier free guidance or not 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). prompt_embeds (torch.FloatTensor, optional) β |
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.FloatTensor, 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_scale (float, optional) β |
A LoRA scale that will be applied to all LoRA layers of the text encoder if LoRA layers are loaded. 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. Encodes the prompt into text encoder hidden states. StableDiffusionPipelineOutput class diffusers.pipelines.stable_diffusion.StableDiffusionPipelineOutput < source > ( images: Union nsfw_content_detected: Optional ) Parameters images (List[PIL.Image.Image] or np.ndarray) β |
List of denoised PIL images of length batch_size or NumPy array of shape (batch_size, height, width, num_channels). nsfw_content_detected (List[bool]) β |
List indicating whether the corresponding generated image contains βnot-safe-for-workβ (nsfw) content or |
None if safety checking could not be performed. Output class for Stable Diffusion pipelines. |
Text-to-Video Generation with AnimateDiff Overview AnimateDiff: Animate Your Personalized Text-to-Image Diffusion Models without Specific Tuning by Yuwei Guo, Ceyuan Yang, Anyi Rao, Yaohui Wang, Yu Qiao, Dahua Lin, Bo Dai. The abstract of the paper is the following: With the advance of text-to-image models (e.g., Stable Diffusion) and corresponding personalization techniques such as DreamBooth and LoRA, everyone can manifest their imagination into high-quality images at an affordable cost. Subsequently, there is a great demand for image animation techniques to further combine generated static images with motion dynamics. In this report, we propose a practical framework to animate most of the existing personalized text-to-image models once and for all, saving efforts in model-specific tuning. At the core of the proposed framework is to insert a newly initialized motion modeling module into the frozen text-to-image model and train it on video clips to distill reasonable motion priors. Once trained, by simply injecting this motion modeling module, all personalized versions derived from the same base T2I readily become text-driven models that produce diverse and personalized animated images. We conduct our evaluation on several public representative personalized text-to-image models across anime pictures and realistic photographs, and demonstrate that our proposed framework helps these models generate temporally smooth animation clips while preserving the domain and diversity of their outputs. Code and pre-trained weights will be publicly available at this https URL. Available Pipelines Pipeline Tasks Demo AnimateDiffPipeline Text-to-Video Generation with AnimateDiff Available checkpoints Motion Adapter checkpoints can be found under guoyww. These checkpoints are meant to work with any model based on Stable Diffusion 1.4/1.5. Usage example AnimateDiff works with a MotionAdapter checkpoint and a Stable Diffusion model checkpoint. The MotionAdapter is a collection of Motion Modules that are responsible for adding coherent motion across image frames. These modules are applied after the Resnet and Attention blocks in Stable Diffusion UNet. The following example demonstrates how to use a MotionAdapter checkpoint with Diffusers for inference based on StableDiffusion-1.4/1.5. Copied import torch |
from diffusers import AnimateDiffPipeline, DDIMScheduler, MotionAdapter |
from diffusers.utils import export_to_gif |
# Load the motion adapter |
adapter = MotionAdapter.from_pretrained("guoyww/animatediff-motion-adapter-v1-5-2", torch_dtype=torch.float16) |
# load SD 1.5 based finetuned model |
model_id = "SG161222/Realistic_Vision_V5.1_noVAE" |
pipe = AnimateDiffPipeline.from_pretrained(model_id, motion_adapter=adapter, torch_dtype=torch.float16) |
scheduler = DDIMScheduler.from_pretrained( |
model_id, |
subfolder="scheduler", |
clip_sample=False, |
timestep_spacing="linspace", |
beta_schedule="linear", |
steps_offset=1, |
) |
pipe.scheduler = scheduler |
# enable memory savings |
pipe.enable_vae_slicing() |
pipe.enable_model_cpu_offload() |
output = pipe( |
prompt=( |
"masterpiece, bestquality, highlydetailed, ultradetailed, sunset, " |
"orange sky, warm lighting, fishing boats, ocean waves seagulls, " |
"rippling water, wharf, silhouette, serene atmosphere, dusk, evening glow, " |
"golden hour, coastal landscape, seaside scenery" |
), |
negative_prompt="bad quality, worse quality", |
num_frames=16, |
guidance_scale=7.5, |
num_inference_steps=25, |
generator=torch.Generator("cpu").manual_seed(42), |
) |
frames = output.frames[0] |
export_to_gif(frames, "animation.gif") |
Here are some sample outputs: masterpiece, bestquality, sunset. |
AnimateDiff tends to work better with finetuned Stable Diffusion models. If you plan on using a scheduler that can clip samples, make sure to disable it by setting clip_sample=False in the scheduler as this can also have an adverse effect on generated samples. Additionally, the AnimateDiff checkpoints can be sensitive to the beta schedule of the scheduler. We recommend setting this to linear. Using Motion LoRAs Motion LoRAs are a collection of LoRAs that work with the guoyww/animatediff-motion-adapter-v1-5-2 checkpoint. These LoRAs are responsible for adding specific types of motion to the animations. Copied import torch |
from diffusers import AnimateDiffPipeline, DDIMScheduler, MotionAdapter |
from diffusers.utils import export_to_gif |
# Load the motion adapter |
adapter = MotionAdapter.from_pretrained("guoyww/animatediff-motion-adapter-v1-5-2", torch_dtype=torch.float16) |
# load SD 1.5 based finetuned model |
model_id = "SG161222/Realistic_Vision_V5.1_noVAE" |
pipe = AnimateDiffPipeline.from_pretrained(model_id, motion_adapter=adapter, torch_dtype=torch.float16) |
pipe.load_lora_weights( |
"guoyww/animatediff-motion-lora-zoom-out", adapter_name="zoom-out" |
) |