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