FreeInit 是一种有效的方法,无需任何额外训练即可提高使用视频扩散模型生成的视频的时间一致性和整体质量。它可以在推理时无缝应用于 PIA、AnimateDiff、ModelScope、VideoCrafter 和其他各种视频生成模型,并通过迭代细化潜在初始化噪声来工作。
import os os.environ["HF_ENDPOINT"] = "https://hf-mirror.com" import torch from diffusers import ( DDIMScheduler, MotionAdapter, PIAPipeline, ) from diffusers.utils import export_to_gif, load_image adapter = MotionAdapter.from_pretrained("openmmlab/PIA-condition-adapter") pipe = PIAPipeline.from_pretrained("SG161222/Realistic_Vision_V6.0_B1_noVAE", motion_adapter=adapter) # enable FreeInit # Refer to the enable_free_init documentation for a full list of configurable parameters pipe.enable_free_init(method="butterworth", use_fast_sampling=True) # Memory saving options pipe.enable_model_cpu_offload() pipe.enable_vae_slicing() pipe.scheduler = DDIMScheduler.from_config(pipe.scheduler.config) image = load_image( "https://hf-mirror.com/datasets/hf-internal-testing/diffusers-images/resolve/main/pix2pix/cat_6.png?download=true" ) image = image.resize((512, 512)) prompt = "cat in a field" negative_prompt = "wrong white balance, dark, sketches,worst quality,low quality" generator = torch.Generator("cpu").manual_seed(0) output = pipe(image=image, prompt=prompt, generator=generator) frames = output.frames[0] export_to_gif(frames, "pia-freeinit-animation.gif")