| import os |
| import urllib.request |
|
|
| if not os.path.exists("biden.jpg"): |
| urllib.request.urlretrieve("https://github.com/ageitgey/face_recognition/blob/master/examples/biden.jpg?raw=true") |
| urllib.request.urlretrieve("https://github.com/ageitgey/face_recognition/blob/master/examples/obama.jpg?raw=true") |
| urllib.request.urlretrieve("https://github.com/ageitgey/face_recognition/blob/master/examples/obama2.jpg?raw=true") |
|
|
| import face_recognition |
|
|
| |
| |
|
|
| |
| |
| |
|
|
| |
| |
|
|
| |
| known_obama_image = face_recognition.load_image_file("obama.jpg") |
| known_biden_image = face_recognition.load_image_file("biden.jpg") |
|
|
| |
| obama_face_encoding = face_recognition.face_encodings(known_obama_image)[0] |
| biden_face_encoding = face_recognition.face_encodings(known_biden_image)[0] |
|
|
| known_encodings = [ |
| obama_face_encoding, |
| biden_face_encoding |
| ] |
|
|
| |
| image_to_test = face_recognition.load_image_file("obama2.jpg") |
| image_to_test_encoding = face_recognition.face_encodings(image_to_test)[0] |
|
|
| |
| face_distances = face_recognition.face_distance(known_encodings, image_to_test_encoding) |
|
|
|
|
| import gradio as gr |
|
|
| def greet(name): |
| ret = "" |
| for i, face_distance in enumerate(face_distances): |
| ret += "The test image has a distance of {:.2} from known image #{}".format(face_distance, i) |
| ret += "\n" |
| ret += "- With a normal cutoff of 0.6, would the test image match the known image? {}".format(face_distance < 0.6) |
| ret += "\n" |
| ret += "- With a very strict cutoff of 0.5, would the test image match the known image? {}".format(face_distance < 0.5) |
| ret += "\n\n" |
|
|
| return ret |
|
|
| iface = gr.Interface(fn=greet, inputs="image", outputs="text") |
| iface.launch() |
|
|