Repository navigation
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Tickets
Newly measured memory retention in the existing representation path; no existing issue is claimed. Checked @Afloat16's 107 earlier repository PRs, related upstream representation/memory/concatenation PRs and issues, and the recent history of
representation.py. This is separate from detector crop batching and model classifier weights.What has been done
represent()collects a float32 array for every preprocessed face, then copies those arrays intobatch_images_np. The originalbatch_imageslist and the final loop variableimgremain alive throughoutmodel.forward(), retaining a second copy of the complete model input alongside inference workspaces.Release those two references immediately after concatenation. Use the batch array's length for the existing single-face embedding return branch. Face preprocessing, batch dimensions, model calls, result grouping, anti-spoofing and
return_facevalues are unchanged.Measured effect
A controlled public
DeepFace.represent()call processes 192 repeats oftests/unit/dataset/img1.jpginto 224×224 BGR float32 inputs. It uses the actualTorchFacialRecognitionadapter and a deterministic small CNN (1×1 Conv2d 3→4, ReLU, adaptive average pooling, flatten), providing a reproducible inference workspace without downloaded weights.Three alternating baseline/modified pairs ran in separate CPU processes, with one Torch thread. Median measurements:
The peak decrease in this controlled workload is 111.21 MiB (14.20%). All six inference-input hashes and complete-result hashes match exactly. Concatenation itself still temporarily needs both copies. These measurements describe this CPU workspace; they do not establish the peak reduction for every pretrained model, execution provider or allocator.
How to test
Base:
8cec026045be164e14b510c55c1264e743dc4999. Linux x86-64, Python 3.12.14, NumPy 2.5.5, OpenCV 4.13.0 and PyTorch 2.15.0+cpu.All 13 new cases fail against the original production file because the redundant arrays are still alive during inference. After the change, they pass while preserving pixels, embeddings, image grouping and metadata across single images, image lists, NumPy batches, both tested normalizations and
return_face. The final case executes the repository's real DeepID PyTorch network with deterministic initialized weights and compares its embeddings exactly; it is a functional check, not a pretrained accuracy measurement.Black 26.10.1 passes for the new test. Its requested production-file reformatting is identical on the base and this change and concerns existing lines outside this patch. Repository-pinned Pylint 2.15.10 crashes on both versions because astroid 2.13.5 cannot parse a dependency's Python 3.12
TypeAlias(visit_typealias); that local check is not reported as passing. The complete model/download test matrix and other inference backends were not run locally.