text stringlengths 0 5.54k |
|---|
adapter = T2IAdapter.from_pretrained("TencentARC/t2i-adapter-canny-sdxl-1.0", torch_dtype=torch.float16, varient="fp16").to("cuda") |
pipe = StableDiffusionXLAdapterPipeline.from_pretrained( |
"stabilityai/stable-diffusion-xl-base-1.0", |
adapter=adapter, |
torch_dtype=torch.float16, |
variant="fp16", |
).to("cuda") |
# set scheduler |
pipe.scheduler = LCMScheduler.from_config(pipe.scheduler.config) |
# load LCM-LoRA |
pipe.load_lora_weights("latent-consistency/lcm-lora-sdxl") |
prompt = "Mystical fairy in real, magic, 4k picture, high quality" |
negative_prompt = "extra digit, fewer digits, cropped, worst quality, low quality, glitch, deformed, mutated, ugly, disfigured" |
generator = torch.manual_seed(0) |
image = pipe( |
prompt=prompt, |
negative_prompt=negative_prompt, |
image=canny_image, |
num_inference_steps=4, |
guidance_scale=1.5, |
adapter_conditioning_scale=0.8, |
adapter_conditioning_factor=1, |
generator=generator, |
).images[0] |
make_image_grid([canny_image, image], rows=1, cols=2) Inpainting LCM-LoRA can be used for inpainting as well. Copied import torch |
from diffusers import AutoPipelineForInpainting, LCMScheduler |
from diffusers.utils import load_image, make_image_grid |
pipe = AutoPipelineForInpainting.from_pretrained( |
"runwayml/stable-diffusion-inpainting", |
torch_dtype=torch.float16, |
variant="fp16", |
).to("cuda") |
# set scheduler |
pipe.scheduler = LCMScheduler.from_config(pipe.scheduler.config) |
# load LCM-LoRA |
pipe.load_lora_weights("latent-consistency/lcm-lora-sdv1-5") |
# load base and mask image |
init_image = load_image("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/inpaint.png") |
mask_image = load_image("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/inpaint_mask.png") |
# generator = torch.Generator("cuda").manual_seed(92) |
prompt = "concept art digital painting of an elven castle, inspired by lord of the rings, highly detailed, 8k" |
generator = torch.manual_seed(0) |
image = pipe( |
prompt=prompt, |
image=init_image, |
mask_image=mask_image, |
generator=generator, |
num_inference_steps=4, |
guidance_scale=4, |
).images[0] |
make_image_grid([init_image, mask_image, image], rows=1, cols=3) AnimateDiff AnimateDiff allows you to animate images using Stable Diffusion models. To get good results, we need to generate multiple frames (16-24), and doing this with standard SD models can be very slow. |
LCM-LoRA can be used to speed up the process significantly, as you just need to do 4-8 steps for each frame. Letβs look at how we can perform animation with LCM-LoRA and AnimateDiff. Copied import torch |
from diffusers import MotionAdapter, AnimateDiffPipeline, DDIMScheduler, LCMScheduler |
from diffusers.utils import export_to_gif |
adapter = MotionAdapter.from_pretrained("diffusers/animatediff-motion-adapter-v1-5") |
pipe = AnimateDiffPipeline.from_pretrained( |
"frankjoshua/toonyou_beta6", |
motion_adapter=adapter, |
).to("cuda") |
# set scheduler |
pipe.scheduler = LCMScheduler.from_config(pipe.scheduler.config) |
# load LCM-LoRA |
pipe.load_lora_weights("latent-consistency/lcm-lora-sdv1-5", adapter_name="lcm") |
pipe.load_lora_weights("guoyww/animatediff-motion-lora-zoom-in", weight_name="diffusion_pytorch_model.safetensors", adapter_name="motion-lora") |
pipe.set_adapters(["lcm", "motion-lora"], adapter_weights=[0.55, 1.2]) |
prompt = "best quality, masterpiece, 1girl, looking at viewer, blurry background, upper body, contemporary, dress" |
generator = torch.manual_seed(0) |
frames = pipe( |
prompt=prompt, |
num_inference_steps=5, |
guidance_scale=1.25, |
cross_attention_kwargs={"scale": 1}, |
num_frames=24, |
generator=generator |
).frames[0] |
export_to_gif(frames, "animation.gif") |
UNet3DConditionModel The UNet model was originally introduced by Ronneberger et al. for biomedical image segmentation, but it is also commonly used in π€ Diffusers because it outputs images that are the same size as the input. It is one of the most important components of a diffusion system because it facilitates the a... |
Height and width of input/output sample. in_channels (int, optional, defaults to 4) β The number of channels in the input sample. out_channels (int, optional, defaults to 4) β The number of channels in the output. down_block_types (Tuple[str], optional, defaults to ("CrossAttnDownBlock3D", "CrossAttnDownBlock3D",... |
The tuple of downsample blocks to use. up_block_types (Tuple[str], optional, defaults to ("UpBlock3D", "CrossAttnUpBlock3D", "CrossAttnUpBlock3D", "CrossAttnUpBlock3D")) β |
The tuple of upsample blocks to use. block_out_channels (Tuple[int], optional, defaults to (320, 640, 1280, 1280)) β |
The tuple of output channels for each block. layers_per_block (int, optional, defaults to 2) β The number of layers per block. downsample_padding (int, optional, defaults to 1) β The padding to use for the downsampling convolution. mid_block_scale_factor (float, optional, defaults to 1.0) β The scale factor to us... |
If None, normalization and activation layers is skipped in post-processing. norm_eps (float, optional, defaults to 1e-5) β The epsilon to use for the normalization. cross_attention_dim (int, optional, defaults to 1024) β The dimension of the cross attention features. attention_head_dim (int, optional, defaults to... |
shaped output. This model inherits from ModelMixin. Check the superclass documentation for itβs generic methods implemented |
for all models (such as downloading or saving). disable_freeu < source > ( ) Disables the FreeU mechanism. enable_forward_chunking < source > ( chunk_size: Optional = None dim: int = 0 ) Parameters chunk_size (int, optional) β |
The chunk size of the feed-forward layers. If not specified, will run feed-forward layer individually |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.