Decide Whom Your Child Looks Like with Facial Recognition: Mommy or Daddy?

Parents do discuss whom their child is looking like but no one can really be convinced about the result with this discussion. Luckily, we have very powerful facial recognition technology nowadays to learn the real and unbiased answer. In this post, we are going to use deepface to decide a child looking more like to which parent.

Child of Brad Pitt – Angelina Jolie couple: Shiloh Jolie-Pitt

Vlog

You can either watch the following video or follow this tutorial. They both cover the parental look-alike facial recognition.


🙋‍♂️ You may consider to enroll my top-rated machine learning course on Udemy

Decision Trees for Machine Learning

Background of facial recognition technology

We normally use facial recognition technology to verify face pairs are same person or different persons. Face pairs are represented as multi-dimensional vectors by facial recognition models such as FaceNet. Thereafter, we expect to have much similar vectors for same person than different persons. We are using some high school physics formulas to understand the similarity of two vectors such as cosine similarity or euclidean distance. Finally, we classify a face pair as same person if the distance between its vector representations is less than a fine-tuned threshold value.

In contrast to regular facial recognition task, we will have two pairs in this problem: father-child and mother-child. We do not need a threshold value because this is not a verification task. We just need to find the whose distance is similar.

We have applied same idea to find the looking-alike celebrities to someone. In that experiment, we compared the face of target person to all imdb dataset. So, this is going to be parental look-alike facial recognition. Luckily, we just need to compare two pairs.

Loading Family Photo

I will use the family photo of Angelina Jolie and Brad Pitt which is also the cover image of this post.

import cv2
import matplotlib.pyplot as plt

# load individual images
father = cv2.imread("father.png")
mother = cv2.imread("mother.png")
child = cv2.imread("child.png")

# plot the family photo
fig = plt.figure(figsize=(15, 15))

ax1 = fig.add_subplot(1,3,1)
plt.imshow(father[:,:,::-1]); plt.axis("off")

ax1 = fig.add_subplot(1,3,2)
plt.imshow(child[:,:,::-1]); plt.axis("off")

ax1 = fig.add_subplot(1,3,3)
plt.imshow(mother[:,:,::-1]); plt.axis("off")

plt.show()

Parental look-alike facial recognition

Luckily, we can by-pass all explained stages above because deepface handles all those required stages in the background. We just need to call a line of code with deepface! To customize the results, I used FaceNet facial recognition model, MtCnn face detector and euclidean distance in the verification configuration. You do not have to set all these 3 arguments. Just passing image pairs is enough to run verification function in deepface.

# father and child pair
paternal_result = DeepFace.verify(img1_path="father.png", 
                                  img2_path="child.png", 
                                  model_name="Facenet", 
                                  detector_backend="mtcnn",
                                  distance_metric="euclidean"
                                 )

# mother and child pair
maternal_result = DeepFace.verify(img1_path="mother.png", 
                                  img2_path="child.png", 
                                  model_name="Facenet", 
                                  detector_backend="mtcnn",
                                  distance_metric="euclidean"
                                 )

Similarity

Verification function returns a json object. You can find the results for father-child pair and mother-child pair below.

# paternal result
{'verified': False,
 'distance': 14.610031647877342,
 'threshold': 10,
 'model': 'Facenet',
 'detector_backend': 'mtcnn',
 'similarity_metric': 'euclidean'}

# maternal result
{'verified': False,
 'distance': 15.884559846193422,
 'threshold': 10,
 'model': 'Facenet',
 'detector_backend': 'mtcnn',
 'similarity_metric': 'euclidean'}

Notice that verified keys are false in the result. This is expected because actually no pairs are same person. Verified key is set to false if the found distance value between vector representations is greater than the threshold value. Found distance and fine-tuned threshold values are also available in the response. We can discard threshold value in the response similar to verified key. We just need distance values in the response.

Decision rule

Remember that we expect more similar vectors for same person than different persons. Distance is the inverse calculation of similarity. The more similar vectors, the less distance value. Then, we expect smaller distance values for same person than different persons. So, we should compare the distance values in the results. Smaller one would be the parent looking like. The decision can be made with the following rule.





if paternal_result["distance"] < maternal_result["distance"]:
    print("the child is looking more like to his/her father")
else:
    print("the child is looking more like to his/her mother")
Shiloh is looking more like to her father

Distance score of Shiloh-Angelina pair is 15.88 whereas Shiloh-Brad pair is 14.61. So, according to the facial recognition technology analysis, Shiloh Jolie-Pitt is looking more like to Brad Pitt than Angelina Jolie!

More experiments

Let’s evaluate this approach for another celebrity couple’s daughter.

Suri Cruise – Daughter of Tom Cruise – Katie Holmes couple
#paternal result
{'verified': False,
 'distance': 15.893103607375274,
 'threshold': 10,
 'model': 'Facenet',
 'detector_backend': 'mtcnn',
 'similarity_metric': 'euclidean'}

#maternal result
{'verified': False,
 'distance': 13.443684986913196,
 'threshold': 10,
 'model': 'Facenet',
 'detector_backend': 'mtcnn',
 'similarity_metric': 'euclidean'}
Suri Cruise is looking more like to her mother

Distance score of Suri-Tom pair is 15.89 whereas Suri-Katie pair is 13.44. So, according to the facial recognition technology analysis results mentioned above, Suri Cruise is looking more like to her mother Katie Holmes than her father Tom Cruise.

Please share me your experiments.

Conclusion

So, we have used facial recognition technology to decide the child looking more like to which parent. We applied almost same procedures we are running in face verification.

I pushed the source code of this study into GitHub as jupyter notebook. If you like the content, you might want to interact with the post by reposting it. Also, I will be appreciate if you star ⭐ the GitHub repo of deepface project 🙏 .


Like this blog? Support me on Patreon

Buy me a coffee