Skip to content
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

the question of face_recognition_sface_2021dec_int8 for java #187

Closed
12341234-yangboran opened this issue Jun 27, 2023 · 13 comments
Closed
Assignees
Labels
question It is not an issue but rather a user question

Comments

@12341234-yangboran
Copy link

ab08f10f81da851ecfa2be6cd795d2d
@12341234-yangboran
Copy link
Author

12341234-yangboran commented Jun 27, 2023

        FaceRecognizerSF faceRecognizerSF = FaceRecognizerSF.create("C:/Users/y1793/Downloads/face_recognition_sface_2021dec.onnx", "");
        Mat alignFaceA = new Mat();
        faceRecognizerSF.alignCrop(imageA, faceA, alignFaceA);
        Mat alignFaceB = new Mat();
        faceRecognizerSF.alignCrop(imageB, faceB, alignFaceB);

        
        Mat featureA = new Mat();
        faceRecognizerSF.feature(alignFaceA, featureA);
        Mat featureB = new Mat();
        faceRecognizerSF.feature(alignFaceB, featureB);

@fengyuentau
Copy link
Member

Expression: vector subscript out of range

Check whether faceA or faceB is empty.

@12341234-yangboran
Copy link
Author

faceRecognizerSF.alignCrop(imageA, faceA.row(0), alignFaceA);
like this?

@fengyuentau
Copy link
Member

See Python demo:

result = recognizer.match(img1, face1[0][:-1], img2, face2[0][:-1])

def match(self, image1, face1, image2, face2):
feature1 = self.infer(image1, face1)
feature2 = self.infer(image2, face2)
if self._disType == 0: # COSINE
cosine_score = self._model.match(feature1, feature2, self._disType)
return 1 if cosine_score >= self._threshold_cosine else 0
else: # NORM_L2
norml2_distance = self._model.match(feature1, feature2, self._disType)
return 1 if norml2_distance <= self._threshold_norml2 else 0

A face box should be sent to alignCrop. The face box should have the format as follows:

[x1, y1, w, h, lm1_x, lm1_y, ..., lm5_x, lm5_y]

, where x1, y1 are the top-left corner point and lm1, lm2, lm3, lm4, lm5 are right eye, left eye, nose tip, right corner of mouth, left corner of mouth respectively. See https://github.com/opencv/opencv_zoo/tree/main/models/face_detection_yunet for more details.

@12341234-yangboran
Copy link
Author

face_recognition_sface_2021dec_int8.onnx may be have something wrong.
63193f35936cfb5897eb8d24ea100433
2a453f25ef95ec02e4ea8c21bdd2b237
there are my image
faceRecognizerSF.match return 0.99999

@12341234-yangboran
Copy link
Author

FaceDetectorYN faceDetectorYN = FaceDetectorYN.create("C:/Users/y1793/Downloads/face_detection_yunet_2022mar_int8.onnx", "", new Size(), score_thresh, nms_thresh, top_k);
FaceRecognizerSF faceRecognizerSF = FaceRecognizerSF.create("C:/Users/y1793/Downloads/face_recognition_sface_2021dec_int8.onnx", "");

@12341234-yangboran 12341234-yangboran changed the title java java the question of face_recognition_sface_2021dec_int8 Jun 30, 2023
@12341234-yangboran 12341234-yangboran changed the title java the question of face_recognition_sface_2021dec_int8 the question of face_recognition_sface_2021dec_int8 for java Jun 30, 2023
@fengyuentau fengyuentau added the question It is not an issue but rather a user question label Jul 9, 2023
@fengyuentau fengyuentau self-assigned this Jul 9, 2023
@fengyuentau
Copy link
Member

hi @fengyuentau

+1 for this, i think something is wrong with the model scoring. i tested 2 faces that are very different, yet the score indicates it was identical.

my code: https://github.com/rh-id/a-jarwis/blob/master/ml-engine/src/androidTest/java/m/co/rh/id/a_jarwis/ml_engine/provider/component/FaceEngineTest.java#L77-L92

https://github.com/rh-id/a-jarwis/blob/master/ml-engine/src/main/java/m/co/rh/id/a_jarwis/ml_engine/provider/component/FaceEngine.java#L61-L79

https://github.com/rh-id/a-jarwis/blob/master/ml-engine/src/main/java/m/co/rh/id/a_jarwis/ml_engine/provider/component/FaceEngine.java#L139-L164

  1. Draw the detected face bounding boxes on the image to see whether faces are detected correctly.
  2. Make sure you send the correct face bounding box along with its matching image to the API.
  3. Could you test your image with the Python demo here? If the results are still wrong, then this model does not satisfy your need.

@rh-id
Copy link

rh-id commented Jul 12, 2023

hi @fengyuentau , I think the demo.py result is correct only my code is incorrect, you could ignore my questions. thanks and sorry for the trouble

@fengyuentau
Copy link
Member

@12341234-yangboran Could you doublecheck with the Python demo as well with your images as input?

@12341234-yangboran
Copy link
Author

hi @fengyuentau , I think the demo.py result is correct only my code is incorrect, you could ignore my questions. thanks and sorry for the trouble

You need clone the result of face recogniz feature to a new entity。

@12341234-yangboran
Copy link
Author

hi @fengyuentau , I think the demo.py result is correct only my code is incorrect, you could ignore my questions. thanks and sorry for the trouble

like this
Mat featureA = new Mat();
faceRecognizer.feature(alignFaceA, featureA);
featureA = featureA.clone();
Mat featureB = new Mat();
faceRecognizer.feature(alignFaceB, featureB);
featureB = featureB.clone();

@rh-id
Copy link

rh-id commented Jul 22, 2023

hi @12341234-yangboran

Yes that is right, it works. I think you could close this issue since it seemed the issue is solved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question It is not an issue but rather a user question
Projects
None yet
Development

No branches or pull requests

3 participants