Views
No views yet
![]() |
1import torch
2from diffusers import MotionAdapter, AnimateDiffPipeline, DDIMScheduler
3from diffusers.utils import export_to_gif
4
5# Load the motion adapter
6adapter = MotionAdapter.from_pretrained("guoyww/animatediff-motion-adapter-v1-5")
7# load SD 1.5 based finetuned model
8model_id = "SG161222/Realistic_Vision_V5.1_noVAE"
9pipe = AnimateDiffPipeline.from_pretrained(model_id, motion_adapter=adapter)
10scheduler = DDIMScheduler.from_pretrained(
11 model_id, subfolder="scheduler", clip_sample=False, timestep_spacing="linspace", steps_offset=1
12)
13pipe.scheduler = scheduler
14
15# enable memory savings
16pipe.enable_vae_slicing()
17pipe.enable_model_cpu_offload()
18
19output = pipe(
20 prompt=(
21 "masterpiece, bestquality, highlydetailed, ultradetailed, sunset, "
22 "orange sky, warm lighting, fishing boats, ocean waves seagulls, "
23 "rippling water, wharf, silhouette, serene atmosphere, dusk, evening glow, "
24 "golden hour, coastal landscape, seaside scenery"
25 ),
26 negative_prompt="bad quality, worse quality",
27 num_frames=16,
28 guidance_scale=7.5,
29 num_inference_steps=25,
30 generator=torch.Generator("cpu").manual_seed(42),
31)
32frames = output.frames[0]
33export_to_gif(frames, "animation.gif")clip_sample=False in the scheduler as this can also have an adverse effect on generated samples.