eightban's memo

残しておきたい記事をまとめてみました。このブログに書いてあるドキュメントやブログで配布しているファイルの使用によって発生するいかなる損害に対してもこのブログの管理者は責任を負いません。使用する場合は自己責任のもとに使用してください。

Python

magic-animate 静止画からアニメーションを作成できる AI を Windows パソコンにインストールする

更新日:

magic-animate

静止画とDensePose モーションシーケンスからアニメーションを作成できる AI です。拡散モデルを用いているのでモデルをダウンロードする必要があります

インストール

/ WinPython仮想環境でAnaconda を使わない方法

ffmpegのダウンロードと展開ffmpeg-master-latest-win64-gpl.zip

Releases · BtbN/FFmpeg-Builds (github.com)

"D:\WinPython\ffmpeg"に展開します

クローン

"D:\WinPython\#winpythonPrompt.bat"実行した後に次のコマンドを流します

git clone https://github.com/magic-research/magic-animate

次のコードが書かれたバッチファイルを作成し実行すると仮想環境が作成されます。その後仮想環境にインストール

@echo off
call %~dp0\scripts\env_for_icons.bat  %*
SET PATH=%PATH%;%WINPYDIRBASE%\PortableGit;%WINPYDIRBASE%\PortableGit\bin
SET PATH=%PATH%;%WINPYDIRBASE%\ffmpeg\bin

If not exist %WINPYDIRBASE%\content mkdir  %WINPYDIRBASE%\content 

set APP_NAME=magic-animate
set APP_DIR=%WINPYDIRBASE%\content\%APP_NAME%
echo %APP_DIR%
cd %APP_DIR%
if not defined VENV_DIR (set "VENV_DIR=%APP_DIR%\venv")
if EXIST %VENV_DIR% goto :activate_venv


::python.exe -m venv "%VENV_DIR%" 
python.exe -m venv "%VENV_DIR%" --system-site-packages 
if %ERRORLEVEL% == 0 goto :activate_venv
echo Unable to create venv 
goto :skip_venv

:activate_venv
call "%VENV_DIR%\Scripts\activate"
::pip install -r requirements.txt
::If  exist %WINPYDIRBASE%\content\%APP_NAME%\GPT_SoVITS\pretrained_models\s2D488k.pth goto :skip_cmd
cmd.exe /k
goto :skip_venv
:skip_cmd
::python.exe webui.py
:skip_venv

必要なライブラリーをインストール

pip install -r requirements.txt

フォルダーの作成とチェンジディレクトリ

(venv) D:\WinPython\content\magic-animate>md pretrained_models
(venv) D:\WinPython\content\magic-animate>cd pretrained_models

小さいファイルのクローン

git clone https://huggingface.co/runwayml/stable-diffusion-v1-5 

サイズの大きいファイルのダウンロード

runwayml/stable-diffusion-v1-5 at main (huggingface.co)

"D:\WinPython\content\magic-animate\pretrained_models\stable-diffusion-v1-5\text_encoder\pytorch_model.bin"
"D:\WinPython\content\magic-animate\pretrained_models\stable-diffusion-v1-5\unet\diffusion_pytorch_model.bin"
"D:\WinPython\content\magic-animate\pretrained_models\stable-diffusion-v1-5\v1-5-pruned-emaonly.safetensors"

stabilityai/sd-vae-ft-mse at main (huggingface.co)

git lfs install
git lfs clone https://huggingface.co/zcxu-eric/MagicAnimate
git clone https://huggingface.co/stabilityai/sd-vae-ft-mse

不要なファイルを削除します

"D:\WinPython\content\magic-animate\pretrained_models\sd-vae-ft-mse\diffusion_pytorch_model.bin"

diffusers のインストール

pip install  diffusers 


/magicanimate/pipelines/pipeline_animation.py and modify following line.
from diffusers.pipeline.pipeline_utils import DiffusionPipeline
-> from diffusers import DiffusionPipeline

einops avのインストール

pip install einops  av

xformers のインストール

pip3 install -U xformers --index-url https://download.pytorch.org/whl/cu118

実行

python -m magicanimate.pipelines.animation --config configs/prompts/animation.yaml

TypeError: write_frames() got an unexpected keyword argument 'audio_path'バージョンが古いと出る場合があります。ベースでアップデートインストール

pip show imageio_ffmpeg

 pip install --upgrade imageio-ffmpeg
A matching Triton is not available, some optimizations will not be enabled.
Error caught was: No module named 'triton'

Windows環境のxformersではTritonがサポートされないことが原因。エラーを無視。

"D:\WinPython\content\magic-animate\configs\prompts\animation.yaml"を修正して入力ファイルを少ないした方が時間が早く終わります

結果

"D:\WinPython\content\magic-animate\samples\animation-2024-01-31T19-49-57\videos\monalisa_running\grid.mp4"

"D:\WinPython\content\magic-animate\samples\animation-2024-01-31T19-49-57\videos\monalisa_running.mp4"

Web での実行

そのままでは動かなかったのでフォルダを変更しましたdemo1

"D:\WinPython\content\magic-animate\demo1\gradio_animate.py"も変更します

from .demo1.animate import MagicAnimate
python -m demo1.gradio_animate

変換後のアニメーションだけにする スケジューラーを変更する

"D:\WinPython\content\magic-animate\demo1\animate.py"

#            save_videos_grid(samples_per_video, animation_path)
            save_videos_grid(samples_per_video[-1:], animation_path)
            scheduler=UniPCMultistepScheduler(**OmegaConf.to_container(inference_config.noise_scheduler_kwargs)),
#            scheduler=DDIMScheduler(**OmegaConf.to_container(inference_config.noise_scheduler_kwargs)),

Triton のインストール

GitHub - openai/triton: Development repository for the Triton language and compiler

ソースからビルドするかバイナリーをインストールします

サイトからダウンロードできなくなる場合があるのでダウンロードしておくことをおすすめします

r4ziel/xformers_pre_built at main (huggingface.co)

pip install https://huggingface.co/r4ziel/xformers_pre_built/resolve/main/triton-2.0.0-cp310-cp310-win_amd64.whl

https://github.com/wkpark/triton

-Python

Copyright© eightban's memo , 2024 All Rights Reserved Powered by STINGER.