Tuesday, July 28, 2020

How to train Inception-v3 image classification model on custom Dataset

How to train Inception-v3 image classification model on custom Dataset

In this blog we are implementing  Inception-v3 image classification model on custom Dataset


We were using Inception-v3 model which is already trained by google on 1000 classes but what if we want to do the same thing but with our own images. We are going to use transfer learning which will help us to retrain final layer of already trained Inception-v3 model with new categories from scratch.

Now first we need to clone my Projects on your local system. i have used CPU for this. you can also impalement on GPU.

I have trained model with 2 classes for demo purpose. you can impalement more for learning. in image Classification we don't need any types of annotations just need Images Categories.

I have Provide 2 categories Dataset for custom Dataset training. you can use this code for real time image classification problem just insert your images folder in Dataset folder then start training.

It return .db files and label files.

Now start 

cmd :- git clone https://github.com/Manishsinghrajput98/inceptionv3_training.git

cmd :- cd  inceptionv3_training

Create virtual environment for this. I have used python 3.6  

cmd :- virtualenv --python=python3.6 myvenv

After this you have to activate the virtual environment

cmd :- source local/bin/myvenv

cmd :- pip install -r requirements.txt

The Folder structure like


I have already mentioned Dataset in my clone project. you don't need to download
Just clone my project. and if you want to train your images so you can replace images folder in 
Dataset folder. but remember images folder name indicate the class name. 

I have provide agriculture, and sports images 

One more point you have to create logs folder. (it is used for store our final train model)

This run.sh file containing number of  epochs, and path of your Dataset folder etc.

you can increase/ decrease epoch. according to your accuracy, number of classes.

you don't need to download pre-trained model for training. it automatically download.

cmd :- bash run.sh

If you run this files and show error like permission denied.

select the properties of run.sh files and set allow execution. then run

The program will start creating .txt files

like 


After this it will start training and complete around 5000 steps 

like



After taking some time your model will successful trained. and final train model store in logs folder.

like



Now we are testing our model on images 

I have already mentioned python script. you can easily use but make sure you need to change the path of logs folder which is contained trained model and label files according to you system.

cmd :- python inception_image.py --input test1.jpg

like 



and try another categories

cmd :- python inception_image.py --input test2.jpg 

like



Also you can try on videos i have also mentioned code for this in our project folder 

cmd :- python inception_video.py --input test.mp4 --output result.mp4

Also you can download my trained model with 2 categories for testing purpose Click here

Note :- Friends also you can create flask api for this. don't worry i have already created flask api for inceptionv3 model.and step by step follow this blogs. also you can download the code.In real time project we will needed api. so i have suggest you can follow this blogs  Click here 

If you have any doubt so please comment 

Thanks 

No comments:

Post a Comment

If you have any doubts. Please let me know