ageitgey / face_recognition

The world's simplest facial recognition api for Python and the command line
MIT License
52.49k stars 13.38k forks source link

face distance accuracy calculation #245

Open tetrahydra opened 6 years ago

tetrahydra commented 6 years ago

I am using your code from face_distance.py

How can I calculate the matching in percentage? Can I simply re-write

(1 - face_distance)%

for i, face_distance in enumerate(face_distances):
    print("The test image has a distance of {:.2} from known image #{}".format(face_distance, i))
ageitgey commented 6 years ago

You can do that if you find it helpful to think of things that way. But keep in mind that the scale isn't exactly linear like that.

The best way to think of it is that a smaller number is less difference and that anything under the threshold you define is a "match". A "85% match" isn't necessarily better than a "80%" match.

tetrahydra commented 6 years ago

If I were to tell the non-techie users, that their requests were successful and the percentage matching rate is X% for each one, how do I do this?

My idea on threshold is 0.1 is strict and 1 when there is no threshold.

What is threshold in face_recognition, really? My understanding is that it is a permissible error.

ageitgey commented 6 years ago

The default threshold is 0.6 or lower face distance is a match. You can use a more strict (lower) threshold if you want by passing in a parameter to the compare_faces() function call.

There's not really a concept of X% match in this algorithm. So however you want to come up with that number is up to you. Whether you call a face distance of 0.6 a 100% match or an 80% match or whatever is up to you.