From 3b58d129e1467ee5fc5420fbd2fdd65a6e5a0e77 Mon Sep 17 00:00:00 2001 From: henryruhs Date: Wed, 27 Mar 2024 12:01:45 +0100 Subject: [PATCH] Minor cleanup --- .../processors/frame/modules/face_swapper.py | 22 +++++++++---------- facefusion/uis/components/benchmark.py | 6 ++--- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/facefusion/processors/frame/modules/face_swapper.py b/facefusion/processors/frame/modules/face_swapper.py index c7da87af..a988fbb3 100755 --- a/facefusion/processors/frame/modules/face_swapper.py +++ b/facefusion/processors/frame/modules/face_swapper.py @@ -27,7 +27,7 @@ from facefusion.processors.frame import globals as frame_processors_globals from facefusion.processors.frame import choices as frame_processors_choices FRAME_PROCESSOR = None -MODEL_MATRIX = None +MODEL_INITIALIZER = None THREAD_LOCK : threading.Lock = threading.Lock() NAME = __name__.upper() MODELS : ModelSet =\ @@ -114,23 +114,23 @@ def clear_frame_processor() -> None: FRAME_PROCESSOR = None -def get_model_matrix() -> Any: - global MODEL_MATRIX +def get_model_initializer() -> Any: + global MODEL_INITIALIZER with THREAD_LOCK: while process_manager.is_checking(): sleep(0.5) - if MODEL_MATRIX is None: + if MODEL_INITIALIZER is None: model_path = get_options('model').get('path') model = onnx.load(model_path) - MODEL_MATRIX = numpy_helper.to_array(model.graph.initializer[-1]) - return MODEL_MATRIX + MODEL_INITIALIZER = numpy_helper.to_array(model.graph.initializer[-1]) + return MODEL_INITIALIZER -def clear_model_matrix() -> None: - global MODEL_MATRIX +def clear_model_initializer() -> None: + global MODEL_INITIALIZER - MODEL_MATRIX = None + MODEL_INITIALIZER = None def get_options(key : Literal['model']) -> Any: @@ -217,7 +217,7 @@ def post_process() -> None: read_static_image.cache_clear() if facefusion.globals.video_memory_strategy == 'strict' or facefusion.globals.video_memory_strategy == 'moderate': clear_frame_processor() - clear_model_matrix() + clear_model_initializer() if facefusion.globals.video_memory_strategy == 'strict': clear_face_analyser() clear_content_analyser() @@ -281,7 +281,7 @@ def prepare_source_frame(source_face : Face) -> VisionFrame: def prepare_source_embedding(source_face : Face) -> Embedding: model_type = get_options('model').get('type') if model_type == 'inswapper': - model_matrix = get_model_matrix() + model_matrix = get_model_initializer() source_embedding = source_face.embedding.reshape((1, -1)) source_embedding = numpy.dot(source_embedding, model_matrix) / numpy.linalg.norm(source_embedding) else: diff --git a/facefusion/uis/components/benchmark.py b/facefusion/uis/components/benchmark.py index 2160d09d..1158a6a9 100644 --- a/facefusion/uis/components/benchmark.py +++ b/facefusion/uis/components/benchmark.py @@ -87,7 +87,8 @@ def start(benchmark_runs : List[str], benchmark_cycles : int) -> Generator[List[ if target_paths: pre_process() for target_path in target_paths: - benchmark_results.append(benchmark(target_path, benchmark_cycles)) + facefusion.globals.target_path = target_path + benchmark_results.append(benchmark(benchmark_cycles)) yield benchmark_results post_process() @@ -103,10 +104,9 @@ def post_process() -> None: clear_static_faces() -def benchmark(target_path : str, benchmark_cycles : int) -> List[Any]: +def benchmark(benchmark_cycles : int) -> List[Any]: process_times = [] total_fps = 0.0 - facefusion.globals.target_path = target_path video_frame_total = count_video_frame_total(facefusion.globals.target_path) output_video_resolution = detect_video_resolution(facefusion.globals.target_path) facefusion.globals.output_video_resolution = pack_resolution(output_video_resolution)