Building Fast Facial Recognition for Videos and Images

Getting started with facial recognition for noobs :D

Saurabh Kadam
Towards Data Science
3 min readDec 24, 2019

Before I start this story, I will give huge shout out to Adrian from PyImageSearch.If you are beginner in deep learning this is best course available in market.(I will put link for his page in bottom.)

If you are sci-fi fan like me than you would have seen person of interest.You have seen like AI finding faces in video feed.It find people’s faces from image repository.This is television version.What if I told you you can build in real life too.I forgot that thing for quiet while.

For this project I got idea from my roommate who I met few days ago.He was keep asking me character name from friends.How about we build facial recognition system in video.With Adrian’s code made that quiet possible.

Idea was quite simple feed data in CNN with enough images.I feed it 15 images for 5 characters from friends.You can get facial recognition encoding from facial recognition and store it in pickle file.You can read this encoding again and match against the faces in image and video file.If it is match then it will throw known_name which we stored in program.If it is not found then it will throw unknown.

I will add github repo and scrapper code for google images.File Recog.py contains encoding sample in pickle file.This pickle file will be used.Recog_faces will used the pickle file which used in mentioned screenshot down.It will throw unknown rectangle if file not present in dataset.Use maximum amount of sample for each character so we can have large number of encoding.This will help in facial recognition.We can same pickle for face recognition in video.

Little Code Guide for mentioned example.

https://gist.github.com/saurabh896/b705536ba4354c8aa382978d5ddfc8e4

Main part of this code facial recognition.We are using same part of code to dump encoding in pickle file.Like I said more sample will provide more accuracy.I run this code with 15 sample for each character so I run into around 83% accuracy.You can still see model not able to recognize Rachel’s Face.Above code recognize faces in image and save encoding in array if you want to see encoding you can just print encoding and known_faces.You will get data points for faces which looks like co-ordinates.If you want to try it you can do it.Remember data science field is motivated by curiosity.

https://gist.github.com/saurabh896/ffdc37836684420491cab60a01982658

Above code change your read your image.Open up your pickle files so loop through you encodings. Find matching encoding with the faces provided in images.If it got match then it will throw name from encoding array.If face not found then it will give unknown.

https://gist.github.com/saurabh896/4ee6e4bfe24467df535f7762b8b112e2

Last code for video.Videos are nothing but images arrange with respect to time.So we divide frame by frame images and match them like we did with images.We use two part first is input as input video which contains this character and output folder to get rectangle bounded output for the model.

if you want to learn more about imutils.use below link

This code will take time cause it is writing into new file.I prefer using laptop cause it has good configuration.If you don’t have good system ,use AWS or GCP for this experiment.

Facial recognition on characters

I implemented same pickle file in video.Which gave me following result.I have to tune up some code to work on slow motion but in the end Idea worked!!Little hiccup for Rachael.Hope Jennifer Aniston won’t mind!! :P

Video Example

You can find working code in github repo. I mentioned down look up if you are interested. Love to here back from you with more ideas.

Hit me up on saurabhkdm721@gmail.com

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Published in Towards Data Science

Your home for data science and AI. The world’s leading publication for data science, data analytics, data engineering, machine learning, and artificial intelligence professionals.

Written by Saurabh Kadam

Devops Professional by Job.Machine Learning ,Deep learning and 3D modelling for Hobby.

No responses yet

What are your thoughts?