Basically I want to achieve what you suggested on #541 on the following knn example
https://github.com/ageitgey/face_recognition/blob/master/examples/face_recognition_knn.py
I used docker to get the example working fine
Have tried to print the result from this code, which are
closest_distances, are_matches but don't think those are relevant to what I need
# Find encodings for faces in the test iamge
faces_encodings = face_recognition.face_encodings(X_img, known_face_locations=X_face_locations)
# Use the KNN model to find the best matches for the test face
closest_distances = knn_clf.kneighbors(faces_encodings, n_neighbors=1)
are_matches = [closest_distances[0][i][0] <= distance_threshold for i in range(len(X_face_locations))]
# Predict classes and remove classifications that aren't within the threshold
return [(pred, loc) if rec else ("unknown", loc) for pred, loc, rec in zip(knn_clf.predict(faces_encodings), X_face_locations, are_matches)]
Did you find any solution for this??
@ageitgey could you please on this?
closest_distances is the distance between the unknown face and the known face. The lower the value, the stronger the match. The distance_threshold is how small that distance has to be to be considered a match. The default distance threshold is 0.6. So a closest_distance greater than 0.6 is not considered a match and a value less than 0.6 is considered a match - with smaller numbers being stronger matches.
That's how this model works. It doesn't use percentage match scores. But if you want to convert that distance value into an estimate of a percentage match so the number is more clear to you, you can use this function: https://github.com/ageitgey/face_recognition/wiki/Calculating-Accuracy-as-a-Percentage
I tried using that function.
this is my syntax :
percentage = face_distance_to_conf(closest_distances)
but i got the below error for the same:
TypeError: '>' not supported between instances of 'tuple' and 'float'
I got it working. However when I am trying the same for more than one person, it gives an error:
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
@ageitgey How can I use the same function for multiple faces in the frame?
Most helpful comment
closest_distancesis the distance between the unknown face and the known face. The lower the value, the stronger the match. Thedistance_thresholdis how small that distance has to be to be considered a match. The default distance threshold is 0.6. So a closest_distance greater than 0.6 is not considered a match and a value less than 0.6 is considered a match - with smaller numbers being stronger matches.That's how this model works. It doesn't use percentage match scores. But if you want to convert that distance value into an estimate of a percentage match so the number is more clear to you, you can use this function: https://github.com/ageitgey/face_recognition/wiki/Calculating-Accuracy-as-a-Percentage