Remove everything source face related from enhancer (#510)

* Remove everything source face related from enhancer

* Disable upscale for enhancer to double fps
This commit is contained in:
Henry Ruhs 2023-06-16 23:17:41 +02:00 committed by GitHub
parent 4a04d2a66a
commit 4fa8d03335
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 26 deletions

View File

@ -6,7 +6,7 @@ import gfpgan
import roop.globals
import roop.processors.frame.core
from roop.core import update_status
from roop.face_analyser import get_one_face, get_many_faces
from roop.face_analyser import get_one_face
from roop.utilities import conditional_download, resolve_relative_path, is_image, is_video
FACE_ENHANCER = None
@ -35,53 +35,40 @@ def get_face_enhancer() -> None:
if FACE_ENHANCER is None:
model_path = resolve_relative_path('../models/GFPGANv1.3.pth')
# todo: set models path https://github.com/TencentARC/GFPGAN/issues/399
FACE_ENHANCER = gfpgan.GFPGANer(
model_path=model_path,
channel_multiplier=2
)
FACE_ENHANCER = gfpgan.GFPGANer(model_path=model_path, upscale=1)
return FACE_ENHANCER
def enhance_face(source_face: Any, target_face: Any, temp_frame: Any) -> Any:
THREAD_SEMAPHORE.acquire()
if target_face:
def enhance_face(temp_frame: Any) -> Any:
with THREAD_SEMAPHORE:
_, _, temp_frame = get_face_enhancer().enhance(
temp_frame,
paste_back=True
)
THREAD_SEMAPHORE.release()
return temp_frame
def process_frame(source_face: Any, temp_frame: Any) -> Any:
if roop.globals.many_faces:
many_faces = get_many_faces(temp_frame)
if many_faces:
for target_face in many_faces:
temp_frame = enhance_face(source_face, target_face, temp_frame)
else:
target_face = get_one_face(temp_frame)
if target_face:
temp_frame = enhance_face(source_face, target_face, temp_frame)
target_face = get_one_face(temp_frame)
if target_face:
temp_frame = enhance_face(temp_frame)
return temp_frame
def process_frames(source_path: str, temp_frame_paths: List[str], progress=None) -> None:
source_face = get_one_face(cv2.imread(source_path))
for temp_frame_path in temp_frame_paths:
temp_frame = cv2.imread(temp_frame_path)
result = process_frame(source_face, temp_frame)
result = process_frame(None, temp_frame)
cv2.imwrite(temp_frame_path, result)
if progress:
progress.update(1)
def process_image(source_path: str, target_path: str, output_path: str) -> None:
source_face = get_one_face(cv2.imread(source_path))
target_frame = cv2.imread(target_path)
result = process_frame(source_face, target_frame)
result = process_frame(None, target_frame)
cv2.imwrite(output_path, result)
def process_video(source_path: str, temp_frame_paths: List[str]) -> None:
roop.processors.frame.core.process_video(source_path, temp_frame_paths, process_frames)
roop.processors.frame.core.process_video(None, temp_frame_paths, process_frames)

View File

@ -44,9 +44,7 @@ def get_face_swapper() -> None:
def swap_face(source_face: Any, target_face: Any, temp_frame: Any) -> Any:
if target_face:
return get_face_swapper().get(temp_frame, target_face, source_face, paste_back=True)
return temp_frame
return get_face_swapper().get(temp_frame, target_face, source_face, paste_back=True)
def process_frame(source_face: Any, temp_frame: Any) -> Any: