人像动画工具LivePortrait跨平台部署指南:从环境配置到模型加速
【免费下载链接】LivePortraitBring portraits to life!项目地址: https://gitcode.com/GitHub_Trending/li/LivePortrait
AI驱动的人像动画技术正深刻改变内容创作方式,LivePortrait作为开源解决方案,支持本地部署的高效人像动画生成。本指南采用"准备-执行-进阶"三段式框架,帮助技术新手在Windows、macOS和Linux系统中完成从环境搭建到高级功能使用的全流程部署。
准备阶段:兼容性检测与环境准备
兼容性检测清单
| 系统要求 | 最低配置 | 推荐配置 |
|---|---|---|
| 操作系统 | Windows 10/11、macOS 12+、Ubuntu 20.04+ | Windows 11、macOS 13+、Ubuntu 22.04+ |
| 处理器 | 四核CPU | 八核及以上CPU |
| 内存 | 8GB RAM | 16GB RAM |
| 显卡 | 集成显卡 | NVIDIA显卡(4GB+显存)或Apple Silicon |
| 磁盘空间 | 10GB可用空间 | 20GB SSD可用空间 |
⚠️ 注意事项:Linux用户需确保系统已安装CUDA Toolkit 11.8+,macOS用户必须使用Apple Silicon芯片才能获得最佳性能。
必备软件安装
Git安装
- Windows:从Git官网下载安装程序,勾选"Add Git to PATH"选项
- macOS:
brew install git - Linux:
sudo apt install git
验证命令:git --version(应显示2.30.0以上版本)
Conda安装
- 推荐使用Miniconda:
# Windows用户下载安装程序后运行 # macOS/Linux用户 wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh bash Miniconda3-latest-Linux-x86_64.sh
验证命令:conda --version(应显示4.10.0以上版本)
FFmpeg安装
- Windows:下载ffmpeg.exe和ffprobe.exe并放置到项目根目录
- macOS:
brew install ffmpeg - Linux:
sudo apt install ffmpeg libsox-dev
验证命令:ffmpeg -version(应显示4.0以上版本)
执行阶段:分步部署与验证
1. 获取项目代码
目标:将LivePortrait代码库克隆到本地
操作:
git clone https://gitcode.com/GitHub_Trending/li/LivePortrait cd LivePortrait验证:ls命令应显示项目文件列表,包括app.py、requirements.txt等
2. 创建虚拟环境
目标:建立独立的Python运行环境
操作:
conda create -n LivePortrait python=3.10 -y conda activate LivePortrait验证:终端提示符应显示"(LivePortrait)"前缀
3. 安装依赖包
目标:根据操作系统安装对应依赖
Windows/Linux用户
# 检查CUDA版本 nvcc -V # 根据CUDA版本安装PyTorch (以CUDA 11.8为例) pip install torch==2.3.0 torchvision==0.18.0 torchaudio==2.3.0 --index-url https://download.pytorch.org/whl/cu118 # 安装其余依赖 pip install -r requirements.txtmacOS用户
pip install -r requirements_macOS.txt验证:pip list | grep torch(应显示已安装的PyTorch版本)
4. 下载预训练模型
目标:获取模型权重文件
操作:
# 安装huggingface_hub pip install -U "huggingface_hub[cli]" # 设置镜像(国内用户) export HF_ENDPOINT=https://hf-mirror.com # 下载模型 huggingface-cli download KwaiVGI/LivePortrait --local-dir pretrained_weights --exclude "*.git*" "README.md" "docs"验证:ls pretrained_weights(应显示多个模型文件和文件夹)
5. 基础功能验证
目标:测试基本人像动画生成功能
操作:
# Windows/Linux python inference.py # macOS PYTORCH_ENABLE_MPS_FALLBACK=1 python inference.py验证:程序执行完成后,animations目录应生成动画文件
进阶阶段:高级功能与性能优化
图形界面启动
目标:使用Gradio界面进行可视化操作
操作:
# 人类模式 python app.py # 动物模式 python app_animals.py程序启动后,会自动在浏览器打开界面,可通过上传图片和视频生成动画。
动物模型支持
目标:启用动物肖像动画功能
操作:
# 构建MultiScaleDeformableAttention组件 cd src/utils/dependencies/XPose/models/UniPose/ops python setup.py build install cd - # 运行动物模型推理 python inference_animals.py -s assets/examples/source/s39.jpg -d assets/examples/driving/wink.pkl --driving_multiplier 1.75 --no_flag_stitching模型加速技巧
💡 优化建议:根据硬件配置调整推理参数
| 硬件类型 | 优化参数 | 预期加速效果 |
|---|---|---|
| 低端GPU | --batch_size 1 --low_res | 提升30%速度 |
| 中端GPU | --fp16 --num_workers 4 | 提升50%速度 |
| 高端GPU | --batch_size 4 --fp16 | 提升100%速度 |
| Apple Silicon | --mps --low_mem | 提升40%速度 |
姿态编辑功能
目标:手动调整肖像姿态和表情
操作:在Gradio界面的"Retargeting"选项卡中,拖动滑块调整参数,点击"Retargeting"按钮应用更改。
故障诊断与解决方案
常见问题处理流程
模型下载失败
- 检查网络连接
- 尝试设置镜像:
export HF_ENDPOINT=https://hf-mirror.com - 手动下载模型并解压到pretrained_weights目录
CUDA相关错误
- 验证CUDA版本:
nvcc -V - 确保PyTorch版本与CUDA匹配
- 尝试降级CUDA至11.8版本
- 验证CUDA版本:
性能问题
- 对于macOS:添加环境变量
PYTORCH_ENABLE_MPS_FALLBACK=1 - 减少输入视频分辨率
- 关闭其他占用GPU的应用程序
- 对于macOS:添加环境变量
附录:自动化部署脚本
Windows批处理脚本(deploy_windows.bat)
@echo off git clone https://gitcode.com/GitHub_Trending/li/LivePortrait cd LivePortrait call conda create -n LivePortrait python=3.10 -y call conda activate LivePortrait pip install torch==2.3.0 torchvision==0.18.0 torchaudio==2.3.0 --index-url https://download.pytorch.org/whl/cu118 pip install -r requirements.txt pip install -U "huggingface_hub[cli]" set HF_ENDPOINT=https://hf-mirror.com huggingface-cli download KwaiVGI/LivePortrait --local-dir pretrained_weights --exclude "*.git*" "README.md" "docs" echo 安装完成,可运行 python app.py 启动界面Shell脚本(deploy_linux_macos.sh)
#!/bin/bash git clone https://gitcode.com/GitHub_Trending/li/LivePortrait cd LivePortrait conda create -n LivePortrait python=3.10 -y conda activate LivePortrait if [[ "$OSTYPE" == "darwin"* ]]; then pip install -r requirements_macOS.txt else pip install torch==2.3.0 torchvision==0.18.0 torchaudio==2.3.0 --index-url https://download.pytorch.org/whl/cu118 pip install -r requirements.txt fi pip install -U "huggingface_hub[cli]" export HF_ENDPOINT=https://hf-mirror.com huggingface-cli download KwaiVGI/LivePortrait --local-dir pretrained_weights --exclude "*.git*" "README.md" "docs" echo "安装完成,可运行 python app.py 启动界面"通过以上步骤,你已完成LivePortrait的全平台部署。如需获取最新功能,可定期执行git pull更新代码库。如有其他问题,可查阅项目中的官方文档或提交issue获取支持。
【免费下载链接】LivePortraitBring portraits to life!项目地址: https://gitcode.com/GitHub_Trending/li/LivePortrait
创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考