From 0245f38f95d5638b619d5735e23c32b6dc53b76d Mon Sep 17 00:00:00 2001 From: henryruhs Date: Sat, 3 Jun 2023 10:53:51 +0200 Subject: [PATCH 01/19] Introduce CI matrix --- .github/workflows/ci.yml | 8 +++++++- roop/utils.py | 4 +--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c543e10..5b0b00d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,6 +16,12 @@ jobs: - run: flake8 run.py core test: runs-on: ubuntu-latest + matrix: + include: + - name: CPU + args: -f=.github/examples/face.jpg -t=.github/examples/target.mp4 -o=.github/examples/output.mp4 --gpu-vendor=nvidia + - name: GPU + args: -f=.github/examples/face.jpg -t=.github/examples/target.mp4 -o=.github/examples/output.mp4 steps: - name: Checkout uses: actions/checkout@v2 @@ -28,6 +34,6 @@ jobs: - run: pip install -r requirements.txt - run: pip install gdown - run: gdown 13QpWFWJ37EB-nHrEOY64CEtQWY-tz7DZ - - run: ./run.py -f=.github/examples/face.jpg -t=.github/examples/target.mp4 -o=.github/examples/output.mp4 + - run: ./run.py {{ matrix.args }} - run: ffmpeg -i .github/examples/snapshot.mp4 -i .github/examples/output.mp4 -filter_complex "psnr" -f null - diff --git a/roop/utils.py b/roop/utils.py index d63807c..3ec6872 100644 --- a/roop/utils.py +++ b/roop/utils.py @@ -31,10 +31,8 @@ def detect_fps(input_path): def run_ffmpeg(args): - log_level = f'-loglevel {roop.globals.log_level}' - - os.system(f'ffmpeg {log_level} {args}') + run_command(f'ffmpeg {log_level} {args}') def set_fps(input_path, output_path, fps): From 92af5f1fea6157055dff63d6b12f7d14560d0915 Mon Sep 17 00:00:00 2001 From: henryruhs Date: Sat, 3 Jun 2023 10:57:42 +0200 Subject: [PATCH 02/19] Introduce CI matrix --- .github/workflows/ci.yml | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5b0b00d..cb2b75a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,12 +16,13 @@ jobs: - run: flake8 run.py core test: runs-on: ubuntu-latest - matrix: + strategy: + matrix: include: - - name: CPU - args: -f=.github/examples/face.jpg -t=.github/examples/target.mp4 -o=.github/examples/output.mp4 --gpu-vendor=nvidia - - name: GPU - args: -f=.github/examples/face.jpg -t=.github/examples/target.mp4 -o=.github/examples/output.mp4 + - name: CPU + args: -f=.github/examples/face.jpg -t=.github/examples/target.mp4 -o=.github/examples/output.mp4 --gpu-vendor=nvidia + - name: GPU + args: -f=.github/examples/face.jpg -t=.github/examples/target.mp4 -o=.github/examples/output.mp4 steps: - name: Checkout uses: actions/checkout@v2 From f2900c14d5abdc792d7c68ef015aa4cbce0515a1 Mon Sep 17 00:00:00 2001 From: henryruhs Date: Sat, 3 Jun 2023 11:06:49 +0200 Subject: [PATCH 03/19] Introduce CI matrix --- .github/workflows/ci.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cb2b75a..65f0afb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -32,6 +32,9 @@ jobs: uses: actions/setup-python@v2 with: python-version: 3.9 + - uses: awalsh128/cache-apt-pkgs-action@latest + with: + packages: tensorrt - run: pip install -r requirements.txt - run: pip install gdown - run: gdown 13QpWFWJ37EB-nHrEOY64CEtQWY-tz7DZ From a5a292b2992148e453f4186ce57caa8de208c48d Mon Sep 17 00:00:00 2001 From: henryruhs Date: Sat, 3 Jun 2023 11:11:01 +0200 Subject: [PATCH 04/19] Introduce CI matrix --- .github/workflows/ci.yml | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 65f0afb..88648de 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,9 +20,9 @@ jobs: matrix: include: - name: CPU - args: -f=.github/examples/face.jpg -t=.github/examples/target.mp4 -o=.github/examples/output.mp4 --gpu-vendor=nvidia - - name: GPU args: -f=.github/examples/face.jpg -t=.github/examples/target.mp4 -o=.github/examples/output.mp4 + - name: GPU + args: -f=.github/examples/face.jpg -t=.github/examples/target.mp4 -o=.github/examples/output.mp4 --gpu-vendor=nvidia steps: - name: Checkout uses: actions/checkout@v2 @@ -32,9 +32,7 @@ jobs: uses: actions/setup-python@v2 with: python-version: 3.9 - - uses: awalsh128/cache-apt-pkgs-action@latest - with: - packages: tensorrt + - run: sudo apt install tensorrt libnvinfer7 - run: pip install -r requirements.txt - run: pip install gdown - run: gdown 13QpWFWJ37EB-nHrEOY64CEtQWY-tz7DZ From 64b10e141549a8d4f41afe67ecc1d2175ecfb917 Mon Sep 17 00:00:00 2001 From: henryruhs Date: Sat, 3 Jun 2023 11:12:34 +0200 Subject: [PATCH 05/19] Introduce CI matrix --- .github/workflows/ci.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 88648de..97d0ad9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -32,6 +32,8 @@ jobs: uses: actions/setup-python@v2 with: python-version: 3.9 + - run: sudo add-apt-repository ppa:nvidia-latest + - run: sudo apt-get update - run: sudo apt install tensorrt libnvinfer7 - run: pip install -r requirements.txt - run: pip install gdown From f54303e7b954eb76d4f7c4f6fe44e61b97895c6c Mon Sep 17 00:00:00 2001 From: henryruhs Date: Sat, 3 Jun 2023 11:15:30 +0200 Subject: [PATCH 06/19] Introduce CI matrix --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 97d0ad9..7ff1df3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -32,7 +32,7 @@ jobs: uses: actions/setup-python@v2 with: python-version: 3.9 - - run: sudo add-apt-repository ppa:nvidia-latest + - run: sudo add-apt-repository ppa:graphics-drivers/ppa - run: sudo apt-get update - run: sudo apt install tensorrt libnvinfer7 - run: pip install -r requirements.txt From d91b43454784b3100924a332ab0e298cc0ad9438 Mon Sep 17 00:00:00 2001 From: henryruhs Date: Sat, 3 Jun 2023 11:19:29 +0200 Subject: [PATCH 07/19] Introduce CI matrix --- .github/workflows/ci.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7ff1df3..fd561a7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -32,9 +32,9 @@ jobs: uses: actions/setup-python@v2 with: python-version: 3.9 - - run: sudo add-apt-repository ppa:graphics-drivers/ppa - - run: sudo apt-get update - - run: sudo apt install tensorrt libnvinfer7 + - uses: Jimver/cuda-toolkit@v0.2.10 + with: + cuda: '11.8.0' - run: pip install -r requirements.txt - run: pip install gdown - run: gdown 13QpWFWJ37EB-nHrEOY64CEtQWY-tz7DZ From ff119214b89897dd8e75a25c38219f3c4b3bd880 Mon Sep 17 00:00:00 2001 From: henryruhs Date: Sat, 3 Jun 2023 11:30:39 +0200 Subject: [PATCH 08/19] Introduce CI matrix --- .github/workflows/ci.yml | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fd561a7..2351219 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -32,11 +32,7 @@ jobs: uses: actions/setup-python@v2 with: python-version: 3.9 - - uses: Jimver/cuda-toolkit@v0.2.10 - with: - cuda: '11.8.0' - - run: pip install -r requirements.txt - - run: pip install gdown + - run: pip install -r requirements.txt gdown - run: gdown 13QpWFWJ37EB-nHrEOY64CEtQWY-tz7DZ - run: ./run.py {{ matrix.args }} - run: ffmpeg -i .github/examples/snapshot.mp4 -i .github/examples/output.mp4 -filter_complex "psnr" -f null - From 71f7f3f68171c7407525d5ea6007c77e6919f744 Mon Sep 17 00:00:00 2001 From: henryruhs Date: Sat, 3 Jun 2023 11:36:29 +0200 Subject: [PATCH 09/19] Introduce CI matrix --- .github/workflows/ci.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2351219..651f5ef 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,9 +20,9 @@ jobs: matrix: include: - name: CPU - args: -f=.github/examples/face.jpg -t=.github/examples/target.mp4 -o=.github/examples/output.mp4 + run: ./run.py -f=.github/examples/face.jpg -t=.github/examples/target.mp4 -o=.github/examples/output.mp4 - name: GPU - args: -f=.github/examples/face.jpg -t=.github/examples/target.mp4 -o=.github/examples/output.mp4 --gpu-vendor=nvidia + run: ./run.py -f=.github/examples/face.jpg -t=.github/examples/target.mp4 -o=.github/examples/output.mp4 --gpu-vendor=nvidia steps: - name: Checkout uses: actions/checkout@v2 @@ -32,8 +32,8 @@ jobs: uses: actions/setup-python@v2 with: python-version: 3.9 - - run: pip install -r requirements.txt gdown + - run: pip install -r requirements.txt tensorrt gdown - run: gdown 13QpWFWJ37EB-nHrEOY64CEtQWY-tz7DZ - - run: ./run.py {{ matrix.args }} + - run: {{ matrix.run }} - run: ffmpeg -i .github/examples/snapshot.mp4 -i .github/examples/output.mp4 -filter_complex "psnr" -f null - From 808662c1cd8b8099911842256d73109a7dd125b6 Mon Sep 17 00:00:00 2001 From: henryruhs Date: Sat, 3 Jun 2023 11:40:45 +0200 Subject: [PATCH 10/19] Introduce CI matrix --- .github/workflows/ci.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 651f5ef..e71538b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -19,9 +19,9 @@ jobs: strategy: matrix: include: - - name: CPU + - run-name: CPU run: ./run.py -f=.github/examples/face.jpg -t=.github/examples/target.mp4 -o=.github/examples/output.mp4 - - name: GPU + - run-name: GPU run: ./run.py -f=.github/examples/face.jpg -t=.github/examples/target.mp4 -o=.github/examples/output.mp4 --gpu-vendor=nvidia steps: - name: Checkout @@ -34,6 +34,6 @@ jobs: python-version: 3.9 - run: pip install -r requirements.txt tensorrt gdown - run: gdown 13QpWFWJ37EB-nHrEOY64CEtQWY-tz7DZ - - run: {{ matrix.run }} + - run: ${{ matrix.run }} - run: ffmpeg -i .github/examples/snapshot.mp4 -i .github/examples/output.mp4 -filter_complex "psnr" -f null - From 4ff9be1268284058ae902ee9cde350d1893468f4 Mon Sep 17 00:00:00 2001 From: henryruhs Date: Sat, 3 Jun 2023 11:43:11 +0200 Subject: [PATCH 11/19] Introduce CI matrix --- .github/workflows/ci.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e71538b..9a9b6a5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -19,9 +19,9 @@ jobs: strategy: matrix: include: - - run-name: CPU + - name: CPU run: ./run.py -f=.github/examples/face.jpg -t=.github/examples/target.mp4 -o=.github/examples/output.mp4 - - run-name: GPU + - name: GPU run: ./run.py -f=.github/examples/face.jpg -t=.github/examples/target.mp4 -o=.github/examples/output.mp4 --gpu-vendor=nvidia steps: - name: Checkout @@ -32,7 +32,7 @@ jobs: uses: actions/setup-python@v2 with: python-version: 3.9 - - run: pip install -r requirements.txt tensorrt gdown + - run: pip install -r requirements.txt gdown - run: gdown 13QpWFWJ37EB-nHrEOY64CEtQWY-tz7DZ - run: ${{ matrix.run }} - run: ffmpeg -i .github/examples/snapshot.mp4 -i .github/examples/output.mp4 -filter_complex "psnr" -f null - From 9101f8d5f2145a58b10528d842d47b95bae4f715 Mon Sep 17 00:00:00 2001 From: henryruhs Date: Sat, 3 Jun 2023 11:52:03 +0200 Subject: [PATCH 12/19] Introduce CI matrix --- .github/workflows/ci.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9a9b6a5..ae9894b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,6 +16,8 @@ jobs: - run: flake8 run.py core test: runs-on: ubuntu-latest + container: + image: nvidia/cuda:11.8.0-devel-ubuntu22.04 strategy: matrix: include: From 98e19e1523eb948fcf0a59a518e9dd1cfa3678cc Mon Sep 17 00:00:00 2001 From: henryruhs Date: Sat, 3 Jun 2023 12:00:02 +0200 Subject: [PATCH 13/19] Introduce CI matrix --- .github/workflows/ci.yml | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ae9894b..4dedb60 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -28,12 +28,10 @@ jobs: steps: - name: Checkout uses: actions/checkout@v2 - - name: Set up ffmpeg - uses: FedericoCarboni/setup-ffmpeg@v2 - - name: Set up Python 3.9 - uses: actions/setup-python@v2 - with: - python-version: 3.9 + run: | + apt-get update + apt-get install -y ffmpeg python3-pip + pip install --upgrade pip - run: pip install -r requirements.txt gdown - run: gdown 13QpWFWJ37EB-nHrEOY64CEtQWY-tz7DZ - run: ${{ matrix.run }} From 10433d158179c5cb48e2db9546f7ffca6edeccc8 Mon Sep 17 00:00:00 2001 From: henryruhs Date: Sat, 3 Jun 2023 12:01:18 +0200 Subject: [PATCH 14/19] Introduce CI matrix --- .github/workflows/ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4dedb60..9231377 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -28,6 +28,7 @@ jobs: steps: - name: Checkout uses: actions/checkout@v2 + - name: Install dependencies run: | apt-get update apt-get install -y ffmpeg python3-pip From 23d8d78c7e35d5048c66cb02302ba7e0dfaae636 Mon Sep 17 00:00:00 2001 From: henryruhs Date: Sat, 3 Jun 2023 12:08:06 +0200 Subject: [PATCH 15/19] Introduce CI matrix --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9231377..e3d5c33 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -31,7 +31,7 @@ jobs: - name: Install dependencies run: | apt-get update - apt-get install -y ffmpeg python3-pip + apt-get install -y ffmpeg python3-tk python3-pip pip install --upgrade pip - run: pip install -r requirements.txt gdown - run: gdown 13QpWFWJ37EB-nHrEOY64CEtQWY-tz7DZ From b0a7b19b1bef328db6f83f63524c729360c196ac Mon Sep 17 00:00:00 2001 From: henryruhs Date: Sat, 3 Jun 2023 12:29:51 +0200 Subject: [PATCH 16/19] Skip matrix build for now (too complicated as of cuda runtimes) --- .github/workflows/ci.yml | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e3d5c33..ef5fa6c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,25 +16,17 @@ jobs: - run: flake8 run.py core test: runs-on: ubuntu-latest - container: - image: nvidia/cuda:11.8.0-devel-ubuntu22.04 - strategy: - matrix: - include: - - name: CPU - run: ./run.py -f=.github/examples/face.jpg -t=.github/examples/target.mp4 -o=.github/examples/output.mp4 - - name: GPU - run: ./run.py -f=.github/examples/face.jpg -t=.github/examples/target.mp4 -o=.github/examples/output.mp4 --gpu-vendor=nvidia steps: - name: Checkout uses: actions/checkout@v2 - - name: Install dependencies - run: | - apt-get update - apt-get install -y ffmpeg python3-tk python3-pip - pip install --upgrade pip + - name: Set up ffmpeg + uses: FedericoCarboni/setup-ffmpeg@v2 + - name: Set up Python 3.9 + uses: actions/setup-python@v2 + with: + python-version: 3.9 - run: pip install -r requirements.txt gdown - run: gdown 13QpWFWJ37EB-nHrEOY64CEtQWY-tz7DZ - - run: ${{ matrix.run }} + - run: ./run.py -f=.github/examples/face.jpg -t=.github/examples/target.mp4 -o=.github/examples/output.mp4 - run: ffmpeg -i .github/examples/snapshot.mp4 -i .github/examples/output.mp4 -filter_complex "psnr" -f null - From 1f0c3b4bb5288acc20c31b37ed070d691e94b3f8 Mon Sep 17 00:00:00 2001 From: henryruhs Date: Sat, 3 Jun 2023 13:37:15 +0200 Subject: [PATCH 17/19] Double GPU performance --- roop/core.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/roop/core.py b/roop/core.py index de5d7f6..50ad051 100644 --- a/roop/core.py +++ b/roop/core.py @@ -1,12 +1,14 @@ #!/usr/bin/env python3 +import os +# reducing num threads doubles performance of gpu-mode +os.environ['OMP_NUM_THREADS'] = '1' import platform import signal import sys import shutil import glob import argparse -import os import torch from pathlib import Path import tkinter as tk @@ -16,7 +18,6 @@ from tkinter.filedialog import asksaveasfilename import webbrowser import cv2 import threading -from threadpoolctl import threadpool_limits from PIL import Image, ImageTk import roop.globals From 21e29534200466f426c12f16b0deb18e92646de3 Mon Sep 17 00:00:00 2001 From: henryruhs Date: Sat, 3 Jun 2023 13:43:56 +0200 Subject: [PATCH 18/19] Double GPU performance --- roop/core.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/roop/core.py b/roop/core.py index 50ad051..cfb9813 100644 --- a/roop/core.py +++ b/roop/core.py @@ -1,11 +1,12 @@ #!/usr/bin/env python3 import os -# reducing num threads doubles performance of gpu-mode -os.environ['OMP_NUM_THREADS'] = '1' +import sys +# single thread doubles performance of gpu-mode - needs to be set before torch import +if any(arg.startswith('--gpu-vendor=') for arg in sys.argv): + os.environ['OMP_NUM_THREADS'] = '1' import platform import signal -import sys import shutil import glob import argparse From 777261c8f9429b00b58388c18760ddddc24e2e3f Mon Sep 17 00:00:00 2001 From: henryruhs Date: Sat, 3 Jun 2023 14:49:27 +0200 Subject: [PATCH 19/19] Add cuda utilization and cuda memory to progress bar --- roop/swapper.py | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/roop/swapper.py b/roop/swapper.py index 5b457b8..9af6ce4 100644 --- a/roop/swapper.py +++ b/roop/swapper.py @@ -1,10 +1,12 @@ import os from tqdm import tqdm +import torch +import onnxruntime import cv2 import insightface + import roop.globals from roop.analyser import get_face_single, get_face_many -import onnxruntime FACE_SWAPPER = None @@ -29,23 +31,17 @@ def swap_face_in_frame(source_face, target_face, frame): return frame -def process_faces(source_face, frame, progress): +def process_faces(source_face, target_frame, progress): if roop.globals.all_faces: - many_faces = get_face_many(frame) + many_faces = get_face_many(target_frame) if many_faces: for face in many_faces: - frame = swap_face_in_frame(source_face, face, frame) - progress.set_postfix(status='.', refresh=True) - else: - progress.set_postfix(status='S', refresh=True) + target_frame = swap_face_in_frame(source_face, face, target_frame) else: - face = get_face_single(frame) + face = get_face_single(target_frame) if face: - frame = swap_face_in_frame(source_face, face, frame) - progress.set_postfix(status='.', refresh=True) - else: - progress.set_postfix(status='S', refresh=True) - return frame + target_frame = swap_face_in_frame(source_face, face, target_frame) + return target_frame def process_video(source_img, frame_paths): @@ -54,12 +50,13 @@ def process_video(source_img, frame_paths): with tqdm(total=len(frame_paths), desc="Processing", unit="frame", dynamic_ncols=True, bar_format=progress_bar_format) as progress: for frame_path in frame_paths: + if roop.globals.gpu_vendor == 'nvidia': + progress.set_postfix(cuda_utilization="{:02d}%".format(torch.cuda.utilization()), cuda_memory="{:02d}GB".format(torch.cuda.memory_usage())) frame = cv2.imread(frame_path) try: result = process_faces(source_face, frame, progress) cv2.imwrite(frame_path, result) except Exception: - progress.set_postfix(status='E', refresh=True) pass progress.update(1)