这一部你可以选着两种方式
1.使用默认的workspace,你无需自己上传,仅用于熟悉操作。
2.通过Google Drive (谷歌云盘)上传自己的workspace到指定目录。
注意:谷歌网址现在都需要“科学上网”才能访问。
# 1.挂载谷歌云盘
# 点击链接授权,复制授权嘛,填入方框回车。
from google.colab import drive
drive.mount('/content/drive', force_remount=True)
# 2.创建DeepFaceLab目录,并且进入目录
%cd /content/drive/My\ Drive/
!mkdir DeepFaceLab
%cd /content/drive/My\ Drive/DeepFaceLab/
# 3.下载workspace数据
!git clone https://github.com/dream80/DFLWorkspace.git workspace
# 1.获取DFL源代码
!git clone https://github.com/iperov/DeepFaceLab.git
# 2.进入DeepFaceLab目录
%cd /content/drive/My Drive/DeepFaceLab/DeepFaceLab
# 3.安装Python依赖
!pip install -r requirements-colab.txt
!pip install --upgrade scikit-image
# 1.确保路径正确,进入DeepFaceLab
%cd /content/drive/My Drive/DeepFaceLab/DeepFaceLab
# 2.SRC视频转图片
!python main.py videoed extract-video --input-file ../workspace/data_src.mp4 --output-dir ../workspace/data_src/
# 3.SRC提取脸部图片
!python main.py extract --input-dir ../workspace/data_src --output-dir ../workspace/data_src/aligned --detector s3fd --debug-dir ../workspace/data_src/aligned_debug
# 4.SRC排序,可以通过谷歌云盘查看结果,删除不良图片
!python main.py sort --input-dir ../workspace/data_src/aligned --by hist
# 5.DST视频转图片
!python main.py videoed extract-video --input-file ../workspace/data_dst.mp4 --output-dir ../workspace/data_dst/
# 6.DST提取脸部图片
!python main.py extract --input-dir ../workspace/data_dst --output-dir ../workspace/data_dst/aligned --detector s3fd --debug-dir ../workspace/data_dst/aligned_debug
# 7.DST排序,可以通过谷歌云盘查看结果,删除不良图片
!python main.py sort --input-dir ../workspace/data_dst/aligned --by hist
# 确保路径正确,进入DeepFaceLab_Colab
%cd /content/drive/My Drive/DeepFaceLab/DeepFaceLab
下面是启动模型训练的脚本,不要全部点,只要点其中一个。默认使用第一个SAE
# 1.Running trainer. SAE
!python main.py train --training-data-src-dir ../workspace/data_src/aligned --training-data-dst-dir ../workspace/data_dst/aligned --model-dir ../workspace/model --model SAE --no-preview
# 2.Running trainer H128
!python main.py train --training-data-src-dir ../workspace/data_src/aligned --training-data-dst-dir ../workspace/data_dst/aligned --model-dir ../workspace/model --model H128 --no-preview
# 3.Running trainer. DF
!python main.py train --training-data-src-dir ../workspace/data_src/aligned --training-data-dst-dir ../workspace/data_dst/aligned --model-dir ../workspace/model --model DF --no-preview
# 4.Running trainer. LIAEF128
!python main.py train --training-data-src-dir ../workspace/data_src/aligned --training-data-dst-dir ../workspace/data_dst/aligned --model-dir ../workspace/model --model LIAEF128 --no-preview
默认使用SAE进行转换,如果需要其他模型,请修改命令中的参数。
比如将 --model SAE 修改为 --model H128
# 1.用src中的脸替换dst的脸
!python main.py convert --input-dir ../workspace/data_dst --output-dir ../workspace/data_dst/merged --aligned-dir ../workspace/data_dst/aligned --model-dir ../workspace/model --model SAE
# 2.把替换好的图片转换成视频
!python main.py videoed video-from-sequence --input-dir ../workspace/data_dst/merged --output-file ../workspace/result.mp4 --reference-file ../workspace/data_dst.mp4
当你第二次开始训练,或者掉线之后继续训练时并不需要执行上面所有的步骤。只需要下面简单的几个步骤。
#挂载谷歌云盘
#点击链接授权,复制授权码,填入框框,然后回车。
from google.colab import drive
drive.mount('/content/drive', force_remount=True)
# 进入DeepFaceLab_Colab目录
%cd /content/drive/My Drive/DeepFaceLab/DeepFaceLab
# 安装Python依赖
!pip install -r requirements-colab.txt
!pip install --upgrade scikit-image
# 开始训练SAE ,如果是其他模型,修改后面的参数即可。
!python main.py train --training-data-src-dir ../workspace/data_src/aligned --training-data-dst-dir ../workspace/data_dst/aligned --model-dir ../workspace/model --model SAE --no-preview