From 65da3be2a4fc081e4138698d5cc3fee48d838d43 Mon Sep 17 00:00:00 2001 From: Adrian Zimbran Date: Mon, 10 Mar 2025 23:31:56 +0200 Subject: [PATCH 1/2] Fix face swapping crash due to None face embeddings - Add explicit checks for face detection results (source and target faces). - Handle cases when face embeddings are not available, preventing AttributeError. - Provide meaningful log messages for easier debugging in future scenarios. --- modules/processors/frame/face_swapper.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/modules/processors/frame/face_swapper.py b/modules/processors/frame/face_swapper.py index e0d1c50..5def2ad 100644 --- a/modules/processors/frame/face_swapper.py +++ b/modules/processors/frame/face_swapper.py @@ -105,14 +105,20 @@ def process_frame(source_face: Face, temp_frame: Frame) -> Frame: many_faces = get_many_faces(temp_frame) if many_faces: for target_face in many_faces: - temp_frame = swap_face(source_face, target_face, temp_frame) + if source_face and target_face: + temp_frame = swap_face(source_face, target_face, temp_frame) + else: + print("Face detection failed for target/source.") else: target_face = get_one_face(temp_frame) - if target_face: + if target_face and source_face: temp_frame = swap_face(source_face, target_face, temp_frame) + else: + print("Face detection failed for target or source.") return temp_frame + def process_frame_v2(temp_frame: Frame, temp_frame_path: str = "") -> Frame: if is_image(modules.globals.target_path): if modules.globals.many_faces: From c728994e6bae65a0b22a38ffa22c1ac006343742 Mon Sep 17 00:00:00 2001 From: Adrian Zimbran Date: Mon, 10 Mar 2025 23:41:28 +0200 Subject: [PATCH 2/2] fixed import and log message --- modules/processors/frame/face_swapper.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/processors/frame/face_swapper.py b/modules/processors/frame/face_swapper.py index 5def2ad..36b83d6 100644 --- a/modules/processors/frame/face_swapper.py +++ b/modules/processors/frame/face_swapper.py @@ -4,6 +4,7 @@ import insightface import threading import numpy as np import modules.globals +import logging import modules.processors.frame.core from modules.core import update_status from modules.face_analyser import get_one_face, get_many_faces, default_source_face @@ -114,7 +115,7 @@ def process_frame(source_face: Face, temp_frame: Frame) -> Frame: if target_face and source_face: temp_frame = swap_face(source_face, target_face, temp_frame) else: - print("Face detection failed for target or source.") + logging.error("Face detection failed for target or source.") return temp_frame