How to create Flask Machine Learning API for Inception-v3 Image Classification model.
In this blog we are implement flask api for inception-v3 classification deep learning model
According to click here
An application programming interface is a computing interface which defines interactions between multiple software intermediaries. It defines the kinds of calls or requests that can be made, how to make them, the data formats that should be used, the conventions to follow, etc.
we are create Flask api for this.
Flask is a web application framework written in Python. It has multiple modules that make it easier for a web developer to write applications without having to worry about the details like protocol management, thread management, etc.
Flask gives is a variety of choices for developing web applications and it gives us the necessary tools and libraries that allow us to build a web application.
Now come to the python code.
First we need to clone my project then download pre-trained machine learning model for detection
One more point guys we are using cpu for this. you can also Deploy your model on GPU or any other server machine.
Source Code : git clone https://github.com/Manishsinghrajput98/ML_Flask_APIs.git
cmd : - cd ML_Flask_APIs
In clone project i have mentioned 3 requirement txt file according our need in project i have used python 3.6
cmd :- cd inceptionv3_ml_flask_api
You can create virtual environment for this
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
After this you need to download my trained model i have providing. you can download easily.
Download Trained Model
After download you need to copy your downloaded model in our clone project. in contained two files one is label files (train.txt) and second is model files (train.pb).
I have train two categories for demo purpose you can use this model.
And in future you can use your training model just replace the path of model file and label file.
After this you need to copy/past our download model in our clone project inceptionv3_ml_flask_api logs folder
And also we need a Postman software to test our API. you need to download postman and then sign up Login.Postman is a scalable API testing tool that quickly integrates into CI/CD pipeline
Now. we are ready to test our api on Postman.
Step by step how to use Click here
The project structure looks like
now we need to run our python script for this.
cmd :- inception_flask_ml.py --port 8080
After this you need to open postman to hit our api
The address of our server to past in postman
Address :- http://localhost:8080/start (This is my local system address. If you have any other server so past these address)
Also we need parameter of our api
Parameter : -
{
"image_path":"/home/rajput/Desktop/ml_flask_api/yolo/manish.png"
}
Change the path according to your system path
After this you can seen the result of our model in terminal also in postman
Fig 1
Fig 2
Note :- Friends this is the complete Flask API with real time Project. you can use these api for your project. in Real time project we need a class name of images, this api also return class name and write text on images Save in our project output folder also you can try this api on videos with FFMPEG (need to some changes)..
Just copy your model path,label name txt, and past these api.
If you have any doubt so please comment
Thanks
No comments:
Post a Comment
If you have any doubts. Please let me know