Introduction
I use here VGG19 pretrained Convolutional Neural Network for the image classification which already trained on 14 million dataset images which belongs to the 1000 classes. I didn't take any custom dataset. I just import some libraries and download the weights of the VGG19 pretrained model and simple save the model using .h5 file and just test model on different images. I have also deployed this model on localhost using the python framework (Flask).
NOTE: I doesn't use a custom dataset. I only download the weights of the VGG19 model. Try to use and deploy. If you want to learn transfer learning with custom dataset So you can follow my previous blog.
Image Classification using Transfer Learning
Transfer learning is the reuse of a pre-trained model on a new problem. It's currently very popular in deep learning because it can train deep neural networks with comparatively little data.
VGG19 is a pretrained Convolutional Neural Network. This model achieves 92.7% top-5 test accuracy in ImageNet, which is a dataset of over 14 million images belonging to 1000 classes.
Architecture of the VGG19 model
→ 2 x convolution layer of 64 channel of 3x3 filter size and same padding and activation function will be relu(Rectified Linear Unit)
→ 1 x maxpool layer of 2x2 pool size and 2x2 stride
→ 2 x convolution layer of 128 channel of 3x3 filter and same padding and activation function will be relu(Rectified Linear Unit)
→ 1 x maxpool layer of 2x2 pool size and 2x2 stride
→ 4 x convolution layer of 256 channel of 3x3 filter and same padding and activation function will be relu(Rectified Linear Unit)
→ 1 x maxpool layer of 2x2 pool size and 2x2 stride
→ 4 x convolution layer of 512 channel of 3x3 kernal and same padding and activation function will be relu(Rectified Linear Unit)
→ 1 x maxpool layer of 2x2 pool size and 2x2 stride
→ 4 x convolution layer of 512 channel of 3x3 kernal and same padding and activation function will be relu(Rectified Linear Unit)
→ 1 x maxpool layer of 2x2 pool size and 2x2 stride and activation function will be relu(Rectified Linear Unit)
Basically relu activation function apply to each layers so that all the negative values are not passed to the next layer.
After implementing all the convolution layers then I flatten the data into vectors which comes out of the convolutions and I passed the data to the dense layer.
→ 1 x Flatten layer
→ 1 x Dense layer of 4096 units and activation function will be relu(Rectified Linear Unit)
→ 1 x Dense layer of 4096 units and activation function will be relu(Rectified Linear Unit)
→ 1 x Dense Softmax layer of 1000 units and activation function will be softmax.
Softmax activation function will be used when we have a multiple classification problem.
![]() |
| VGG19 Network Architecture |
Lets start:-
Firstly, import all the required libraries for train and test the model like numpy, VGG19, matplotlib, load_model, preprocess_input, decode_predictions etc. Then download the VGG19 weights. The size of the VGG19 weights is 549 MB. And check the summary of the model.
Then i saved my model with .h5 file and load the model using the load_model library.
Test my model using VGG19 weights.
Deployment
I have also deployed this model using the python framework flask. Flask is a library of python which provides tools for the web development.
You can see the testing in the below image. This is the simple GUI of our web page. Just upload the image using the choose button. And click on the button. Let's upload the image.
You can see that i upload the groom image using the upload button and you can see the result of our model. Let's test another image.
Now i upload a panda image and you can see the result.
NOTE: If you have a gpu based laptop, then you can run .ipnyb file in local system. Otherwise you can use the Google Colab which provides a faster gpu for train a model faster. And one more thing. When you run .ipnyb. So it downloads the weights of the VGG19 whose size is 549 MB. So you need to download the model after saving and use the model with flask application.
Source code and how to use:
1. Go to my github and download code : Image Classification using Transfer Learning
2. After download, Extract the folder.
3. Then run the .ipnyb file to download the weights of 549 MB and after downloading, just save the model and use it.
4. Then Go into the folder.
5. Open the command prompt and go to the project folder with cd command.
6. Write (python Image_classification.py) in your prompt.
7. You will get a link like (http://127.0.0.1:5000/).
8. Paste in the Chrome or any browser.
9. Now you can use the model.
Video Tutorial
ThankYou!!!!!!







How to use use Naive-bayes
ReplyDeleteWait brother... I'll explain you in next project
Delete