Using Deep Learning To Predict How Many People Attended My Sister’s Engagement

My mom challenged me to give her an approximate count of people who attended my sister’s engagement.

Sumeet More
4 min readOct 13, 2019

--

This article is about how I approached and solved a problem with deep learning.

My sister’s engagement had just gotten over and my mom presented me with a challenge: I had to predict how many people attended the engagement. 😥

I will walk through each step with examples, for better understanding.

My approach

  • The base data to count the number of unique people was photos from our known contact, a photographer who has clicked pictures of all our family events.
  • I took all the photos from this photographer and put them in a folder.
  • Then I wrote a Python script to detect faces from pictures, cropped them and saved it in a folder.
  • Right after that, I developed a C# program using deep learning library, Face Recognition DotNet, to decipher if two photos of a facial picture belonged to the same person or not.

Note: In case you’re wondering why I checked for similarity, this is because one person can be in multiple photos and my Python script was just detecting and cropping faces. If we just count photos based on the Python script, we might get a false count since it will include duplicates.

That’s why I used the similarity factor for face photos using deep learning and got a unique count. 💫

Implementation

Now that we know the approach, let’s take an example and see how I implemented this with the above approach.

I am taking 2 photos, and as a human, we can easily tell that there are 3 unique people based on these two photos.

This entire post is based on these 2 photos and we will see how at each step these photos will be transformed to get the desired outcome.

Note: It is obvious I can’t write an entire post on the 500+ photos in our collection and I respect privacy of my guests. 🤗

We will submit the above 2 photos to my Python script, and let it detect faces and do the cropping.

Here’s the code:

And here’s the outcome:

After running the Python script on the photos, we’ve got the above outcome. You can clearly see the duplicates and the rectangular boxes around faces.

Now that we have photos in a folder, let’s run the C# program which uses deep learning library to get a unique count of people.

Here’s the code:

As you can see, the output is 3 (highlighted in the section in the top right-hand side), which is the desired output! 🚀.

A quick explanation of the above code

From these screenshots, you can take both the programs, replicate it at your end and see the results.

I won’t go too deep here, but let me give you a gist of what the program is doing.

Python script

Basically using opencv to detect faces from images. 👱‍♂️👱‍♀️

C# program

Using Dlib/FaceRecognitionDotNet deep learning library, we’re encoding both images into byte array and trying to match them using deep learning algorithms.

Conclusion

Woohoo! 🎉

I ran the same program for 500+ photos and got rough count of 94 unique people who attended the engagement. We had made arrangements for 100 people and getting this rough count through deep learning program helped us to verify that owner charged us for right number of people and event turned out to be success seeing the conversion rate. 🥳

Happy coding! 😄

Sumeet More is a Web Engineer at Softway. He is fascinated when two applications talk to each other. He loves Machine Learning and writing high performance code just as much as he loves eating Krispy Kreme donuts.

--

--

Sumeet More
Sumeet More

Written by Sumeet More

Software Engineer 2 at Microsoft | Backend Engineer and Architect| Blockchain & ML enthusiast | C#,.NET Core, Rust, Javascript and Go

No responses yet