Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

wwdok/SadTalker_ModelScope

Open more actions menu

Repository files navigation

SadTalker within modelscope

For English Reader, please refer to README-EN.md

本仓库是基于 https://github.com/OpenTalker/SadTalker (ed419f275f8a5cae7ca786349787ffebce5bd59e)改编而来,目标是为了将sadtalker仓库封装成modelscope library,这样就能便用几行代码调用sadtalker的能力,方便集成到其他项目里,且本仓库支持使用文本生成语音(edge tts和sambert),无需用户自己上传音频,方便用户快速试玩。

modelscope托管的仓库:https://modelscope.cn/models/wwd123/sadtalker (是本github仓库的精减版,两处的代码有轻微的不同。)

该仓库主要分为两种使用方式,第一种运行时跑的是本仓库根目录下的代码,入口文件是gradio_app.py。另一个是通过modelscope调用、运行时跑的是modelscope cache目录下的代码,入口文件是gradio_app_ms.py、demo.ipynb、ms_wrapper.py。

第一种使用方式

配置环境

以Linux为例,考虑到在安装过程中可能会出现某些pypi包会覆盖安装的问题,安装上讲究顺序。

  1. 如果你还没安装pytorch,先安装pytorch:注意pytorch版本要跟cuda版本对应。
  2. 首先安装kantts:pip install kantts -f https://modelscope.oss-cn-beijing.aliyuncs.com/releases/repo.html, kantts会重装最新版的numpy,这会导致错误,所以下面我们在requirements.txt里重新安装较低版的numpy。这个是为了使用sambert TTS而安装的依赖,如果你不需要sambert TTS的功能,可以不安装它。
  3. 然后安装其他pypi包:pip install -r requirements.txt
  4. 下面是原SadTalker里没有但我发现我本机需要安装的:
tb-nightly
pytorch_wavelets
tensorboardX
typing-extensions==4.3.0
  1. 上面的安装过程中很可能会重装opencv python,而我的服务器没有GUI,所以我需要再重装一下opencv python headless,如果你的电脑有GUI,则跳过这一步。
  2. 安装ffmpeg。首先通过ffmpeg -version检查你的电脑是否已经安装过ffmpeg,没有的话,通过以下两行命令安装:
sudo apt update
sudo apt install ffmpeg

windows安装ffmpeg会有所不同,请百度一下。 7. 下载预训练模型权重:bash download_models.sh。这一步会可能耗时,你也可以把里面的链接粘贴到其他下载器下载,下载完再移动到指定文件夹下。完成后会生成checkpoints和gfpgan/weights文件夹,里面分别有4个模型权重文件。

运行

  • 运行python gradio_app.py启动web ui。

第二种使用方式

配置环境

配置环境教程

运行

from modelscope.pipelines import pipeline

inference = pipeline('talking-head', model='wwd123/sadtalker', model_revision='v1.0.0') # 请使用最新版的model_revision
# 两个必须参数
source_image = 'examples/source_image/man.png' # 请修改成你的实际路径
driven_audio = 'examples/driven_audio/chinese_poem1.wav' # 请修改成你的实际路径
# 其他可选参数
out_dir = './results/' # 输出文件夹
kwargs = {
    'preprocess' : 'full', # 'crop', 'resize', 'full'
    'still_mode' : True,
    'use_enhancer' : False,
    'batch_size' : 1,
    'size' : 256, # 256, 512
    'pose_style' : 0,
    'exp_scale' : 1,
    'result_dir': out_dir
}

video_path = inference(source_image, driven_audio=driven_audio, **kwargs)
print(f"==>> video_path: {video_path}")

本仓库也提供了基于modelscope封装好的sadtalker库的webui:python gradio_app_ms.py。 你可以在Colab上试玩:Open In Colab,也可以在本地试玩demo.ipynb

参数说明

  • source_image: 必填,要驱动的人脸图片的路径。
  • driven_audio: 必填,且必须带上driven_audio=,驱动音频文件的路径,支持wav,mp3格式。
  • preprocess:full:输出的视频帧跟原图一样大,crop:输出的视频帧只有裁剪后的人脸区域。
  • still_mode: 设置为True会减少头部运动。
  • use_enhancer: 是否使用GFPGAN对人脸增强,即增加清晰度。
  • batch_size: 该值代表了Face Renderer阶段并行处理的批次数,因为这一阶段是最耗时的。比如batch size=1时,Face Renderer需要100个时间步,batch size=10时,Face Renderer仅需要10个时间步,但是batch size增大有两个问题,第一,GPU显存占用增大,第二,预处理会占用时间,只有当需要合成的视频比较长时,增大batch size才有用。
  • size: 人脸裁剪成的大小。
  • pose_style: 是条件VAE(即PoseVAE)的条件输入,使用的地方最终位于src/audio2pose_models/cvae.py里的class DECODERdef forward
  • exp_scale: 越大的话表情越夸张。
  • result_dir: 结果输出路径。

About

Use one line code to call SadTalker API with modelscope

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Contributors

Languages

Morty Proxy This is a proxified and sanitized view of the page, visit original site.