Skip to content

Keep CenterFace geometry isolated across concurrent requests - #1765

Open
Afloat16 wants to merge 1 commit into
serengil:masterfrom
Afloat16:fix/centerface-request-geometry-20261127
Open

Afloat16 wants to merge 1 commit into
serengil:masterfrom
Afloat16:fix/centerface-request-geometry-20261127

Conversation

@Afloat16

Copy link
Copy Markdown
Contributor

Tickets

Self-contained regression in cached CenterFace inference.

What has been done

CenterFace stores the resized image dimensions and scale factors on its shared model object. When requests with different image sizes overlap, one request can decode and rescale its boxes and landmarks using the other request's geometry. The resulting coordinates also select the wrong pixels during face extraction.

Keep the geometry local to each forward call and pass it through inference and postprocessing. The cached ONNX session can continue serving overlapping calls, and sequential decoding retains the same calculations.

Add deterministic concurrency regressions for images with equal and different resized network shapes, face extraction through the normal detection pipeline, and alternating sequential image sizes. The tests use unittest.mock only for model construction/inference; OpenCV resizing, decoding, NMS, coordinate conversion, and cropping run normally.

How to test

DEEPFACE_BACKEND_ENGINE=onnx python -m pytest -q \
  tests/unit/test_centerface_request_geometry.py \
  tests/unit/test_centerface_empty.py \
  tests/unit/test_face_crop_bounds.py \
  tests/unit/test_landmark_sanitization.py
python -m mypy deepface/

Base: master 8cec026045be164e14b510c55c1264e743dc4999.

  • Original production source: 3 new regressions fail, 1 sequential control passes.
  • Fixed production source: 51 selected tests pass, with no skips.
  • A separate native check runs the pretrained CenterFace ONNX graph on the repository's img1.jpg, resized to 257×331 and 403×249. Synchronizing the return of two real inference calls reproduces a maximum box error of 16.136 pixels and landmark error of 13.792 pixels on the original source. With this change, both requests exactly match their sequential boxes and landmarks. This used ONNX Runtime 1.32.0 on CPU, OpenCV 4.11.0, NumPy 2.3.5, and Python 3.12.14.
  • MyPy 1.14.1 passes all 145 source files before and after the change. Black checks and git diff --check pass.
  • CI-pinned Pylint 2.15.10 cannot finish under this Python 3.12 environment: Astroid crashes on visit_typealias on both the original and changed module. Compatible Pylint 3.3.9 reports the same two existing positional-argument warnings and 9.83/10 on both versions.

The full model/backend suite and GPU execution were not run.

Pass each image's resize dimensions and scale factors through inference
and postprocessing instead of storing them on the cached detector.
Preserve concurrent inference and cover overlapping detections and crops.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant