roop: one click face swap. 只用一张人脸图片,就能完结视频换脸。

  • 项目地址: github.com/s0md3v/roop
  • Colab 部署: github.com/dream80/roo…

本文是本地部署的实践记录。

roop 视频换脸

环境基础

  • OS: Ubuntu 22.04.2 LTS
  • Kernel: 5.19.0
  • CPU: Intel(R) Core(TM) i7-10750H
  • GPU: NVIDIA GeForce RTX 2060
  • RAM: 16.0GiB

环境装置

Nvidia 驱动

# 检查可用驱动信息
ubuntu-drivers devices
# 装置 Nvidia 驱动(可选提示 recommended 的)
sudo apt install nvidia-driver-530
# 检查 Nvidia 驱动(检查不了,可重登录或重启)
nvidia-smi

Anaconda

  • Anaconda: www.anaconda.com/download
# 装置 Anaconda, 都 yes
bash Anaconda3-2023.07-1-Linux-x86_64.sh

创立虚拟环境,

conda create -n roop python=3.10 -y
conda activate roop

roop 装置

获取代码,

sudo apt install git -y
git clone --depth 1 https://github.com/s0md3v/roop.git

装置依靠,

cd roop
pip install -r requirements.txt
# 如遇过错,可依提示。例如:
#  pip install -r requirements.txt --use-pep517
# 如遇 dependency conflict,可修改依靠版本。例如:
#  numpy>=1.23.5
# 若配置镜像
pip config set global.index-url http://mirrors.aliyun.com/pypi/simple
pip config set install.trusted-host mirrors.aliyun.com
cat ~/.config/pip/pip.conf

roop 体会

运转,

cd roop
python run.py --execution-provider cuda
# 如果报错相似 ONNXRuntimeError CUBLAS_STATUS_ALLOC_FAILED,需削减执行线程
#  https://github.com/s0md3v/roop/issues/413
python run.py --execution-provider cuda --execution-threads 1

可见窗口,

roop 视频换脸

挑选一张人脸图片、一个视频,就能完结转换了。

输出信息,

$ python run.py --execution-provider cuda --execution-threads 1
Applied providers: ['CUDAExecutionProvider', 'CPUExecutionProvider'], with options: {'CPUExecutionProvider': {}, 'CUDAExecutionProvider': {'device_id': '0', 'gpu_mem_limit': '18446744073709551615', 'gpu_external_alloc': '0', 'gpu_external_free': '0', 'gpu_external_empty_cache': '0', 'cudnn_conv_algo_search': 'EXHAUSTIVE', 'cudnn_conv1d_pad_to_nc1d': '0', 'arena_extend_strategy': 'kNextPowerOfTwo', 'do_copy_in_default_stream': '1', 'enable_cuda_graph': '0', 'cudnn_conv_use_max_workspace': '1', 'tunable_op_enable': '0', 'enable_skip_layer_norm_strict_mode': '0', 'tunable_op_tuning_enable': '0'}}
# ...
find model: /home/john/.insightface/models/buffalo_l/w600k_r50.onnx recognition ['None', 3, 112, 112] 127.5 127.5
set det-size: (640, 640)
inswapper-shape: [1, 3, 128, 128]
100%|█████████████████████████████████████████████████████████████████████████████████████████| 336/336 [00:01<00:00, 185.49it/s]
[ROOP.CORE] Creating temp resources...
[ROOP.CORE] Extracting frames with 30.0 FPS...
[ROOP.FACE-SWAPPER] Progressing...
Processing: 100%|█| 336/336 [01:40<00:00,  3.33frame/s, memory_usage=04.94GB, execution_providers=['CUDAExecutionProvider'], exec
[ROOP.CORE] Creating video with 30.0 FPS...
[ROOP.CORE] Restoring audio...
[ROOP.CORE] Processing to video succeed!

结语

roop 视频换脸,个人感觉作用还不错。

GoCoding 个人实践的经验分享,欢迎重视!