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

Threshold of trained models #120

Open
mohamedamara7 opened this issue Jul 16, 2023 · 1 comment
Open

Threshold of trained models #120

mohamedamara7 opened this issue Jul 16, 2023 · 1 comment

Comments

@mohamedamara7
Copy link

mohamedamara7 commented Jul 16, 2023

How I can know the best threshold of your trained models for face verification? Is there even a pseudocode for reading two faces using cv2 and compare their similarity?

@leondgarse
Copy link
Owner

  • Most time I'm using 0.6 as threshold.
  • For reading image and compare, you can refer to colab efficientnetV2_basic_test.ipynb Keras insightface test section. Technically, Just following the steps face detection in image --> face align --> normalize to [-1, 1] --> input to model and get embedding output --> l2 normalize embedding --> calculate cosine distance is enough. Processes in video_test.py#L90 is following this.
    iaa = np.zeros([1, 112, 112, 3]) # Face image 1
    ibb = np.ones([1, 112, 112, 3]) # Face image 2
    
    mm = keras.models.load_model('model_path.h5') # load pretrained basic_model
    eaa = mm(iaa)  # face 1 embedding
    ebb = mm(ibb) # face 2 embedding
    print(eaa.shape, ebb.shape)
    # (1, 256) (1, 256)
    
    from sklearn.preprocessing import normalize
    eea = normalize(eaa) # normalize
    eeb = normalize(ebb)
    print((eea ** 2).sum(), (eeb ** 2).sum())
    # 1.0 1.0
    
    print(np.dot(eea, eeb.T)) # cos similarity
    # [[0.38431713]]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants