AnimateDiff也可用于SDXL模型
import os
os.environ["HF_ENDPOINT"] = "https://hf-mirror.com"
mport torch from diffusers.models import MotionAdapter from diffusers import AnimateDiffSDXLPipeline, DDIMScheduler from diffusers.utils import export_to_gif adapter = MotionAdapter.from_pretrained("guoyww/animatediff-motion-adapter-sdxl-beta", torch_dtype=torch.float16) model_id = "stabilityai/stable-diffusion-xl-base-1.0" scheduler = DDIMScheduler.from_pretrained( model_id, subfolder="scheduler", clip_sample=False, timestep_spacing="linspace", beta_schedule="linear", steps_offset=1, ) pipe = AnimateDiffSDXLPipeline.from_pretrained( model_id, motion_adapter=adapter, scheduler=scheduler, torch_dtype=torch.float16, variant="fp16", ).to("cuda") # 启用内存节约
pipe.enable_vae_slicing() pipe.enable_vae_tiling() output = pipe( prompt="a panda surfing in the ocean, realistic, high quality", negative_prompt="low quality, worst quality", num_inference_steps=20, guidance_scale=8, width=1024, height=1024, num_frames=16, ) frames = output.frames[0]
export_to_gif(frames, "animation02.gif")