Face Recognition Model (using MobileNet)

Facial Recognition Model training takes a lot of time for training the weights. So,I used the concept of transfer learning to train my model from a pre trained MobileNet model to save the time. All the features extracted by this model is similar so it takes less time to train model again .

For my model I freezed the layers already present in the model and added customized fully connected layer(fcl) in the end. This reduced the amount of dataset to be provided to my model.

I used dataset having faces of five celebrities separated in training and testing(validation) images folders .

Image for post
Image for post
training and validation images are stored in respective folders
  1. The first step was to reload MobileNet model. In variable MobileNet I added the weights but excluded the top layer by using include_top= False. Then the layers were freezed and made untrainable by using layer.trainable=False . The layers we then printed with their names and showing if they are trainable or not but since we have freezed them so model shows False succeeding their names.
Image for post
Image for post
Reloading MobileNet model and freezing the layers

2. The next step was to create customized FCL and and attach it on top of the freezed bottom layers. For this the function used was head_model having customized layers.

Image for post
Image for post
making customized layer and attaching with model
Image for post
Image for post
summary of model shows last five layers added by us

3. For better model training we use data augmentation to process out image dataset.

data augmentation performed

4. Model is trained by performing 5 epochs and the accuracy achieved by my model is 93.21%.

Image for post
Image for post
training model

5. testing our model by providing random images from test images.

Image for post
Image for post
prediction 1 (correct)
Image for post
Image for post
prediction 2 (false prediction)

The predictions can be further improved by altering our customized layers and providing a bigger dataset to our model.

The code is available at: https://github.com/ishajain140/face_recognition_model_mobilenet.git

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store