From 9bfeb95f56c89357180c3f79c90bbf592ea2d970 Mon Sep 17 00:00:00 2001 From: henryruhs Date: Tue, 15 Aug 2023 19:11:01 +0200 Subject: [PATCH] Different way to handle THIS --- roop/core.py | 6 +++--- roop/predictor.py | 2 +- roop/uis/__components__/face_selector.py | 2 +- roop/uis/__components__/output.py | 7 +++---- roop/uis/__components__/preview.py | 3 +-- 5 files changed, 9 insertions(+), 11 deletions(-) diff --git a/roop/core.py b/roop/core.py index fbe638572..2fcbcbb64 100755 --- a/roop/core.py +++ b/roop/core.py @@ -42,7 +42,7 @@ def parse_args() -> None: program.add_argument('--face-analyser-age', help='age used for the face analyser', dest='face_analyser_age', choices=['child', 'teen', 'adult', 'senior']) program.add_argument('--face-analyser-gender', help='gender used for the face analyser', dest='face_analyser_gender', choices=['male', 'female']) program.add_argument('--reference-face-position', help='position of the reference face', dest='reference_face_position', type=int, default=0) - program.add_argument('--reference-face-distance', help='distance between reference face and target face', dest='reference_face_distance', type=float, default=0.85) + program.add_argument('--reference-face-distance', help='distance between reference face and target face', dest='reference_face_distance', type=float, default=1.5) program.add_argument('--reference-frame-number', help='number of the reference frame', dest='reference_frame_number', type=int, default=0) program.add_argument('--trim-frame-start', help='start frame use for extraction', dest='trim_frame_start', type=int) program.add_argument('--trim-frame-end', help='end frame use for extraction', dest='trim_frame_end', type=int) @@ -151,7 +151,7 @@ def start() -> None: # process image to image if has_image_extension(roop.globals.target_path): if predict_image(roop.globals.target_path): - destroy() + return shutil.copy2(roop.globals.target_path, roop.globals.output_path) # process frame for frame_processor_module in get_frame_processors_modules(roop.globals.frame_processors): @@ -166,7 +166,7 @@ def start() -> None: return # process image to videos if predict_video(roop.globals.target_path): - destroy() + return update_status('Creating temporary resources...') create_temp(roop.globals.target_path) # extract frames diff --git a/roop/predictor.py b/roop/predictor.py index b59fee93e..f3f2996a4 100644 --- a/roop/predictor.py +++ b/roop/predictor.py @@ -8,7 +8,7 @@ PREDICTOR = None THREAD_LOCK = threading.Lock() -MAX_PROBABILITY = 0.85 +MAX_PROBABILITY = 0.75 def get_predictor() -> Model: diff --git a/roop/uis/__components__/face_selector.py b/roop/uis/__components__/face_selector.py index e701b3d94..e072d85fe 100644 --- a/roop/uis/__components__/face_selector.py +++ b/roop/uis/__components__/face_selector.py @@ -47,7 +47,7 @@ def render() -> None: REFERENCE_FACE_DISTANCE_SLIDER = gradio.Slider( label='REFERENCE FACE DISTANCE', value=roop.globals.reference_face_distance, - maximum=2, + maximum=3, step=0.05, visible='reference' in roop.globals.face_recognition ) diff --git a/roop/uis/__components__/output.py b/roop/uis/__components__/output.py index 33c6bde93..a0bf66a49 100644 --- a/roop/uis/__components__/output.py +++ b/roop/uis/__components__/output.py @@ -4,8 +4,7 @@ import roop.globals from roop.core import start from roop.uis.typing import Update -from roop.utilities import has_image_extension, has_video_extension, normalize_output_path - +from roop.utilities import is_image, is_video, normalize_output_path START_BUTTON: Optional[gradio.Button] = None CLEAR_BUTTON: Optional[gradio.Button] = None @@ -42,9 +41,9 @@ def update() -> Tuple[Update, Update]: roop.globals.output_path = normalize_output_path(roop.globals.source_path, roop.globals.target_path, '..') if roop.globals.output_path: start() - if has_image_extension(roop.globals.output_path): + if is_image(roop.globals.output_path): return gradio.update(value=roop.globals.output_path, visible=True), gradio.update(value=None, visible=False) - if has_video_extension(roop.globals.output_path): + if is_video(roop.globals.output_path): return gradio.update(value=None, visible=False), gradio.update(value=roop.globals.output_path, visible=True) return gradio.update(value=None, visible=False), gradio.update(value=None, visible=False) diff --git a/roop/uis/__components__/preview.py b/roop/uis/__components__/preview.py index f3b10b8a8..2db4baf09 100644 --- a/roop/uis/__components__/preview.py +++ b/roop/uis/__components__/preview.py @@ -5,7 +5,6 @@ import roop.globals from roop.capturer import get_video_frame, get_video_frame_total -from roop.core import destroy from roop.face_analyser import get_one_face from roop.face_reference import get_face_reference, set_face_reference from roop.predictor import predict_frame @@ -91,7 +90,7 @@ def update(frame_number: int = 0) -> Tuple[Update, Update]: def extract_preview_frame(temp_frame: Frame) -> Frame: if predict_frame(temp_frame): - destroy() + return cv2.GaussianBlur(temp_frame, (99, 99), 0) source_face = get_one_face(cv2.imread(roop.globals.source_path)) if roop.globals.source_path else None temp_frame = reduce_preview_frame(temp_frame) if 'reference' in roop.globals.face_recognition and not get_face_reference():