perf(people): batch face embedding inference into single ONNX call #623

Merged
chris merged 2 commits from fix/face-embedding-batch into main 2026-07-14 23:21:27 +02:00
Owner

Summary

Replace per-face session.run() loop in detect_and_embed() with single batched ONNX inference call.

Changes

  • Add _preprocess_for_embedding helper: crops face region, pads 10%, resizes to 112x112, normalizes to [-1, 1]. Returns [3, 112, 112] tensor without batch dim.
  • Batch detect_and_embed: collect all face crops via _preprocess_for_embedding, stack into [N, 3, 112, 112], single session.run(), split output rows, L2-normalize each, assign to face dicts.

Edge cases handled

  • 0 faces: early return, no inference call
  • 1 face: ONNX may drop batch dim → reshape (512,) to (1, 512)
  • N faces: single batched call → [N, 512] output

Backward compatibility

  • _extract_embedding kept unchanged
  • Function signatures and return types unchanged
  • Output embeddings numerically identical (same preprocessing + normalization)
## Summary Replace per-face `session.run()` loop in `detect_and_embed()` with single batched ONNX inference call. ## Changes - **Add `_preprocess_for_embedding` helper**: crops face region, pads 10%, resizes to 112x112, normalizes to [-1, 1]. Returns `[3, 112, 112]` tensor without batch dim. - **Batch `detect_and_embed`**: collect all face crops via `_preprocess_for_embedding`, stack into `[N, 3, 112, 112]`, single `session.run()`, split output rows, L2-normalize each, assign to face dicts. ## Edge cases handled - **0 faces**: early return, no inference call - **1 face**: ONNX may drop batch dim → reshape `(512,)` to `(1, 512)` - **N faces**: single batched call → `[N, 512]` output ## Backward compatibility - `_extract_embedding` kept unchanged - Function signatures and return types unchanged - Output embeddings numerically identical (same preprocessing + normalization)
perf(people): batch face embedding inference into single ONNX call
All checks were successful
Build and Deploy / Detect changed services and test scopes (push) Successful in 7s
Build and Deploy / Run scoped PR tests (push) Has been skipped
Build and Deploy / Smoke API and media worker (push) Has been skipped
Build and Deploy / Smoke web (push) Has been skipped
Build and Deploy / Smoke ML worker (push) Has been skipped
Build and Deploy / Build plants worker image (push) Has been skipped
Build and Deploy / Build people worker image (push) Has been skipped
Build and Deploy / Build converter worker image (push) Has been skipped
Build and Deploy / Build API image (push) Has been skipped
Build and Deploy / Build media worker image (push) Has been skipped
Build and Deploy / Build web image (push) Has been skipped
Build and Deploy / Build ML worker image (push) Has been skipped
Build and Deploy / Deploy API (push) Has been skipped
Build and Deploy / Deploy web (push) Has been skipped
Build and Deploy / Deploy media worker (push) Has been skipped
Build and Deploy / Deploy ML worker (push) Has been skipped
Build and Deploy / Deploy plants worker (push) Has been skipped
Build and Deploy / Deploy people worker (push) Has been skipped
Build and Deploy / Deploy converter worker (push) Has been skipped
Build and Deploy / Clean Docker build artifacts (push) Has been skipped
e4b162aad3
Replace per-face loop with single batched session.run() call.
Add _preprocess_for_embedding helper returning [3,112,112] tensor.
Stack all face crops into [N,3,112,112] batch before inference.
Handle edge cases: 0 faces (skip), 1 face (batch dim handling).
Keep _extract_embedding unchanged for backward compatibility.
Merge branch 'main' into fix/face-embedding-batch
All checks were successful
Build and Deploy / Detect changed services and test scopes (push) Successful in 3s
Build and Deploy / Smoke API and media worker (push) Has been skipped
Build and Deploy / Smoke web (push) Has been skipped
Build and Deploy / Smoke ML worker (push) Has been skipped
Build and Deploy / Build plants worker image (push) Has been skipped
Build and Deploy / Build people worker image (push) Has been skipped
Build and Deploy / Build converter worker image (push) Has been skipped
Build and Deploy / Build API image (push) Has been skipped
Build and Deploy / Build media worker image (push) Has been skipped
Build and Deploy / Build web image (push) Has been skipped
Build and Deploy / Build ML worker image (push) Has been skipped
Build and Deploy / Deploy API (push) Has been skipped
Build and Deploy / Deploy web (push) Has been skipped
Build and Deploy / Deploy media worker (push) Has been skipped
Build and Deploy / Deploy ML worker (push) Has been skipped
Build and Deploy / Deploy plants worker (push) Has been skipped
Build and Deploy / Deploy people worker (push) Has been skipped
Build and Deploy / Deploy converter worker (push) Has been skipped
Build and Deploy / Run scoped PR tests (push) Successful in 2m39s
Build and Deploy / Clean Docker build artifacts (push) Has been skipped
03e2075a77
chris merged commit 7e059a4b0f into main 2026-07-14 23:21:27 +02:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
chris/memories!623
No description provided.