Minor cleanup

This commit is contained in:
henryruhs
2024-03-27 12:01:45 +01:00
parent 5a8a95f9f1
commit 3b58d129e1
2 changed files with 14 additions and 14 deletions
@@ -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:
+3 -3
View File
@@ -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)