ディープフェイク【roop編】:1枚の画像から動画の顔スワップ

roop本家
インストール元:https://github.com/s0md3v/roop
インストール方法:https://github.com/s0md3v/roop/wiki/1.-Installation
事前準備
事前セットアップ(Windows):https://github.com/s0md3v/roop/wiki/1.3-Setup-Windows
Python
winget install -e --id Python.Python.3.10
PIP
python -m ensurepip
GIT
winget install -e --id Git.Git
FFmpeg
winget install -e --id Gyan.FFmpeg
Reboot your system in order for FFmpeg to function properly.
shutdown /r
Toolset
Microsoft Visual C++ 2015 Redistributable
winget install -e --id Microsoft.VCRedist.2015+.x64
Microsoft Visual Studio 2022 build tools
During installation, ensure to select the Desktop Development with C++ package.
winget install -e --id Microsoft.VisualStudio.2022.BuildTools --override "--wait --add Microsoft.VisualStudio.Workload.NativeDesktop --includeRecommended"
roop構築
Cドライブに新規「DeepFake」フォルダを作成

コマンドプロンプトで、C:\DeepFake に移動(※管理者で起動)

コマンドを実行
git clone https://github.com/s0md3v/roop

C:\DeepFake に「roop」フォルダが生成されています。

コマンドプロンプトで、C:\DeepFake\roop に移動
コマンドを実行
pip install -r requirements.txt

C:\DeepFake\roopフォルダ内にデータが生成されています。

アクセラレーション(加速装置)
CUDA (Nvidia):https://github.com/s0md3v/roop/wiki/2.-Acceleration
- Install CUDA Toolkit 11.8 and cuDNN for Cuda 11.x
- Install dependencies:
pip uninstall onnxruntime onnxruntime-gpu
pip install onnxruntime-gpu==1.15.1
- Usage in case the provider is available:
python run.py --execution-provider cuda
run.py にて、roopが起動します

オプション:run.py
python run.py [options]
-h, --help
show this help message and exit
-s SOURCE_PATH, --source SOURCE_PATH
select an source image
-t TARGET_PATH, --target TARGET_PATH
select an target image or video
-o OUTPUT_PATH, --output OUTPUT_PATH
select output file or directory
--frame-processor FRAME_PROCESSOR [FRAME_PROCESSOR ...]
frame processors (choices: face_swapper, face_enhancer, ...)
--keep-fps
keep target fps
--keep-frames
keep temporary frames
--skip-audio
skip target audio
--many-faces
process every face
--reference-face-position REFERENCE_FACE_POSITION
position of the reference face
--reference-frame-number REFERENCE_FRAME_NUMBER
number of the reference frame
--similar-face-distance SIMILAR_FACE_DISTANCE
face distance used for recognition
--temp-frame-format {jpg,png}
image format used for frame extraction
--temp-frame-quality [0-100]
image quality used for frame extraction
--output-video-encoder {libx264,libx265,libvpx-vp9,h264_nvenc,hevc_nvenc}
encoder used for the output video
--output-video-quality [0-100]
quality used for the output video
--max-memory MAX_MEMORY
maximum amount of RAM in GB
--execution-provider {cpu} [{cpu} ...]
available execution provider (choices: cpu, ...)
--execution-threads EXECUTION_THREADS
number of execution threads
-v, --version
show program's version number and exit
roop実行
Select face:対象となる画像

Select target:対象とする動画
「Start」ボタンで生成を開始します。

実行結果
起動バッチファイル
roop_setup.bat を新規作成
python run.py --execution-provider cuda --max-memory 12 --keep-fps --keep-frames --many-faces
pause
C:\DeepFake\roopフォルダ内にroop_setup.batを保存

roop_setup.bat をダブルクリックすることにより、roopが起動できます!
おまけ:すごく大切なこと
以下のように途中で止まってしまう場合

C:\DeepFake\roop\roop内フォルダの、core.py を編集

core.py を編集
編集内容
sys.exit() ⇒ #sys.exit()

これで、途中で止まってしまう現象がスキップできました!