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 PyTorch VGG-Face model-memory improvement; no existing issue is being closed.
What has been done
The PyTorch VGG-Face embedding factory loads the full 2622-class checkpoint and retains its
fc8classifier inside the returned descriptor, althoughVggFaceDescriptor.forward()only callsembed(). These unused weights stay in the cached model and are included when the client moves it to its inference device.Release
fc8after the full checkpoint has loaded strictly and before wrapping the embedding descriptor. This removes 10,742,334 parameters / 42,969,336 bytes (40.98 MiB in float32) from the resident model. The initialized full model has 145,002,878 parameters; the descriptor needs 134,260,544.The factory still loads the existing complete pretrained checkpoint, including its classifier keys, with strict checking.
base_model()continues to construct a classifier, and directly constructedVggFaceDescriptor(base)objects keep their supplied base unchanged. Existing evaluation-mode setup and the embedding forward computation are unchanged.Visible model-state change: the descriptor returned by
load_model()now hasmodel.fc8 = None, and itsstate_dict()omitsmodel.fc8.weightandmodel.fc8.bias. Applications that manually saved an old descriptor's state and strictly reload it into the new descriptor must drop those two unused keys. This does not change the format or loading of the downloadable base-model checkpoint. Callers that need the 2622-class head should keep using the base classifier.How to test
Linux x86-64, Python 3.12.14, PyTorch 2.15.0+cpu; base
8cec026045be164e14b510c55c1264e743dc4999.OMP_NUM_THREADS=2 DEEPFACE_BACKEND_ENGINE=pytorch PYTHONPATH=. python -m pytest tests/unit/test_vgg_descriptor_memory.py -q: 3 passed. Tests write a compact synthetic checkpoint with every actual parameter shape and key, load it through the real strict loader, compare the real factory's(2, 4096)output exactly against the loaded base's embeddings, check that exactly the two classifier state keys disappear, retain the base classifier, and still reject missing embedding weights. No pretrained-weight download is needed.--follow-imports=silent): passed; Ruff critical rules andgit diff --check: passed. Black passes on the new test; the production file has the same pre-existing line-wrap finding as the base.Pretrained recognition accuracy, GPU memory and the full repository suite were not run locally.