環境
Ubuntu 22.04 on WSL2 CUDA 12.1 Python 3.10 torch==2.1.1+cu121
Python環境構築
1行で済むようにrequirements.txtを作成しました。pip install -r https://raw.githubusercontent.com/dai-ichiro/myEnvironments/main/AnimateDiff_SDXL/requirements_cu121.txt
リポジトリのクローン
git clone https://github.com/guoyww/AnimateDiff.git cd AnimateDiff git checkout sdxl
フォルダ構成
「AnimateDiff/models」以下が次のようになるようにモデルをダウンロードしました。models ├── DreamBooth_LoRA │ └── (No Files) ├── Motion_Module │ └── mm_sdxl_v10_beta.ckpt └── StableDiffusion └── stable-diffusion-xl-base-1.0
LoRAは今回使用しませんでした。
エラー内容
「diffusers==0.23.1」を使用したためそのまま実行するとエラーが出ました。ImportError: cannot import name 'AdaGroupNorm' from 'diffusers.models.attention' (/mnt/wsl/PHYSICALDRIVE3p1/animatediff/env/env1116/lib/python3.10/site-packages/diffusers/models/attention.py)
ImportError: cannot import name 'randn_tensor' from 'diffusers.utils' (/home/hoge/documents/animatediff/env/env1116/lib/python3.10/site-packages/diffusers/utils/__init__.py)
スクリプトの変更が必要になります。
スクリプトの変更
「AnimateDiff/animatediff/models/unet_blocks.py」の11行目を変更します。変更前
from diffusers.models.attention import AdaGroupNorm
変更後
from diffusers.models.normalization import AdaGroupNorm
「AnimateDiff/animatediff/pipelines/pipeline_animation.py」の35行目からを変更します。
変更前
from diffusers.utils import ( is_accelerate_available, is_accelerate_version, logging, randn_tensor, replace_example_docstring, BaseOutput, )
変更後
from diffusers.utils import ( is_accelerate_available, is_accelerate_version, logging, replace_example_docstring, BaseOutput, ) from diffusers.utils.torch_utils import randn_tensor
YAMLファイルの準備
以下の内容のYAMLファイルを「sdxl_base.yaml」として「AnimateDiff」フォルダ直下に配置しました。motion_module_path: "models/Motion_Module/mm_sdxl_v10_beta.ckpt" base_model_path: "models/StableDiffusion/stable-diffusion-xl-base-1.0" seed: -1 guidance_scale: 8.5 steps: 50 prompt: - "A panda standing on a surfboard in the ocean in sunset, 4k, high resolution.Realistic, Cinematic, high resolution" n_prompt: - ""
実行
python -m scripts.animate \ --exp_config sdxl_base.yaml \ --L 16 \ --H 1024 \ --W 1024
結果
1024x1024の動画が作成されました。動画はGoogle Bloggerに載せています。
support-touchsp.blogspot.com