batch_swap: detect+align source once, swap N times #9

Closed
opened 2026-08-07 01:57:39 +00:00 by Mark · 0 comments
Owner

After the face-swap fix in a32bbef, every call to FaceSwapper.infer() does SCRFD detection + ArcFace embedding extraction + INSwapper inference. For multi-face targets (the common case), this re-detects/re-embeds the same source face N times.

Fix: Refactor infer() to accept either a raw source face image (current behavior) or a pre-computed embedding (skip detect+align+embed). Then update batch_swap() to detect+align+embed ONCE on the source image, then call batch_swap_with_embedding() for each target face box. Expected ~Nx speedup on N-face targets.

Files: auraframe/models/face_swapper.py — infer(), batch_swap()

Test: Benchmark timing before/after on a multi-face target. Identity transfer metrics unchanged.

Caveat: Performance optimization. Current behavior is correct (just slow). Don't bundle with other fixes.

After the face-swap fix in a32bbef, every call to `FaceSwapper.infer()` does SCRFD detection + ArcFace embedding extraction + INSwapper inference. For multi-face targets (the common case), this re-detects/re-embeds the same source face N times. **Fix:** Refactor `infer()` to accept either a raw source face image (current behavior) or a pre-computed embedding (skip detect+align+embed). Then update `batch_swap()` to detect+align+embed ONCE on the source image, then call `batch_swap_with_embedding()` for each target face box. Expected ~Nx speedup on N-face targets. **Files:** `auraframe/models/face_swapper.py` — `infer()`, `batch_swap()` **Test:** Benchmark timing before/after on a multi-face target. Identity transfer metrics unchanged. **Caveat:** Performance optimization. Current behavior is correct (just slow). Don't bundle with other fixes.
Mark 2026-08-07 02:38:17 +00:00
Sign in to join this conversation.
No description provided.