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) <noreply@anthropic.com>
This commit is contained in:
Max Buckley
2026-04-09 14:34:53 +02:00
parent bcdd0ce2dd
commit 646b0f816f
2 changed files with 2 additions and 3 deletions
+1 -2
View File
@@ -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:
+1 -1
View File
@@ -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)