视频换脸AISWAP技术示例

        视频换脸现在很火,主要得益于现在的显卡的强大以及深度学习的突飞猛进。视频换脸,简单来说就是使用一张静态的人脸图片替换掉视频中原来的脸。下面是我的实操,四个步骤来实现:

一、安装Anaconda

Anaconda镜像文件:https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/
选择对应的版本进行下载,安装完之后conda info 可以查看32位还是64位等信息
打开Anaconda Prompt进入命令行:

conda create -n aiface python=3.9

使用Anaconda可以方便管理多个版本的 Python,安装完之后,输入命令 activate aiface,把名为aiface的环境进行激活即可,查看有哪些运行环境路径:conda env list

激活环境之后,相当于就是一个独立的系统下面进行配置!

二、安装CUDA和cuDNN

CUDA https://developer.nvidia.com/cuda-downloads
我这里下载的是:https://developer.download.nvidia.cn/compute/cuda/11.3.1/local_installers/cuda_11.3.1_465.89_win10.exe
安装之后验证是否成功:
nvcc -V

老版本:https://developer.nvidia.com/cuda-10.2-download-archive
https://developer.download.nvidia.com/compute/cuda/10.2/Prod/local_installers/cuda_10.2.89_441.22_win10.exe


cuDNN https://developer.nvidia.com/rdp/cudnn-download
没有账号需要先注册账号,我这里下载的是:cuDNN Library for Windows (x86)
下载的压缩包解压到对应的目录里面
..\cuda\bin ==> C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.3\bin
..\cuda\include ==> C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.3\include
..\cuda\lib\x64 ==> C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.3\lib\x64

添加环境变量
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.3\lib\x64

 

三、安装图片更换的源码

使用git命令来安装源码,如果没有安装,可以下载安装:https://git-scm.com/download
进入站点下载或者git命令安装:https://github.com/AliaksandrSiarohin/first-order-model
git命令安装:git clone https://github.com/AliaksandrSiarohin/first-order-model.git aiface


C:\Users\Tony\aiface里面有一个requirements.txt文档,一些包的列表
注释#torch==1.0.0和#torchvision==0.2.1,这两个单独安装
(aiface) C:\Users\Tony>cd C:\Users\Tony\aiface
(aiface) C:\Users\Tony\aiface>pip install -r requirements.txt

 

四、安装torch + torchvision

https://pytorch.org/get-started/locally/

选择自己的配置环境,将生成一条命令,如:
pip install torch==1.9.0+cu102 torchvision==0.10.0+cu102 torchaudio===0.9.0 -f https://download.pytorch.org/whl/torch_stable.html
建议在命令后面追加清华的镜像 -i https://pypi.tuna.tsinghua.edu.cn/simple

也可以下载下来进行离线安装
https://download.pytorch.org/whl/torch_stable.html
torch-1.9.0+cpu-cp38-cp38-win_amd64.whl
pip install torch-1.9.0+cpu-cp38-cp38-win_amd64.whl

安装之后验证是否成功:

import torch
print(torch.__version__)

import torchvision
print(torchvision.__version__)

最后进行骚操作:在克隆下来的目录下面,新建test目录,在test下面新建m、videos、imgs三个目录

checkpoint:放训练模型,vox–adv–cpk.pth.tar
driving:放自己的视频
source:放图片

python demo.py  --config config/vox-adv-256.yaml --driving_video test/videos/1.mp4 --source_image test/imgs/1.png --checkpoint test/m/vox-adv-cpk.pth.tar --relative --adapt_scale


conda config --remove-key channels
把defaults也删除
conda config --remove channels defaults

频道也可以在用户目录下面的.condarc文件里面修改
channels:
  - https://mirrors.ustc.edu.cn/anaconda/pkgs/main/
  - https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge/
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
  - defaults
show_channel_urls: true

查看镜像列表:

conda config --show-sources
conda config --remove-key channels
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/win-64/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/win-64/
conda config --set show_channel_urls yes
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/win-64/

在安装torch的过程中,会遇到很多问题,有版本问题,平台问题,缺少第三方库等等的问题,看错误来解决!一般第一次操作,会经过很多次的处理错误才能搞定
检测GPU是否可用

import torch
torch.cuda.is_available()


因为上面离线下载测试的是没有GPU的tourch,使用到的是CPU的,这个需要注意!返回True就是使用了torch的GPU版本
最后那个训练模型的包vox-adv-cpk.pth.tar,下载地址:https://download.csdn.net/download/weixin_41896770/19779651

  • 0
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

寅恪光潜

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值