はじめに
「Hallo2」は顔画像と音声ファイルからしゃべっている動画を作成するモデルです。「リップシンク」モデルと表現されることもあります。以前「SadTalker」というのを使ったことがあります。それと同じようなことができます。touch-sp.hatenablog.com
PC環境
Hallo2のGitHubには公式にサポートしているのはUbuntuのみと書かれています。今回Windowsで動作させてみました。
Windows 11 CUDA 11.8 Python 3.10
Python環境構築
git clone https://github.com/fudan-generative-vision/hallo2 cd hallo2
pip install torch==2.2.2 torchvision==0.17.2 torchaudio==2.2.2 --index-url https://download.pytorch.org/whl/cu118 pip install -r requirements.txt
GitHub通りに環境構築して実行するとエラーがでます。
ImportError: cannot import name 'cached_download' from 'huggingface_hub'
huggingface-hubをダウングレードする必要がありました。
pip uninstall huggingface-hub pip install huggingface-hub==0.25.2
再度実行するとxFormersとTritonに関する警告がでます。
WARNING[XFORMERS]: xFormers can't load C++/CUDA extensions. xFormers was built for: PyTorch 2.2.2+cu121 with CUDA 1201 (you have 2.2.2+cu118) Python 3.10.11 (you have 3.10.11) Please reinstall xformers (see https://github.com/facebookresearch/xformers#installing-xformers) Memory-efficient attention, SwiGLU, sparse and more won't be available. Set XFORMERS_MORE_DETAILS=1 for more details
A matching Triton is not available, some optimizations will not be enabled
これらを踏まえて新たにrequirements.txtを作り直しました。
以下の2行で環境構築できると思います。
WindowsからTritonが使用できないので警告は残りますが実行は可能です。
pip install torch==2.2.2 torchvision==0.17.2 torchaudio==2.2.2 xformers --index-url https://download.pytorch.org/whl/cu118 pip install -r https://raw.githubusercontent.com/dai-ichiro/myEnvironments/refs/heads/main/Hallo2/requirements_win.txt
学習済みモデルのダウンロード
GitHub通りに行いました。git lfs install git clone https://huggingface.co/fudan-generative-ai/hallo2 pretrained_models
「stable-diffusion-v1-5/unet/diffusion_pytorch_model.safetensors」と「hallo2/net.pth」の二つのダウンロードに失敗したので手動でダウンロードしました。
実行
python scripts/inference_long.py --config ./configs/inference/long.yaml
追加で超解像を行うことができます。
python scripts/video_sr.py --input_path ./output_long\debug\1\merge_video.mp4 --output_path final_output --bg_upsampler realesrgan --face_upsample
結果
用意した画像はサンプルとしてGitHubにあった画像1枚です。結果はGoogle Bloggerに載せておきます。
support-touchsp.blogspot.com
補足
WindowsでTritonを使う方法はこちらを見て下さい。touch-sp.hatenablog.com