The photos of my family members were used to be recognized by the module.But i find the accuracy is low. All the male's faces were recognized as one face , and the same as the female's.
import face_recognition
chensijing_image = face_recognition.load_image_file("/root/picture/chensijing1.jpg")#member1,male
liuxiaoling_image = face_recognition.load_image_file("/root/picture/liuxiaoling1.jpg")#member2,female
huhongping_image = face_recognition.load_image_file("/root/picture/huhongping1.jpg") #member3,female
unknown_image = face_recognition.load_image_file("/root/picture/liuxiaoling2.jpg")
chensijing_face_encoding = face_recognition.face_encodings(chensijing_image)[0]
liuxiaoling_face_encoding = face_recognition.face_encodings(liuxiaoling_image)[0]
huhongping_face_encoding = face_recognition.face_encodings(huhongping_image)[0]
unknown_face_encoding = face_recognition.face_encodings(unknown_image)[0]
known_faces = [
chensijing_face_encoding,
liuxiaoling_face_encoding,
huhongping_face_encoding
]
results = face_recognition.compare_faces(known_faces, unknown_face_encoding)
print("Is the unknown face a picture of chensijing? {}".format(results[0]))
print("Is the unknown face a picture of liuxiaoling? {}".format(results[1]))
print("Is the unknown face a picture of huhongping? {}".format(results[2]))
print("Is the unknown face a new person that we've never seen before? {}".format(not True in results))
output:
Is the unknown face a picture of chensijing? False
Is the unknown face a picture of liuxiaoling? True
Is the unknown face a picture of huhongping? True
Is the unknown face a new person that we've never seen before? False
Maybe your family members look similar, so using a more strict tolerance will make the model more sensitive. Try passing a lower value for tolerance to compare_faces, like this:
results = face_recognition.compare_faces(known_faces, unknown_face_encoding, tolerance=0.5)
You can use the face_recognition.face_distance() function to check the face distance between your family members to find the best tolerance to use.
When I set the parameter tolerance=0.4, it performances very well.
Thank you!
Most helpful comment
Maybe your family members look similar, so using a more strict tolerance will make the model more sensitive. Try passing a lower value for tolerance to compare_faces, like this:
You can use the
face_recognition.face_distance()function to check the face distance between your family members to find the best tolerance to use.