Cache ArcFace ONNX session + remove redundant resize in _extract_arcface_embedding #8

Closed
opened 2026-08-07 01:51:42 +00:00 by Mark · 1 comment
Owner

_extract_arcface_embedding() in face_swapper.py has two performance issues:

  1. Redundant cv2.resize on line 251 — warp_and_crop_face already outputs 112x112, so the resize is a no-op that still allocates and copies.
  2. A fresh ort.InferenceSession is created per call (line 261) — hundreds of ms overhead per swap. The detector session is already cached on self._detector; the ArcFace session should be cached the same way.

Fix: Cache the ArcFace ONNX session on self._arcface_session. Remove the redundant resize.

Files: auraframe/models/face_swapper.py lines 245-268
Test: Existing tests pass. Benchmark to verify speedup.

_extract_arcface_embedding() in face_swapper.py has two performance issues: 1. Redundant cv2.resize on line 251 — warp_and_crop_face already outputs 112x112, so the resize is a no-op that still allocates and copies. 2. A fresh ort.InferenceSession is created per call (line 261) — hundreds of ms overhead per swap. The detector session is already cached on self._detector; the ArcFace session should be cached the same way. Fix: Cache the ArcFace ONNX session on self._arcface_session. Remove the redundant resize. Files: auraframe/models/face_swapper.py lines 245-268 Test: Existing tests pass. Benchmark to verify speedup.
Author
Owner

Fixed in 218e013:

  • Cached ArcFace ONNX session on self._arcface_session (keyed by model path) to avoid hundreds-of-ms session re-creation per swap
  • Removed redundant cv2.resize(face_bgr, (112, 112)) — warp_and_crop_face already guarantees 112x112 output
Fixed in 218e013: - Cached ArcFace ONNX session on `self._arcface_session` (keyed by model path) to avoid hundreds-of-ms session re-creation per swap - Removed redundant `cv2.resize(face_bgr, (112, 112))` — `warp_and_crop_face` already guarantees 112x112 output
Mark 2026-08-07 01:56:00 +00:00
Sign in to join this conversation.
No description provided.