欢迎访问我的网站,希望内容对您有用,感兴趣的可以加入免费知识星球。

roop一键换脸

算法 迷途小书童 10个月前 (07-09) 860次浏览 0个评论

环境

  • windows 10 64bit
  • anaconda with python 3.9

简介

roop 是一个只需使用单张图片就可实现快速换脸的开源项目,并提供了 GUI 操作界面。

实操

# 下载源码
git clone https://github.com/s0md3v/roop

# 进入源码目录
cd roop

# 创建一个全新的python虚拟环境
conda create -n faceswap python=3.9

# 激活虚拟环境
conda activate faceswap

# 安装所有依赖库
pip install -r requirements.txt

# 执行,进入GUI界面
python run.py

第一次运行,脚本会自动去下载模型文件,稍等就好

roop

roop

界面非常简单,Select face 选择要替换的人脸照片,右侧的 Select target 是被替换的人脸,可以是图片,也可以是视频,这里弄张女神李嘉欣测试下

roop

界面中间部分有几个设置开关

  • Keep fps 保持目标文件的 fps
  • Keep audio 保留音频
  • Keep frames 保持同样的帧数
  • Many faces 支持多张脸的替换

点击 Start 后选择最后合成图像或视频的路径,开始替换

roop

FAQ

  1. 在安装依赖包的时候报错了,信息如下,出错的包是 basicsr
Downloading http://mirrors.aliyun.com/pypi/packages/86/41/00a6b000f222f0fa4c6d9e1d6dcc9811a374cabb8abb9d408b77de39648c/basicsr-1.4.2.tar.gz (172 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 172.5/172.5 kB ? eta 0:00:00
  Preparing metadata (setup.py) ... error
  error: subprocess-exited-with-error

  × python setup.py egg_info did not run successfully.
  │ exit code: 1
  ╰─> [36 lines of output]
      C:\Users\xgx\Anaconda3\envs\faceswap\lib\site-packages\setuptools\installer.py:27: SetuptoolsDeprecationWarning: setuptools.installer is deprecated. Requirements should be satisfied by a PEP 517 installer.
        warnings.warn(
      WARNING: The repository located at mirrors.aliyun.com is not a trusted or secure host and is being ignored. If this repository is available via HTTPS we recommend you use HTTPS instead, otherwise you may silence this warning and allow it anyway with '--trusted-host mirrors.aliyun.com'.
      ERROR: Could not find a version that satisfies the requirement torch (from versions: none)
      ERROR: No matching distribution found for torch
      Traceback (most recent call last):
        File "C:\Users\xgx\Anaconda3\envs\faceswap\lib\site-packages\setuptools\installer.py", line 82, in fetch_build_egg
          subprocess.check_call(cmd)
        File "C:\Users\xgx\Anaconda3\envs\faceswap\lib\subprocess.py", line 373, in check_call
          raise CalledProcessError(retcode, cmd)
      subprocess.CalledProcessError: Command '['C:\\Users\\xgx\\Anaconda3\\envs\\faceswap\\python.exe', '-m', 'pip', '--disable-pip-version-check', 'wheel', '--no-deps', '-w', 'C:\\Users\\xgx\\AppData\\Local\\Temp\\tmpi5giffsl', '--quiet', 'torch']' returned non-zero exit status 1.

      The above exception was the direct cause of the following exception:

      Traceback (most recent call last):
        File "<string>", line 2, in <module>
        File "<pip-setuptools-caller>", line 34, in <module>
        File "C:\Users\xgx\AppData\Local\Temp\pip-install-h1ub0fvn\basicsr_d42e31333c1c424691d9e5bf78cf4529\setup.py", line 147, in <module>
          setup(
        File "C:\Users\xgx\Anaconda3\envs\faceswap\lib\site-packages\setuptools\__init__.py", line 86, in setup
          _install_setup_requires(attrs)
        File "C:\Users\xgx\Anaconda3\envs\faceswap\lib\site-packages\setuptools\__init__.py", line 80, in _install_setup          resolved_dists = pkg_resources.working_set.resolve(
        File "C:\Users\xgx\Anaconda3\envs\faceswap\lib\site-packages\pkg_resources\__init__.py", line 789, in resolve
          dist = best[req.key] = env.best_match(
        File "C:\Users\xgx\Anaconda3\envs\faceswap\lib\site-packages\pkg_resources\__init__.py", line 1075, in best_match
          return self.obtain(req, installer)
        File "C:\Users\xgx\Anaconda3\envs\faceswap\lib\site-packages\pkg_resources\__init__.py", line 1087, in obtain
          return installer(requirement)
        File "C:\Users\xgx\Anaconda3\envs\faceswap\lib\site-packages\setuptools\dist.py", line 944, in fetch_build_egg
          return fetch_build_egg(self, req)
        File "C:\Users\xgx\Anaconda3\envs\faceswap\lib\site-packages\setuptools\installer.py", line 84, in fetch_build_egg
          raise DistutilsError(str(e)) from e
      distutils.errors.DistutilsError: Command '['C:\\Users\\xgx\\Anaconda3\\envs\\faceswap\\python.exe', '-m', 'pip', '--disable-pip-version-check', 'wheel', '--no-deps', '-w', 'C:\\Users\\xgx\\AppData\\Local\\Temp\\tmpi5giffsl', '--quiet', 'torch']' returned non-zero exit status 1.
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed

× Encountered error while generating package metadata.
╰─> See above for output.

note: This is an issue with the package mentioned above, not pip.
hint: See above for details.

解决方法是

pip install basicsr==1.4.2 --use-pep517

其中,PEP 517Python Enhancement Proposal 中的一个标准,其定义了 Python 打包和分发的接口

具体来说,PEP 517 定义了两个接口,分别为 建立构建环境执行构建

  • 建立构建环境:是用于创建一个 Python 环境,使得可以在其中进行构建和打包操作。该环境可以是虚拟环境,也可以是真实的 Python 环境
  • 执行构建:是用于执行构建操作,例如生成源代码分发包或二进制分发包等

PEP 517 的作用是让 Python 打包和分发的工具可以互相兼容,无论是 setuptoolsdistutilsflit 还是 poetry 等,都可以使用 PEP 517 提供的接口进行打包和分发操作

  1. 在执行 run.py 脚本时报错
OMP: Error #15: Initializing libiomp5md.dll, but found libiomp5md.dll already initialized.
OMP: Hint This means that multiple copies of the OpenMP runtime have been linked into the program. That is dangerous, since it can degrade performance or cause incorrect results. The best thing to do is to ensure that only a single OpenMP runtime is linked into the process, e.g. by avoiding static linking of the OpenMP runtime in any library. As an unsafe, unsupported, undocumented workaround you can set the environment variable KMP_DUPLICATE_LIB_OK=TRUE to allow the program to continue to execute, but that may cause crashes or silently produce incorrect results. For more information, please see http://www.intel.com/software/products/support/.

这个错误比较常见,解决方法一般是在文件中添加如下2行代码

import os
os.environ["KMP_DUPLICATE_LIB_OK"]="True"

代码的作用就是导入 os 库,然后设置环境标量 KMP_DUPLICATE_LIB_OK 的值为 True。不过不想改动源码的话,也可以直接在终端里设置环境变量,命令如下

# cmd
set KMP_DUPLICATE_LIB_OK="True"

# powershell
$Env:KMP_DUPLICATE_LIB_OK="True"

模型下载

运行 run.py 时下载的模型,童鞋们按需取用,放在 models 文件夹下

链接:https://pan.quark.cn/s/1ce0ad48ca4c

参考资料

喜欢 (1)

您必须 登录 才能发表评论!