Building Fast Facial Recognition for Videos and Images
Getting started with facial recognition for noobs :D
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.
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.
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.
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.
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
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