Repository navigation
Run mtcnn on tensorflow, pytorch and onnx, group detectors by engine - #1681
Merged
Merged
Conversation
mtcnn and fastmtcnn were the same model - identical weights, a few pixels
apart from pre/post-processing - so fastmtcnn is now mtcnn on pytorch.
- mtcnn is routed by backend engine: ipazc/mtcnn on tensorflow,
facenet-pytorch on pytorch, and a new native onnx port on onnx
- onnx mtcnn: P-Net, R-Net and O-Net exported from facenet-pytorch with
channels last inputs, and its pipeline ported to numpy. It finds the
same faces as pytorch - identical boxes and eyes on all 76 faces in
tests/unit/dataset - at the same speed, without tensorflow or torch
- fastmtcnn stays as an alias of mtcnn on pytorch and logs a one-time
deprecation warning
- face_detection is grouped into tf, pytorch, onnx, opencv and external
subpackages
- facenet-pytorch moves to the pytorch extra, capped below 2.6.0 since
2.6.0 pins torch<2.3, numpy<2 and Pillow<10.3. The pytorch docker image
installs facenet-pytorch==2.5.3
- werkzeug is imported for type hints only, so a base install without the
api extra can import deepface again
- readme no longer mentions fastmtcnn
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.
Summary
mtcnnandfastmtcnnwere the same model. Their weights are identical tensor by tensor,and their boxes differ by only a few pixels because of pre/post-processing. This PR makes
mtcnna single detector that runs on every backend engine, adds a native onnx version,and groups
face_detectioninto one folder per engine.mtcnn on every engine
fastmtcnn)fastmtcnnstill works on every engine. It now points to the pytorch implementation andlogs a one-time warning that the name will be deprecated in favour of
mtcnnon thepytorch engine.
onnx mtcnn
channels-last inputs like the other deepface onnx graphs. P-Net accepts any input size. Its
ceil-mode max-pool is swapped for an equivalent that onnx can export with dynamic shapes.
Each graph matches torch to ≤5e-5.
regression, three stages) is ported to numpy. The area resize reproduces torch's
interpolate(mode="area");cv2.INTER_AREAwould not give the same result.identical boxes and eye coordinates. Confidences agree within 4e-7.
Hugging Face as backup. Both sources were verified byte-identical.
face_detection layout
tf/pytorch/onnx/opencv/external/Detectors other than mtcnn are still offered on every engine, as before.
Dependencies
facenet-pytorch>=2.5.3,<2.6.0moves fromrequirements_additional.txtto thepytorchextra. The cap matters: 2.6.0 pins
torch<2.3,numpy<2andPillow<10.3, which woulddowngrade users' installs.
facenet-pytorch==2.5.3, pinned liketorch==2.1.2.Fixes
deepface/commons/image_utils.pyimportedwerkzeugat module level, but werkzeug comesonly with the
apiextra. A basepip install deepfacetherefore failed as soon asdetection was imported. werkzeug is now imported for type hints only.
Behaviour changes
mtcnn: they now get facenet-pytorch instead of the keras-basedpackage. Boxes may shift by a few pixels.
mtcnn: they get the native port instead of the keras-based package,so keras is no longer required.
Test plan
tests/unit/test_mtcnn_engines.py: routing per engine, thefastmtcnndeprecation alias, area resize vs torch, NMS, no-face and tiny-image paths, and onnx vs
pytorch parity
passed; 15 torch/facenet-pytorch checks skip)