Google Colab で AnimateDiff を試す
「Google Colab」で「AnimateDiff」を試したので、まとめました。diffusers版は動作が安定してなかったので、公式リポジトリ版を使用してます。
1. AnimateDiff
「AnimateDiff」は、1枚の画像から一貫性のあるアニメーションを生成する機能です。diffusersにもAnimateDiffが追加されましたが、動作が怪しかったので、今回は公式リポジトリを利用しています。
2. AnimateDiff のモデル
AnimateDiff で提供されているモデルは、次のとおりです。
2-1. モーションモジュール
2-2. モーションLoRA
モデルは、Google Drive / HuggingFace/ CivitAIで入手できます。
3. Colabでの実行
Colabでの実行手順は、次のとおりです。
(1) パッケージのインストール。
# パッケージのインストール
!git clone https://github.com/guoyww/AnimateDiff
!pip install -q torch==2.0.1+cu118 torchvision==0.15.2+cu118 torchaudio==2.0.2+cu118 torchtext==0.15.2 torchdata==0.6.1 --extra-index-url https://download.pytorch.org/whl/cu118 -U
!pip install einops omegaconf safetensors diffusers[torch]==0.11.1 transformers xformers==0.0.20 triton==2.0.0
!rm -rf /content/AnimateDiff/models/StableDiffusion
!git clone -b fp16 https://huggingface.co/runwayml/stable-diffusion-v1-5 /content/AnimateDiff/models/StableDiffusion/
%cd AnimateDiff
(2) モデルのダウンロード。
今回は、「Stable Diffusion 1.5」ベースの「Counterfeit-V3.0」を使用します。
# モーションモジュールのダウンロード
!wget -P /content/AnimateDiff/models/Motion_Module https://huggingface.co/camenduru/AnimateDiff/resolve/main/mm_sd_v15_v2.ckpt
# モデルのダウンロード
!wget -P /content/AnimateDiff/models/DreamBooth_LoRA https://huggingface.co/gsdf/Counterfeit-V3.0/resolve/main/Counterfeit-V3.0_fix_fp16.safetensors
(3) コンフィグファイル「0-Counterfeit-V3.0.yaml」を作成して、「AnimateDiff/configs/prompts/v2」に配置。
使用するモデルとプロンプトを指定しています。
・0-Counterfeit-V3.0.yaml
RealisticVision:
inference_config: "configs/inference/inference-v2.yaml"
motion_module:
- "models/Motion_Module/mm_sd_v15_v2.ckpt"
dreambooth_path: "models/DreamBooth_LoRA/Counterfeit-V3.0_fix_fp16.safetensors"
lora_model_path: ""
seed: [1]
steps: 25
guidance_scale: 7.5
prompt:
- "cute cat ear maid, best quality, high quality"
n_prompt:
- "worst quality, low quality, monochrome"
(4) 「AnimateDiff/animatediff/utils/convert_from_ckpt.py」の726行目を以下のように修正。
動画生成時に、以下のエラーが発生したので、strictをはずしてます。
RuntimeError: Error(s) in loading state_dict for CLIPTextModel:
Unexpected key(s) in state_dict: "text_model.embeddings.position_ids".
(5) 動画生成の実行。
数分ほどで動画生成され、AnimateDiff/samplesに出力されます。
# 動画生成の実行
!python -m scripts.animate --config /content/AnimateDiff/configs/prompts/v2/0-Counterfeit-V3.0.yaml --pretrained_model_path /content/AnimateDiff/models/StableDiffusion
・sample.gif
この記事が気に入ったらサポートをしてみませんか?