LivePortrait 本地部署教程
一句话简介
强大且开源的可控人像AI视频生成项目,在Github上。
在线体验
部署
conda以及项目准备
git clone https://github.com/KwaiVGI/LivePortrait
cd LivePortrait
# create env using conda
conda create -n LivePortrait python=3.9
conda activate LivePortrait
注意看自己操作系统不要全部安装
# for Linux and Windows users
pip install -r requirements.txt
# for macOS with Apple Silicon users
pip install -r requirements_macOS.txt
下载权重
git lfs install
git clone https://huggingface.co/KwaiVGI/LivePortrait temp_pretrained_weights
mv temp_pretrained_weights/* pretrained_weights/
rm -rf temp_pretrained_weights
推理
Linux and Windows
python inference.py
macOS
PYTORCH_ENABLE_MPS_FALLBACK=1 python inference.py
如果脚本成功运行,你会得到文件animations/s6–d0_concat.mp4。包含:驾驶视频,输入图像或视频,以及生成的结果。
自定义视频
参照视频的DISCORD建议
1.将其裁剪为1:1 的宽高比(例如 512×512 或 256×256 像素),或通过 启用自动裁剪–flag_crop_driving_video。
启动自动裁剪的示例:
python inference.py -s assets/examples/source/s9.jpg -d assets/examples/driving/d13.mp4 --flag_crop_driving_video
–scale_crop_driving_video、–vy_ratio_crop_driving_video选项来调整比例和偏移量
2.重点关注头部区域,与示例视频类似。
3.尽量减少肩部运动。
4.确保参照视频的第一帧是正面且表情中性。
动作模板制作
您还可以使用自动生成的以 结尾的运动模板文件来.pkl加速推理,并保护隐私,例如:
python inference.py -s assets/examples/source/s9.jpg -d assets/examples/driving/d5.pkl # portrait animation
python inference.py -s assets/examples/source/s13.mp4 -d assets/examples/driving/d5.pkl # portrait video editing
Gradio 可视化界面操作
–server_port、、–share、-server_name可以修改服务地址
Linux and Windows
python app.py
macOS
PYTORCH_ENABLE_MPS_FALLBACK=1 python app.py
评估脚本
只能NVIDIA GPU
python speed.py