当前位置:   article > 正文

数字人解决方案——Wav2lip本地部署_本地部署数字人

本地部署数字人

1、安装anaconda

  • anaconda自行下载安装

2、下载wav2lip 

github中搜索wav2lip

  1. git clone https://github.com/Rudrabha/Wav2Lip.git 

源码到本地 

准备脸部检测预训练模型

下载地址:https://www.adrianbulat.com/downloads/python-fan/s3fd-619a316812.pth

将下载的模型文件放置在face_detection/detection/sfd目录下,并重命名为s3fd.pth

准备Wav2Lip模型文件 

依据下图下载两个模型文件

下载模型放在

使用conda创建新的虚拟环境并激活 

conda create -n wav2lip python=3.6

通过conda环境激活窗口

进入到wav2lip目录 

执行安装包.bat命令 ,本地化安装运行环境包,launcher.py,安装包.bat,代码在文章末尾,复制到Wav2lip文件夹下新建文件,复制源码进去即可

若安装报错,requirements.txt  版本修改为

librosa>=0.7.0

numpy>=1.17.3

opencv-contrib-python>=4.4.0.44

opencv-python>=4.4.0.44

torch>=1.7.1

torchvision>=0.8.2

tqdm>=4.45.0

numba>=0.48

最后可以执行合成命令了,也可以新建个bat文件,保存下执行命令运行:

  1. venv\Scripts\python inference.py --checkpoint_path checkpoints/wav2lip_gan.pth --face examples/driven_video/yxn.mp4 --audio examples/driven_audio/a.wav
  2.  

 安装包.bat

  1. @echo off
  2. IF NOT EXIST venv (
  3. python -m venv venv
  4. ) ELSE (
  5. echo venv folder already exists, skipping creation...
  6. )
  7. call .\venv\Scripts\activate.bat
  8. set PYTHON="venv\Scripts\Python.exe"
  9. echo venv %PYTHON%
  10. %PYTHON% Launcher.py
  11. echo.
  12. echo Launch unsuccessful. Exiting.
  13. pause

 launcher.py 

  1. # this scripts installs necessary requirements and launches main program in webui.py
  2. # borrow from : https://github.com/AUTOMATIC1111/stable-diffusion-webui/blob/master/launch.py
  3. import subprocess
  4. import os
  5. import sys
  6. import importlib.util
  7. import shlex
  8. import platform
  9. import json
  10. python = sys.executable
  11. git = os.environ.get('GIT', "git")
  12. index_url = os.environ.get('INDEX_URL', "")
  13. stored_commit_hash = None
  14. skip_install = False
  15. dir_repos = "repositories"
  16. script_path = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
  17. if 'GRADIO_ANALYTICS_ENABLED' not in os.environ:
  18. os.environ['GRADIO_ANALYTICS_ENABLED'] = 'False'
  19. def check_python_version():
  20. is_windows = platform.system() == "Windows"
  21. major = sys.version_info.major
  22. minor = sys.version_info.minor
  23. micro = sys.version_info.micro
  24. if is_windows:
  25. supported_minors = [10]
  26. else:
  27. supported_minors = [7, 8, 9, 10, 11]
  28. if not (major == 3 and minor in supported_minors):
  29. raise (f"""
  30. INCOMPATIBLE PYTHON VERSION
  31. This program is tested with 3.10.6 Python, but you have {major}.{minor}.{micro}.
  32. If you encounter an error with "RuntimeError: Couldn't install torch." message,
  33. or any other error regarding unsuccessful package (library) installation,
  34. please downgrade (or upgrade) to the latest version of 3.10 Python
  35. and delete current Python and "venv" folder in WebUI's directory.
  36. You can download 3.10 Python from here: https://www.python.org/downloads/release/python-3109/
  37. {"Alternatively, use a binary release of WebUI: https://github.com/AUTOMATIC1111/stable-diffusion-webui/releases" if is_windows else ""}
  38. Use --skip-python-version-check to suppress this warning.
  39. """)
  40. def commit_hash():
  41. global stored_commit_hash
  42. if stored_commit_hash is not None:
  43. return stored_commit_hash
  44. try:
  45. stored_commit_hash = run(f"{git} rev-parse HEAD").strip()
  46. except Exception:
  47. stored_commit_hash = "<none>"
  48. return stored_commit_hash
  49. def run(command, desc=None, errdesc=None, custom_env=None, live=False):
  50. if desc is not None:
  51. print(desc)
  52. if live:
  53. result = subprocess.run(command, shell=True, env=os.environ if custom_env is None else custom_env)
  54. if result.returncode != 0:
  55. raise RuntimeError(f"""{errdesc or 'Error running command'}.
  56. Command: {command}
  57. Error code: {result.returncode}""")
  58. return ""
  59. result = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True, env=os.environ if custom_env is None else custom_env)
  60. if result.returncode != 0:
  61. message = f"""{errdesc or 'Error running command'}.
  62. Command: {command}
  63. Error code: {result.returncode}
  64. stdout: {result.stdout.decode(encoding="utf8", errors="ignore") if len(result.stdout)>0 else '<empty>'}
  65. stderr: {result.stderr.decode(encoding="utf8", errors="ignore") if len(result.stderr)>0 else '<empty>'}
  66. """
  67. raise RuntimeError(message)
  68. return result.stdout.decode(encoding="utf8", errors="ignore")
  69. def check_run(command):
  70. result = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
  71. return result.returncode == 0
  72. def is_installed(package):
  73. try:
  74. spec = importlib.util.find_spec(package)
  75. except ModuleNotFoundError:
  76. return False
  77. return spec is not None
  78. def repo_dir(name):
  79. return os.path.join(script_path, dir_repos, name)
  80. def run_python(code, desc=None, errdesc=None):
  81. return run(f'"{python}" -c "{code}"', desc, errdesc)
  82. def run_pip(args, desc=None):
  83. if skip_install:
  84. return
  85. index_url_line = f' --index-url {index_url}' if index_url != '' else ''
  86. return run(f'"{python}" -m pip {args} --prefer-binary{index_url_line}', desc=f"Installing {desc}", errdesc=f"Couldn't install {desc}")
  87. def check_run_python(code):
  88. return check_run(f'"{python}" -c "{code}"')
  89. def git_clone(url, dir, name, commithash=None):
  90. # TODO clone into temporary dir and move if successful
  91. if os.path.exists(dir):
  92. if commithash is None:
  93. return
  94. current_hash = run(f'"{git}" -C "{dir}" rev-parse HEAD', None, f"Couldn't determine {name}'s hash: {commithash}").strip()
  95. if current_hash == commithash:
  96. return
  97. run(f'"{git}" -C "{dir}" fetch', f"Fetching updates for {name}...", f"Couldn't fetch {name}")
  98. run(f'"{git}" -C "{dir}" checkout {commithash}', f"Checking out commit for {name} with hash: {commithash}...", f"Couldn't checkout commit {commithash} for {name}")
  99. return
  100. run(f'"{git}" clone "{url}" "{dir}"', f"Cloning {name} into {dir}...", f"Couldn't clone {name}")
  101. if commithash is not None:
  102. run(f'"{git}" -C "{dir}" checkout {commithash}', None, "Couldn't checkout {name}'s hash: {commithash}")
  103. def git_pull_recursive(dir):
  104. for subdir, _, _ in os.walk(dir):
  105. if os.path.exists(os.path.join(subdir, '.git')):
  106. try:
  107. output = subprocess.check_output([git, '-C', subdir, 'pull', '--autostash'])
  108. print(f"Pulled changes for repository in '{subdir}':\n{output.decode('utf-8').strip()}\n")
  109. except subprocess.CalledProcessError as e:
  110. print(f"Couldn't perform 'git pull' on repository in '{subdir}':\n{e.output.decode('utf-8').strip()}\n")
  111. def run_extension_installer(extension_dir):
  112. path_installer = os.path.join(extension_dir, "install.py")
  113. if not os.path.isfile(path_installer):
  114. return
  115. try:
  116. env = os.environ.copy()
  117. env['PYTHONPATH'] = os.path.abspath(".")
  118. print(run(f'"{python}" "{path_installer}"', errdesc=f"Error running install.py for extension {extension_dir}", custom_env=env))
  119. except Exception as e:
  120. print(e, file=sys.stderr)
  121. def prepare_environment():
  122. global skip_install
  123. torch_command = os.environ.get('TORCH_COMMAND', "pip install torch==1.12.1+cu113 torchvision==0.13.1+cu113 torchaudio==0.12.1 --extra-index-url https://download.pytorch.org/whl/cu113")
  124. ## check windows
  125. if sys.platform != 'win32':
  126. requirements_file = os.environ.get('REQS_FILE', "req.txt")
  127. else:
  128. requirements_file = os.environ.get('REQS_FILE', "requirements.txt")
  129. commit = commit_hash()
  130. print(f"Python {sys.version}")
  131. print(f"Commit hash: {commit}")
  132. run_pip(f"install -r \"{requirements_file}\"", "requirements for SadTalker WebUI (may take longer time in first time)")
  133. if sys.platform != 'win32' and not is_installed('tts'):
  134. run_pip(f"install TTS", "install TTS individually in SadTalker, which might not work on windows.")
  135. def start():
  136. print(f"Launching SadTalker Web UI")
  137. from app_sadtalker import sadtalker_demo
  138. demo = sadtalker_demo()
  139. demo.queue()
  140. demo.launch()
  141. if __name__ == "__main__":
  142. prepare_environment()

 启动生产合成视频.bat

  1. @echo off
  2. set PYTHON="venv\Scripts\Python.exe"
  3. echo venv %PYTHON%
  4. %PYTHON% inference.py --checkpoint_path checkpoints/wav2lip_gan.pth --face examples/driven_video/yxn.mp4 --audio examples/driven_audio/test.wav
  5. echo.
  6. echo Launch unsuccessful. Exiting.
  7. pause

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小蓝xlanll/article/detail/625728
推荐阅读
相关标签
  

闽ICP备14008679号