CARVIEW |
Navigation Menu
-
-
Notifications
You must be signed in to change notification settings - Fork 56.2k
Add DNN-based face detection and face recognition into modules/objdetect #20422
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
{ | ||
Mat inputBolb = dnn::blobFromImage(_aligned_img, 1, Size(112, 112), Scalar(0, 0, 0), true, false); | ||
this->model.setInput(inputBolb); | ||
return this->model.forward(_face_feature); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
imho it needs a clone() here, else the 2nd run of the network overwrites the 1st
(shallow copy of the network's last layer)
and both features are the same
heh, you had it correct in your previous version
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the late response. I deleted the '.clone()' because I think maintaining the extracted feature is up to the user. User may allow network to overwrite the last feature to reduce excess memory usage.
And I'm sorry for another mistake, this function need not return any value.
Maybe, I can delete 'return', and add '.clone()' into the sample code.
faceRecognizer->facefeature(aligned_face1, feature1);
feature1 = feature1.clone();
faceRecognizer->facefeature(aligned_face2, feature2);
feature2 = feature2.clone();
@fengyuentau, thank you! Please, also add some regression test |
@fengyuentau, looks good to me, thank you! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@vpisarev What is about reusing of High Level DNN API concept? How to manage execution of used networks - select backend/device at least?
How this code should be aligned with existed opencv_face_detector?
detector = cv.FaceDetectorYN.create( | ||
args.model, | ||
"", | ||
(320, 320), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(320, 320)
How is this aligned with .setInputSize()?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This algorithm requires to generate priors/anchors for different input sizes. My intention is to allow users to set the input size for the network when creating instances in case the input size is fixed, such as taking video stream as input. However, users may also want to detect on images of different sizes with one instance, so .setInputSize()
is added to do so without distorting images.
image = cv.imread(args.input) | ||
|
||
# Set input size before inference | ||
detector.setInputSize((image.shape[1], image.shape[0])) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Input of what? frame? network input to be preprocessed?
Class methods have zero documentation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added the documentation to this class method in the latest commit. This class method sets the size of network input, which overwrites the input size in create
.
* fix typos in samples/dnn/face_match.py * import numpy before importing cv2 * add documentation to .setInputSize() * remove extra include in face_recognize.cpp
I read some code and documents on the |
@fengyuentau, we discussed this PR another time. We reached consensus that the face detector class cannot reuse the object detection class from dnn. But could you, please, derive the face detection and recognition classes from cv::dnn::Model? |
BTW, It would be easy in case of code in dnn module. But currently this code is in objdetect module. Internal dnn::Model::Impl interface is no exposing from dnn to other modules for now - more refactoring is required (probably from OpenCV Core Dev Team). Can we put these new algorithms into |
@alalek, I suggest to follow the same approach as with the deep learning-based tracking algorithms in opencv_video. Putting algorithms into a nested namespace is a bad idea, I think. If it will take a lot of time to refactor dnn to expose dnn::Model properly, I suggest to merge this pull request as-is |
jenkins cn please retry a build |
1 similar comment
jenkins cn please retry a build |
@alalek Anything else needs to be done for this PR regarding your and Vadim's comment? Can you help reviewing again? Thanks. |
jenkins cn please retry a build |
See comment in opencv_extra's PR. |
Add DNN-based face detection and face recognition into modules/objdetect * Add DNN-based face detector impl and interface * Add a sample for DNN-based face detector * add recog * add notes * move samples from samples/cpp to samples/dnn * add documentation for dnn_face * add set/get methods for input size, nms & score threshold and topk * remove the DNN prefix from the face detector and face recognizer * remove default values in the constructor of impl * regenerate priors after setting input size * two filenames for readnet * Update face.hpp * Update face_recognize.cpp * Update face_match.cpp * Update face.hpp * Update face_recognize.cpp * Update face_match.cpp * Update face_recognize.cpp * Update dnn_face.markdown * Update dnn_face.markdown * Update face.hpp * Update dnn_face.markdown * add regression test for face detection * remove underscore prefix; fix warnings * add reference & acknowledgement for face detection * Update dnn_face.markdown * Update dnn_face.markdown * Update ts.hpp * Update test_face.cpp * Update face_match.cpp * fix a compile error for python interface; add python examples for face detection and recognition * Major changes for Vadim's comments: * Replace class name FaceDetector with FaceDetectorYN in related failes * Declare local mat before loop in modules/objdetect/src/face_detect.cpp * Make input image and save flag optional in samples/dnn/face_detect(.cpp, .py) * Add camera support in samples/dnn/face_detect(.cpp, .py) * correct file paths for regression test * fix convertion warnings; remove extra spaces * update face_recog * Update dnn_face.markdown * Fix warnings and errors for the default CI reports: * Remove trailing white spaces and extra new lines. * Fix convertion warnings for windows and iOS. * Add braces around initialization of subobjects. * Fix warnings and errors for the default CI systems: * Add prefix 'FR_' for each value name in enum DisType to solve the redefinition error for iOS compilation; Modify other code accordingly * Add bookmark '#tutorial_dnn_face' to solve warnings from doxygen * Correct documentations to solve warnings from doxygen * update FaceRecognizerSF * Fix the error for CI to find ONNX models correctly * add suffix f to float assignments * add backend & target options for initializing face recognizer * add checkeq for checking input size and preset size * update test and threshold * changes in response to alalek's comments: * fix typos in samples/dnn/face_match.py * import numpy before importing cv2 * add documentation to .setInputSize() * remove extra include in face_recognize.cpp * fix some bugs * Update dnn_face.markdown * update thresholds; remove useless code * add time suffix to YuNet filename in test * objdetect: update test code
Merge with extra: opencv/opencv_extra#903
This PR adds a DNN-based face detector and a DNN-based face recognizer into
modules/objdetect
.Pull Request Readiness Checklist
See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request
Patch to opencv_extra has the same branch name.