From 646b0f816fa33f4a2ea9d997dc78e6821db9695d Mon Sep 17 00:00:00 2001 From: Max Buckley Date: Thu, 9 Apr 2026 14:34:53 +0200 Subject: [PATCH] Move hot-path imports to module scope Address Sourcery review feedback: move face_align and get_one_face imports from inside per-frame functions to module-level to avoid repeated attribute lookup overhead in the processing loop. Co-Authored-By: Claude Opus 4.6 (1M context) --- modules/processors/frame/core.py | 3 +-- modules/processors/frame/face_swapper.py | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/modules/processors/frame/core.py b/modules/processors/frame/core.py index 195a3ea..628a2a6 100644 --- a/modules/processors/frame/core.py +++ b/modules/processors/frame/core.py @@ -11,6 +11,7 @@ from tqdm import tqdm import modules import modules.globals +from modules.face_analyser import get_one_face FRAME_PROCESSORS_MODULES: List[ModuleType] = [] FRAME_PROCESSORS_INTERFACE = [ @@ -321,8 +322,6 @@ def _run_pipe_pipeline( bar_fmt = ('{l_bar}{bar}| {n_fmt}/{total_fmt} ' '[{elapsed}<{remaining}, {rate_fmt}{postfix}]') - from modules.face_analyser import get_one_face - try: with tqdm(total=total_frames, desc='Processing', unit='frame', dynamic_ncols=True, bar_format=bar_fmt) as progress: diff --git a/modules/processors/frame/face_swapper.py b/modules/processors/frame/face_swapper.py index f51a2a6..e1f141a 100644 --- a/modules/processors/frame/face_swapper.py +++ b/modules/processors/frame/face_swapper.py @@ -1,6 +1,7 @@ from typing import Any, List, Optional import cv2 import insightface +from insightface.utils import face_align import threading import numpy as np import platform @@ -241,7 +242,6 @@ def swap_face(source_face: Face, target_face: Face, temp_frame: Frame) -> Frame: return original_frame # Get the aligned input crop for the mask (same as insightface does internally) - from insightface.utils import face_align aimg, _ = face_align.norm_crop2(temp_frame, target_face.kps, face_swapper.input_size[0]) swapped_frame = _fast_paste_back(temp_frame, bgr_fake, aimg, M)