text stringlengths 0 5.54k |
|---|
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 ... |
import requests |
import torch |
from diffusers import AnimateDiffVideoToVideoPipeline, DDIMScheduler, MotionAdapter |
from diffusers.utils import export_to_gif |
from io import BytesIO |
from PIL import Image |
# 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 = AnimateDiffVideoToVideoPipeline.from_pretrained(model_id, motion_adapter=adapter, torch_dtype=torch.float16).to("cuda") |
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() |
# helper function to load videos |
def load_video(file_path: str): |
images = [] |
if file_path.startswith(('http://', 'https://')): |
# If the file_path is a URL |
response = requests.get(file_path) |
response.raise_for_status() |
content = BytesIO(response.content) |
vid = imageio.get_reader(content) |
else: |
# Assuming it's a local file path |
vid = imageio.get_reader(file_path) |
for frame in vid: |
pil_image = Image.fromarray(frame) |
images.append(pil_image) |
return images |
video = load_video("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/animatediff-vid2vid-input-1.gif") |
output = pipe( |
video = video, |
prompt="panda playing a guitar, on a boat, in the ocean, high quality", |
negative_prompt="bad quality, worse quality", |
guidance_scale=7.5, |
num_inference_steps=25, |
strength=0.5, |
generator=torch.Generator("cpu").manual_seed(42), |
) |
frames = output.frames[0] |
export_to_gif(frames, "animation.gif") Here are some sample outputs: Source Video Output Video raccoon playing a guitar |
panda playing a guitar |
closeup of margot robbie, fireworks in the background, high quality |
closeup of tony stark, robert downey jr, fireworks |
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" |
) |
scheduler = DDIMScheduler.from_pretrained( |
model_id, |
subfolder="scheduler", |
clip_sample=False, |
beta_schedule="linear", |
timestep_spacing="linspace", |
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" |
), |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.