fix dataflow in faceswapper, no read of files withing inner methods (#1148)

* fix dataflow in faceswapper, no read of files withing inner methods

* fix lint

* adjust code more

* adjust code more
This commit is contained in:
Henry Ruhs
2026-06-05 13:11:18 +02:00
committed by GitHub
parent a24fae9765
commit 3b751e6e17
2 changed files with 9 additions and 8 deletions
+1 -1
View File
@@ -4,9 +4,9 @@ from typing import List, Optional
import facefusion.choices
from facefusion.filesystem import create_directory, get_file_name, is_directory, is_file, move_file, remove_directory, remove_file, resolve_file_pattern
from facefusion.sanitizer import sanitize_job_id
from facefusion.jobs.job_helper import get_step_output_path
from facefusion.json import read_json, write_json
from facefusion.sanitizer import sanitize_job_id
from facefusion.time_helper import get_current_date_time
from facefusion.types import Args, Job, JobSet, JobStatus, JobStep, JobStepStatus
@@ -592,7 +592,7 @@ def post_process() -> None:
face_recognizer.clear_inference_pool()
def swap_face(source_face : Face, target_face : Face, temp_vision_frame : VisionFrame) -> VisionFrame:
def swap_face(source_face : Face, target_face : Face, source_vision_frame : VisionFrame, temp_vision_frame : VisionFrame) -> VisionFrame:
model_template = get_model_options().get('template')
model_size = get_model_options().get('size')
pixel_boost_size = unpack_resolution(state_manager.get_item('face_swapper_pixel_boost'))
@@ -612,7 +612,7 @@ def swap_face(source_face : Face, target_face : Face, temp_vision_frame : Vision
pixel_boost_vision_frames = implode_pixel_boost(crop_vision_frame, pixel_boost_total, model_size)
for pixel_boost_vision_frame in pixel_boost_vision_frames:
pixel_boost_vision_frame = prepare_crop_frame(pixel_boost_vision_frame)
pixel_boost_vision_frame = forward_swap_face(source_face, target_face, pixel_boost_vision_frame)
pixel_boost_vision_frame = forward_swap_face(source_face, target_face, source_vision_frame, pixel_boost_vision_frame)
pixel_boost_vision_frame = normalize_crop_frame(pixel_boost_vision_frame)
temp_vision_frames.append(pixel_boost_vision_frame)
crop_vision_frame = explode_pixel_boost(temp_vision_frames, pixel_boost_total, model_size, pixel_boost_size)
@@ -631,7 +631,7 @@ def swap_face(source_face : Face, target_face : Face, temp_vision_frame : Vision
return paste_vision_frame
def forward_swap_face(source_face : Face, target_face : Face, crop_vision_frame : VisionFrame) -> VisionFrame:
def forward_swap_face(source_face : Face, target_face : Face, source_vision_frame : VisionFrame, crop_vision_frame : VisionFrame) -> VisionFrame:
face_swapper = get_inference_pool().get('face_swapper')
model_type = get_model_options().get('type')
face_swapper_inputs = {}
@@ -639,7 +639,7 @@ def forward_swap_face(source_face : Face, target_face : Face, crop_vision_frame
for face_swapper_input in face_swapper.get_inputs():
if face_swapper_input.name == 'source':
if model_type in [ 'blendswap', 'uniface' ]:
face_swapper_inputs[face_swapper_input.name] = prepare_source_frame(source_face)
face_swapper_inputs[face_swapper_input.name] = prepare_source_frame(source_face, source_vision_frame)
else:
source_embedding = prepare_source_embedding(source_face)
source_embedding = balance_source_embedding(source_embedding, target_face.embedding)
@@ -665,9 +665,8 @@ def forward_convert_embedding(face_embedding : Embedding) -> Embedding:
return face_embedding
def prepare_source_frame(source_face : Face) -> VisionFrame:
def prepare_source_frame(source_face : Face, source_vision_frame : VisionFrame) -> VisionFrame:
model_type = get_model_options().get('type')
source_vision_frame = read_static_image(get_first(state_manager.get_item('source_paths')))
if model_type == 'blendswap':
source_vision_frame, _ = warp_face_by_face_landmark_5(source_vision_frame, source_face.landmark_set.get('5/68'), 'arcface_112_v2', (112, 112))
@@ -778,8 +777,10 @@ def process_frame(inputs : FaceSwapperInputs) -> ProcessorOutputs:
target_faces = select_faces(reference_vision_frame, source_vision_frames, target_vision_frame)
if source_face and target_faces:
source_vision_frame = get_first(source_vision_frames)
for target_face in target_faces:
target_face = scale_face(target_face, target_vision_frame, temp_vision_frame)
temp_vision_frame = swap_face(source_face, target_face, temp_vision_frame)
temp_vision_frame = swap_face(source_face, target_face, source_vision_frame, temp_vision_frame)
return temp_vision_frame, temp_vision_mask