はじめに
以前「FreeInit」についての記事を書きました。touch-sp.hatenablog.com
Diffusersから使えるようになって環境設定、使い方など非常に簡単になっています。
PC環境
Windows 11 CUDA 11.8 Python 3.11
Python環境構築
pip install torch==2.1.2+cu118 --index-url https://download.pytorch.org/whl/cu118 pip install git+https://github.com/huggingface/diffusers pip install accelerate transformers
結果
左から「FreeInitなし」→「FreeInit (ideal)」→「FreeInit (gaussian)」→「FreeInit (butterworth)」です。Pythonスクリプト
import torch from diffusers import MotionAdapter, AnimateDiffPipeline, DDIMScheduler from diffusers.utils import export_to_gif adapter = MotionAdapter.from_pretrained("animatediff-motion-adapter-v1-5-2") model_id = "model/rcnzCartoon3d_v20" pipe = AnimateDiffPipeline.from_pretrained( model_id, motion_adapter=adapter, torch_dtype=torch.float16 ).to("cuda") pipe.scheduler = DDIMScheduler.from_pretrained( model_id, subfolder="scheduler", beta_schedule="linear", clip_sample=False, timestep_spacing="linspace", steps_offset=1 ) pipe.enable_free_init( method="butterworth", # "ideal", "gaussian", or "butterworth" num_iters=5, # default 3 use_fast_sampling=False ) generator = torch.manual_seed(2024) output = pipe( prompt="A cute raccoon playing guitar in a boat on the ocean", negative_prompt="bad quality, worse quality", num_frames=16, guidance_scale=7.5, num_inference_steps=25, generator=generator ) pipe.disable_free_init() frames = output.frames[0] export_to_gif(frames, "animation_butterworth.gif")