Merge remote-tracking branch 'origin/main'

# Conflicts:
#	core/processor.py
This commit is contained in:
chris 2023-05-31 16:39:04 -04:00
commit 6a410e8f84
4 changed files with 20 additions and 27 deletions

View File

@ -1,8 +1,9 @@
import os import os
from tqdm import tqdm
import cv2 import cv2
import insightface import insightface
import core.globals import core.globals
from core.config import get_face, get_all_faces from core.analyser import get_face
FACE_SWAPPER = None FACE_SWAPPER = None
@ -17,33 +18,21 @@ def get_face_swapper():
def process_video(source_img, frame_paths): def process_video(source_img, frame_paths):
source_face = get_face(cv2.imread(source_img)) source_face = get_face(cv2.imread(source_img))
for frame_path in frame_paths: with tqdm(total=len(frame_paths), desc="Processing", unit="frame", dynamic_ncols=True, bar_format='{l_bar}{bar}| {n_fmt}/{total_fmt} [{elapsed}<{remaining}, {rate_fmt}{postfix}]') as progress:
frame = cv2.imread(frame_path) for frame_path in frame_paths:
frame = cv2.imread(frame_path)
swapper = get_face_swapper() try:
try:
if core.globals.all_faces:
all_faces = get_all_faces(frame)
result = frame
for singleFace in all_faces:
if singleFace:
result = swapper.get(result, singleFace, source_face, paste_back=True)
print('.', end='', flush=True)
else:
print('S', end='', flush=True)
cv2.imwrite(frame_path, result)
else:
face = get_face(frame) face = get_face(frame)
if face: if face:
result = swapper.get(frame, face, source_face, paste_back=True) result = get_face_swapper().get(frame, face, source_face, paste_back=True)
cv2.imwrite(frame_path, result) cv2.imwrite(frame_path, result)
print('.', end='', flush=True) progress.set_postfix(status='.', refresh=True)
else: else:
print('S', end='', flush=True) progress.set_postfix(status='S', refresh=True)
except Exception:
except Exception as e: progress.set_postfix(status='E', refresh=True)
print('E', end='', flush=True) pass
pass progress.update(1)
def process_img(source_img, target_path, output_file): def process_img(source_img, target_path, output_file):

View File

@ -1,4 +1,4 @@
numpy==1.24.3 numpy==1.23.5
opencv-python==4.7.0.72 opencv-python==4.7.0.72
onnx==1.14.0 onnx==1.14.0
insightface==0.7.3 insightface==0.7.3
@ -7,5 +7,7 @@ tk==0.1.0
pillow==9.5.0 pillow==9.5.0
torch==2.0.1 torch==2.0.1
onnxruntime-gpu==1.15.0 onnxruntime-gpu==1.15.0
tensorflow==2.12.0
opennsfw2==0.10.2 opennsfw2==0.10.2
protobuf==3.20.2 protobuf==3.20.2
tqdm==4.65.0

6
run.py
View File

@ -1,6 +1,7 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import platform import platform
import signal
import sys import sys
import time import time
import shutil import shutil
@ -20,9 +21,9 @@ import cv2
import threading import threading
from PIL import Image, ImageTk from PIL import Image, ImageTk
import core.globals import core.globals
from core.processor import process_video, process_img from core.swapper import process_video, process_img
from core.utils import is_img, detect_fps, set_fps, create_video, add_audio, extract_frames, rreplace from core.utils import is_img, detect_fps, set_fps, create_video, add_audio, extract_frames, rreplace
from core.config import get_face from core.analyser import get_face
if 'ROCMExecutionProvider' in core.globals.providers: if 'ROCMExecutionProvider' in core.globals.providers:
del torch del torch
@ -30,6 +31,7 @@ if 'ROCMExecutionProvider' in core.globals.providers:
pool = None pool = None
args = {} args = {}
signal.signal(signal.SIGINT, lambda signal_number, frame: quit())
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument('-f', '--face', help='use this face', dest='source_img') parser.add_argument('-f', '--face', help='use this face', dest='source_img')
parser.add_argument('-t', '--target', help='replace this face', dest='target_path') parser.add_argument('-t', '--target', help='replace this face', dest='target_path')