By Using Transfer Learning Create Own Machine Learning Model

By Using Transfer Learning Create Own Machine Learning Model

Transfer learning:

In deep learning, transfer learning is a technique whereby a neural network model is first trained on a problem similar to the problem that is being solved. One or more layers from the trained model are then used in a new model trained on the problem of interest.

Ex: I took a sample of celebrities dataset image from https://www.kaggle.com/havingfun/100-bollywood-celebrity-faces/data and predict the face by using of own model. so 1st I made this model from pre-trained model which is mobilenet model which is already created by someone and by meaning of pre trained model weights are already set . we only feed one FC layer by using NN . and then compile both models in one model.

So let's go for the code

No alt text provided for this image


In this code we first import the model MobileNet and we set the target size of image and freez the all input layer. In transfer learning the main concept is that we want to train those layer which satisfy our requirement or customize the layers with our requirement.

for this we have to freeze all I mentioned above the layers except input layer because input layer is not trainable.

No alt text provided for this image

This code our customize model with adding Fully Connected layers on the top of existing model that is mobilenet.

No alt text provided for this image

Now we load our celebrities dataset which I downloaded already from keggle.

No alt text provided for this image

This is code for trained the model by using keras framework and fit the model . and save the model in celebs_mobilenet.h6 extension.

No alt text provided for this image

Now here I load the our trained model. and predict the faces.

No alt text provided for this image

Here we feed the our dataset into this and predict the result. here below some our predicted faces..

No alt text provided for this image
No alt text provided for this image

Hope you liked it

Thankyou!




To view or add a comment, sign in

More articles by Suraj S.

Others also viewed

Explore content categories