Face Recognition using transfer learning

Face Recognition using transfer learning

I am writing this article to explain all the things which can used for face recognition using transfer learning

Transfer learning: Basically it is the way of using weights of pretrained model to trained for more objects. For more details go to this link .

https://machinelearningmastery.com/transfer-learning-for-deep-learning/

The pretrained model which we used is very famous model called VGG16.

VGG16: VGG16 is a convolutional neural network model proposed by K. Simonyan and A. Zisserman . The model achieves 92.7% top-5 test accuracy in ImageNet, which is a dataset of over 14 million images belonging to 1000 classes

No alt text provided for this image

The dataset which is used is ImageNet.

Dataset: ImageNet is a dataset of over 15 million labeled high-resolution images belonging to roughly 22,000 categories.

Steps for creating face detection model

  1. First we have to import vgg16 form keras as from keras.applications import vgg16
  2. Now we have to download the weights form vgg16 and

model= vgg16.VGG16(weights = "imagenet")

here VGG16 is a function which will download the weights from imagenet dataset

and this model has now all the layers which is used in VGG16 with their weights.

3. To see all the layers present in vgg16 use this

model.layers

4. As we dont want to tarined all these layers as these were trained already so we can

freeze all layers by making their trainable features as false

for layer in model.layers :

layer.trainable=False

No alt text provided for this image

5. Now we have to remove last layer of VGG16 which is the output layer because

now we want to add our layers so there is no need of vgg16 output layer. we can remove

layer while downloading the weights so write include_top = 'false' in Vgg16 function .

6. To create our own fully connected layer first import Dense function from keras and

create layers as many as anyone want to use .

No alt text provided for this image

In this code we have imported Dense for creating FCl (fully connected layer)

and the optimizer used for fully connected layer is RMSprop we can use any other

optimizer also such as adam. here we used model.output to get last layer of VGG16

it is not the output layer. now we add our fcl to that last layer but not using add function

as we mostly do the reason is their we create model from scratch but here our model is

created already we just add some more layers to train them for our new object.

'Gloabalavergaepooling2d ' function was used for converting the weights to 1D .

and we used activation function 'relu '. The number of neuron units can vary to any

number . Last layer of any model should be output layer so we used number of units in

this layer is 1 because we want to do binary classification similarly the activation

function used is sigmoid . Now here Model function is used for attaching vgg16 layers

with our own created fcl.

6. Now we have to compiled the model.

No alt text provided for this image

here we used binary_crossentropy optimizer for finding loss as its used for binary

classification. and metrics is used to find the train accuracy of dataset.

7. Now we have to train the model as

No alt text provided for this image

Before train the model we can do augmentation on dataset if dataset is small using Image

generator function . In this fit function we passed validation dataset to find testing accuracy

of test dataset and as we know accuracy of model also depend on number of epochs so we

should give sufficient number of epochs .In this model we have achieved 98.95% training

accuracy and 60 % testing accuracy. we can imporve it either increasing epochs or using

other methods.

8. Now last step to predict image or face for that we used Image function of keras to load

the image .and size of image we used to predict should be same as to train then convert it

into numpy array and after that expand the dimension of image from 3D to 4D as CNN

take dataset as 4 D .

No alt text provided for this image

Output

there is two values present result so we have to see class_indices to check which value

associated to which person and write one logic to show the image to with person name

No alt text provided for this image

Finally our model predict right person's face.

No alt text provided for this image


要查看或添加评论,请登录

Hritick Goyal的更多文章

  • Monitoring VM Using Prometheus

    Monitoring VM Using Prometheus

    In this article we will see how we can deploy Prometheus and Grafana server in kubernetes and how to use it for…

  • Web Development on Aws using Terraform

    Web Development on Aws using Terraform

    In this article we will see how to do web development on aws .For all configurations we will use terraform instead of…

  • Jenkins Image & deployment pipline

    Jenkins Image & deployment pipline

    In this article we will see how to create a jenkins image and how to use that image for building a deployment pipeline.…

  • Deploying App on AWS EKS (Elastic Kubernetes Service )

    Deploying App on AWS EKS (Elastic Kubernetes Service )

    In this blog i will explain how to use amazon eks service to deploy app . First it is good to know what is eks service.

  • Integration of Machine Learning models with jenkins (MLops)

    Integration of Machine Learning models with jenkins (MLops)

    In this article i will explain you how we can integrate machine learning model with devops (jenkins) These are the…

  • First task of Devops assembly line Training

    First task of Devops assembly line Training

    I have just completed my first task in devops assembly line training under Vimal Daga sir. The task was to create end…

社区洞察

其他会员也浏览了