OpenCV Series — 11 — DoppelGanger App — Using Dlib’s Face Recognition resnet Model
--
In this post , we are going to discuss about a project that I did as part of my OpenCV course. This project is used for identifying the celebrity lookalikes using Dlib’s pre-trained face-recognizer resnet model. There is no training involved , we will be just enrolling new celebrity faces to the model and use the Euclidean distance between the DoppelGanger image and the Celebrity images to identify the relevance between them for the look-alike. The model reshapes & converts the images to 128 X 1 vector , a point in 128 Dimensional space. We then use these array of vectors to calculate the Euclidean distance for the given image.
The sample dataset is used as given as below, 5 images per celebrity in each folder,
The celebrity names and the folders are mapped using a dictionary in a python numpy array file called celeb_mapping.npy
{'n00000001': 'A.J. Buckley',
'n00000002': 'A.R. Rahman',
'n00000003': 'Aamir Khan',
'n00000004': 'Aaron Staton',
'n00000005': 'Aaron Tveit',
'n00000006': 'Aaron Yoo',
'n00000007': 'Abbie Cornish',
.
.
.
}
So now let’s look at the code, Load the necessary packages.
Load the Dlib’s frontal face detector, shape predictor model and the face recognizer resnet model,
Load the celeb_mapping.npy to labelMap dictionary
Now we need to map the image files to the celebrity names
# Initialize variables.
subfolders = []
imagePaths = []
labels = []
nameLabelMap = {}
# For each subfolder in labelMap
for key in labelMap:
# Append the root folder path to the subfolder
subfolderpath = os.path.join(faceDatasetFolder, key)
# if it is a folder
if os.path.isdir(subfolderpath)…