LivePortrait 本地部署教程,强大且开源的可控人像AI视频生成

 
 

 

 

1,准备工作,本地下载代码并准备环境,运行命令前需安装git

没有外网环境的朋友可以直接点击【网盘打包下载

git clone https://github.com/KwaiVGI/LivePortrait
cd LivePortrait

# create env using conda
conda create -n LivePortrait python=3.9
conda activate LivePortrait

# install dependencies with pip
# for Linux and Windows users
pip install -r requirements.txt
# for macOS with Apple Silicon users
pip install -r requirements_macOS.txt

注意:确保您的系统已安装FFmpeg,包括ffmpegffprobe!不会安装?看这个FFmpeg 【安装教程

2. 下载预训练权重

下载预训练权重的最简单方法是从 HuggingFace 下载:

# first, ensure git-lfs is installed, see: https://docs.github.com/en/repositories/working-with-files/managing-large-files/installing-git-large-file-storage
git lfs install
# clone and move the weights
git clone https://huggingface.co/KwaiVGI/LivePortrait temp_pretrained_weights
mv temp_pretrained_weights/* pretrained_weights/
rm -rf temp_pretrained_weights

 

非海外用户,没有外网环境的朋友,你可以从Google Drive百度云网盘下载所有预训练权重。解压并将它们放在 中./pretrained_weights

确保目录结构如下,或包含:

pretrained_weights
├── insightface
│   └── models
│       └── buffalo_l
│           ├── 2d106det.onnx
│           └── det_10g.onnx
└── liveportrait
    ├── base_models
    │   ├── appearance_feature_extractor.pth
    │   ├── motion_extractor.pth
    │   ├── spade_generator.pth
    │   └── warping_module.pth
    ├── landmark.onnx
    └── retargeting_models
        └── stitching_retargeting_module.pth

3.推理使用

# For Linux and Windows
python inference.py

# For macOS with Apple Silicon, Intel not supported, this maybe 20x slower than RTX 4090
PYTORCH_ENABLE_MPS_FALLBACK=1 python inference.py

如果脚本成功运行,你会得到一个名为 的输出mp4文件animations/s6--d0_concat.mp4。此文件包含以下结果:驾驶视频,输入图像或视频,以及生成的结果。

图像

或者您可以通过指定-s和参数-d来更改输入

# source input is an image
python inference.py -s assets/examples/source/s9.jpg -d assets/examples/driving/d0.mp4

# source input is a video ✨
python inference.py -s assets/examples/source/s13.mp4 -d assets/examples/driving/d0.mp4

# more options to see
python inference.py -h

参照视频自动裁剪 📢📢📢

 

要使用您自己的参照视频,我们建议:⬇️

  • 将其裁剪为1:1 的宽高比(例如 512×512 或 256×256 像素),或通过 启用自动裁剪--flag_crop_driving_video
  • 重点关注头部区域,与示例视频类似。
  • 尽量减少肩部运动。
  • 确保参照视频的第一帧是正面且表情中性

以下是自动裁剪的案例--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选项来调整比例和偏移量,或者手动进行调整。

动作模板制作

 

您还可以使用自动生成的以 结尾的运动模板文件来.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

4. Gradio 可视化界面操作

在Gradio的可视化界面下可以获得更好的体验,适合新手使用,只需运行下面安装代码即可:

# For Linux and Windows users (and macOS with Intel??)
python app.py

# For macOS with Apple Silicon users, Intel not supported, this maybe 20x slower than RTX 4090
PYTORCH_ENABLE_MPS_FALLBACK=1 python app.py

您可以指定--server_port、、--share参数--server_name来满足您的需求!

🚀 它们还提供了加速选项--flag_do_torch_compile。首次推理会触发优化过程(约一分钟),使后续推理速度提高 20-30%。性能提升可能因 CUDA 版本的不同而有所差异。

# enable torch.compile for faster inference
python app.py --flag_do_torch_compile

注意:Windows 和 macOS 不支持此方法。或者,在HuggingFace上轻松尝试一下🤗

5. 推理速度评估

 

下方提供了一个脚本来评估每个模块的推理速度:

# For NVIDIA GPU
python speed.py

以下是使用原生 PyTorch 框架在 RTX 4090 GPU 上推断一帧的结果torch.compile

模型 参数(米) 模型大小(MB) 推理(毫秒)
外观特征提取器 0.84 3.3 0.82
运动提取器 28.12 108 0.84
铲形发电机 55.37 212 7.59
变形模块 45.53 174 5.21
拼接和重定向模块 0.23 2.3 0.31

注意:拼接和重定向模块的值代表三个连续 MLP 网络的组合参数数量和总推理时间。

当然如果你没有一张好的显卡,无法本地运行,那么可以在huggingface上免费体验:【点击前往】在线使用

详细的LivePortrait安装教程如下:

THE END
喜欢就支持一下吧
点赞2178 分享
快速破解WiFi密码!完整教程,包教包会-零度博客
Qwen2.5-VL 本地部署!最强视觉 AI 大模型,免费开源,离线可用,实测效果惊艳?| 零度解说-零度博客

Qwen2.5-VL 本地部署!最强视觉 AI 大模型,免费开源,离线可用,实测效果惊艳?| 零度解说

https://www.youtube.com/watch?v=x5XS0mNT_FE   Qwen2.5-VL 最强的开源视觉大模型下载:https://www.freedidi.com/18497.html  
admin的头像-零度博客admin
1.2W+1913
Thunderbird 终于修复Linux通知bug! 该问题存在长达24年-零度博客

Thunderbird 终于修复Linux通知bug! 该问题存在长达24年

7月23日消息,Mozilla公司的Thunderbird团队在时隔24年后,终于为使用GNOME和KDE桌面环境的Linux用户带来了系统托盘邮件通知功能。 这项提案最早可以追溯到1999年11月12日星期五,Mozilla公司于...
Team Red Miner + Gminer挖矿程序下载-零度博客

Team Red Miner + Gminer挖矿程序下载

1.Team Red Miner:【点击下载】 2.挖矿矿池获取:【点击进入】 3.Gminer:【点击下载】 4.实时算力和收益查询网站:【点击进入】  5.推荐的钱包:BRD 【点击获取】
admin的头像-零度博客admin
1.6W+2251
如何更改 iTunes 和 App Store 国家/地区以及您首先需要了解的内容-零度博客

如何更改 iTunes 和 App Store 国家/地区以及您首先需要了解的内容

考虑更改您的 iTunes 和 App Store 国家/地区?在继续执行此操作之前,您需要了解以下内容。 我们可能生活在一个相互关联的世界中,但国际法律和政策无法始终跟上我们的喷气式飞机方式。如果您...
admin的头像-零度博客admin
1.6W+2251
谷歌在 Windows PC 上推出 Android 游戏测试版 2-零度博客

谷歌在 Windows PC 上推出 Android 游戏测试版 2

谷歌正在推出其应用程序的有限测试版,以便将 Android 游戏带到 Windows PC。Google Play Games 将于今天在香港、韩国和台湾推出测试版,让 Windows PC 用户可以玩热门的 Android 游戏,如Mobil...
admin的头像-零度博客admin
1.5W+2251
黑客一直在向伪装成礼物的美国公司发送充满恶意软件的 U 盘-零度博客

黑客一直在向伪装成礼物的美国公司发送充满恶意软件的 U 盘

“恶意 U盘”的伎俩虽然已经很老套了,但显然它仍然在骗子中广受欢迎。 外观友好的 USB 记忆棒是恶意软件传播的载体,与互联网本身一样古老,显然,它们仍然很受犯罪分子的欢迎。 周四,联邦调...
admin的头像-零度博客admin
1.5W+2251
Deep Live Cam:AI实时换脸直播!效果惊人,支持 Windows+Mac-零度博客

Deep Live Cam:AI实时换脸直播!效果惊人,支持 Windows+Mac

最近 Deep Live Cam这款实时AI换脸神器,在GitHub上火爆得一塌糊涂!现在就跟着我一起来看看,这个技术怎么让我们的视频制作和创意表达变得无限可能! 功能简介 Deep Live Cam,使用尖端的AI技...
admin的头像-零度博客admin
3.9W+3259
手机 连接到您的 PC电脑!任何地方,完全免费 | 零度解说-零度博客