From f95a0bb7fb677b28038608e028417b812fd89f48 Mon Sep 17 00:00:00 2001 From: Max Buckley Date: Wed, 22 Apr 2026 13:40:18 +0200 Subject: [PATCH] Make square aligned-face assumption explicit in _fast_paste_back Addresses Sourcery feedback on PR #1776: _get_soft_alpha caches a single NxN template keyed by N, which is correct for the inswapper model (128x128 aligned-face space) but would silently mis-warp if a caller ever passed a non-square aligned face. Assert the shape instead of silently assuming it. --- modules/processors/frame/face_swapper.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/modules/processors/frame/face_swapper.py b/modules/processors/frame/face_swapper.py index 361c3a6..80ce911 100644 --- a/modules/processors/frame/face_swapper.py +++ b/modules/processors/frame/face_swapper.py @@ -297,6 +297,10 @@ def _fast_paste_back(target_img: Frame, bgr_fake: np.ndarray, aimg: np.ndarray, """ h, w = target_img.shape[:2] face_h, face_w = aimg.shape[:2] + # inswapper's aligned-face space is square (128x128). _get_soft_alpha + # caches a single NxN template keyed by N, so fail loudly if that ever + # stops being true rather than silently mis-warping the alpha mask. + assert face_h == face_w, f"Expected square aligned face, got {face_h}x{face_w}" IM = cv2.invertAffineTransform(M) # Bbox in output coords from the affine corners of the aligned-face square.