Another post starts with you beautiful people!
Thank you all for showing so much interests in my last posts about object detection and recognition using YOLOv4. I was very happy to see many aspiring data scientists have learnt from my past three posts about using YOLOv4. Today I am going to share you all a new skill to learn. Most of you have seen my post about deploying and consuming ML models as Flask API where we have learnt to deploy and consume a keras model with Flask API . In this post you are going to learn a new framework- FastAPI to deploy your model as Rest API. After completing this post you will have a new industry standard skill.
What is FastAPI?
FastAPI is a modern, fast (high-performance), web framework for building APIs with Python 3.6+ based on standard Python type hints. It is easy to learn, fast to code and ready for production. Yes, you heard it right! Flask is not meant to be used in production but with FastAPI you can use your model in production with minimal code. Along with this advantage FastAPI also have inbuilt OpenAPI (previously known as Swagger) support. With this OpenAPI support you don't need to use Postman or any other tool for testing your API. You will have a UI where you can easily test your endpoints.
How to install FastAPI?
We can install FastAPI using pip. For this installation open your Anaconda Prompt with admin rights, activate your virtual environment and run the following two commands one by one-
Thank you all for showing so much interests in my last posts about object detection and recognition using YOLOv4. I was very happy to see many aspiring data scientists have learnt from my past three posts about using YOLOv4. Today I am going to share you all a new skill to learn. Most of you have seen my post about deploying and consuming ML models as Flask API where we have learnt to deploy and consume a keras model with Flask API . In this post you are going to learn a new framework- FastAPI to deploy your model as Rest API. After completing this post you will have a new industry standard skill.
What is FastAPI?
FastAPI is a modern, fast (high-performance), web framework for building APIs with Python 3.6+ based on standard Python type hints. It is easy to learn, fast to code and ready for production. Yes, you heard it right! Flask is not meant to be used in production but with FastAPI you can use your model in production with minimal code. Along with this advantage FastAPI also have inbuilt OpenAPI (previously known as Swagger) support. With this OpenAPI support you don't need to use Postman or any other tool for testing your API. You will have a UI where you can easily test your endpoints.
How to install FastAPI?
We can install FastAPI using pip. For this installation open your Anaconda Prompt with admin rights, activate your virtual environment and run the following two commands one by one-
- pip install fastapi
- pip install uvicorn
Here uvicorn is a lightning-fast ASGI server and enables us to use FastAPI for all our asynchronous calls without any worry. Once you installed this framework, you can confirm the installation by following code snippet-
See the similarity with Flask API. Here in the same manner we have initialized the FastAPI as app variable. Save the above file and to run this file use the command: uvicorn main:app --reload where main is your Python file name and app is the variable we used for the initialization of FastAPI() function. Here --reload parameter is used to take any changes in Python file immediately. After making any changes you will not need to rerun the server. Once your server is up and running you will see following look like message in console-
Now open the url http://127.0.0.1:8000/items/5?q=somequery in a browser window. You will see a json response. Now open the url http://127.0.0.1:8000/docs and you will see screen like below-
See, this is the OpenAPI UI where you can easily test your API endpoints. Now you are aware of basic of FastAPI, we will move to the next step.
Serving my YOLO model as FastAPI?
In this post I am going to deploy my YOLO model as FastAPI. If you still have not tried YOLO then you can learn from previous post and trained your custom model. The API deployment process will be the same for any kind of ML model. Here I am using my custom YOLOv3 models which detects price tags in a given shelf image and then extract the price from those tags. Basically aim of these models are to extract the price of a brand and send in response to front end. So in this example input will be the complete path of an image and response will be extracted price.
Here is my code snippet of main Python file-
As you can see code is similar as we saw earlier. Here I have defined my get_price() function as asynchronous using 'async' keyword. Function is taking one input arguement- image which is the complete path of the image. I am reading the image using OpenCV. The HTTP method of this call is 'GET'. The complete logic for price tag detection and recognition is written in another Python file tag_detection.py which I have imported and called the required function. This tag_detection() function will return the extracted prices. You can replace this function with your own classification/regression or NLP model logic.
I have saved this file as price_extraction.py. So I ran following command to run the server: uvicorn price_extraction:app --reload and after server started I open the OpenAPI UI with command http://127.0.0.1:8000/docs-
Now to test the endpoint click on the GET or your HTTP method button. In my case it is looking like below-
Once you expand your HTTP method, you need to click on Try it out button to enable the input field. Based on your ML model input fields may be more than one. In my case it is one. After clicking on this button, enter the values of the input field and click on the Execute button. This button will trigger your endpoint and return the response.
In my case response screen looks like below-
And my input image was this-
Quite interesting right! With minimal code we are able to deploy and consume our model as Rest API. We also don't need to use any external tool for testing the endpoints. With OpenAPI inbuilt support no wonder companies like Microsoft, Netflix and Uber are using the FastAPI in production. Now you don't need to think too much; just take your existing ML model, wrap it in FastAPI code you learned today from this post and start experimenting with it because we learn by doing experiments in Data Science.
Once you are done with this go ahead and deploy your FastAPI in Heroku by following this link to showcase your model with others. In my next post I will share you my new learning till then Go chase your dreams, have an awesome day, make every second count and see you later in my next post.
b
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteNice Article.Thank you for sharing useful information.
ReplyDeleteFor Online MBA check below.
Innomatics Research Labs is collaborated with JAIN (Deemed-to-be University) and offering the Online MBA in Business Intelligence,Business Analytics Program. This two-year program from JAIN (deemed-to-be) University offers foundation courses, core courses, Specialization courses, and a comprehensive master thesis intermediary, apart from an option to pursue a cross-functional and open elective.
Online MBA in Business Analytics
Online MBA in Business Intelligence
Thanks for sharing such an awesome information. Keep sharing more blogs.
ReplyDeleteData Science Training in Hyderabad
Machine Learning Training in Hyderabad
I really enjoyed reading your blog. I think fast API is the best web framework. I will definitely try it. But do you know anything on Informatica Read Rest Api? Please share if you have. Thanks!
ReplyDeleteOur DevOps Training in Noida incorporates *online classes, classroom sessions, real-life case studies, develop and deploy software using DevOps* and lots more.
ReplyDeleteGet the best Python Training in Noida, ✓ state-of-the-art infrastructure, ✓ interactive classes, ✓ self-paced studies, and ✓ studies through real-life case studies.
ReplyDeleteThis comment has been removed by the author.
ReplyDelete"Nice Blog! such a informative things you are sharing ,I really liked your content. If you wanna know about ""Skillslash | Training with live industry experience that gets you hired""
ReplyDeletego to Data Science Course"
It is very useful for me. Thanks...
ReplyDeleteAzure Databricks Online Training
Azure Databricks Online Training
i read your article it is very informative and attractive I hope you will share some more content. learn more from Machine Learning With Data Science Course
ReplyDelete
ReplyDeleteData Science Training Course in Delhi
Thanks for sharing the valuable information and helpful content . Machine Learning course
ReplyDeleteIt is extremely nice to see the greatest details presented in an easy and understanding manner.
ReplyDeletecyber security course
You completed certain reliable points there. I did a search on the subject and found nearly all persons will agree with your blog. 360DigiTMG data science course in jaipur
ReplyDeleteThank you for sharing an amazing & wonderful blog. This content is very useful, informative and valuable in order to enhance knowledge. Keep sharing this type of content with us & keep updating us with new blogs. Apart from this, if anyone who wants to join the Python Base training institute in Delhi, can contact 9311002620 or visit our website-
ReplyDeletehttps://www.htsindia.com/Courses/python/python-training-institute-in-delhi
Excellent work! You have a nice blog here. You wrote something that everyone could understand and made the topic appealing. This article is very interesting and effective because it explains everything in detail. Amazon Lex was used to building a chatbot, integrated with a web page and a web page deployed on the AWS cloud. Thank you for this very important article!. For more information Visit Clinical Data Science
ReplyDeleteTake my money!!! It is great and helpful article! congratulations!
ReplyDeleteankara parça eşya taşıma
ReplyDeletetakipçi satın al
antalya rent a car
antalya rent a car
ankara parça eşya taşıma
GİY18F
ankara parça eşya taşıma
ReplyDeletetakipçi satın al
antalya rent a car
antalya rent a car
ankara parça eşya taşıma
7Uİ
Ağrı Lojistik
ReplyDeleteÇorlu Lojistik
Kars Lojistik
Antalya Lojistik
Rize Lojistik
6TM56
0CF32
ReplyDeleteSivas Lojistik
Kars Lojistik
Afyon Lojistik
Sinop Lojistik
Kırıkkale Evden Eve Nakliyat
7597C
ReplyDeleteYozgat Parça Eşya Taşıma
Bartın Parça Eşya Taşıma
Tokat Lojistik
Tekirdağ Evden Eve Nakliyat
Hakkari Parça Eşya Taşıma
E64B5
ReplyDeleteErzurum Lojistik
Urfa Evden Eve Nakliyat
Siirt Lojistik
Eskişehir Evden Eve Nakliyat
Isparta Evden Eve Nakliyat
2D3A5
ReplyDeleteEdirne Evden Eve Nakliyat
Uşak Parça Eşya Taşıma
Erzincan Lojistik
Hatay Lojistik
Karaman Lojistik
3397B
ReplyDeleteKars Lojistik
Malatya Evden Eve Nakliyat
Tekirdağ Parça Eşya Taşıma
Şırnak Evden Eve Nakliyat
Giresun Parça Eşya Taşıma
79E67
ReplyDeleteMalatya Parça Eşya Taşıma
Urfa Lojistik
Bursa Parça Eşya Taşıma
Ağrı Parça Eşya Taşıma
Samsun Lojistik
FD46D
ReplyDeleteBitmex Güvenilir mi
Adıyaman Evden Eve Nakliyat
Tekirdağ Evden Eve Nakliyat
Kilis Şehirler Arası Nakliyat
Tekirdağ Çatı Ustası
Trabzon Şehirler Arası Nakliyat
Sakarya Lojistik
Ünye Çekici
Çanakkale Şehirler Arası Nakliyat
C60D9
ReplyDeleteAydın Şehirler Arası Nakliyat
Ünye Evden Eve Nakliyat
Kocaeli Lojistik
Giresun Evden Eve Nakliyat
Antalya Şehir İçi Nakliyat
Bolu Parça Eşya Taşıma
Ünye Yol Yardım
Karapürçek Parke Ustası
Altındağ Boya Ustası
0A48E
ReplyDeletebinance komisyon indirimi %20
87B48
ReplyDeletereferanskodunedir.com.tr
19DB6
ReplyDeleteAfyon Ücretsiz Sohbet Sitesi
bitlis rastgele görüntülü sohbet uygulaması
Tunceli Canlı Sohbet Sitesi
karaman rastgele canlı sohbet
sesli sohbet siteleri
yabancı sohbet
bayburt en iyi ücretsiz sohbet uygulamaları
çorum sohbet chat
balıkesir sohbet chat
0E927
ReplyDeleteen iyi sesli sohbet uygulamaları
van sohbet odaları
görüntülü canlı sohbet
balıkesir sohbet
Hatay Bedava Sohbet Uygulamaları
elazığ kadınlarla sohbet et
artvin canli goruntulu sohbet siteleri
Hakkari Kadınlarla Rastgele Sohbet
konya yabancı görüntülü sohbet
C3693
ReplyDeleteErzurum Parasız Görüntülü Sohbet Uygulamaları
bedava sohbet odaları
elazığ ücretsiz sohbet odaları
kırklareli canlı sohbet siteleri ücretsiz
Kars Canlı Sohbet Siteleri
Karaman Canli Sohbet
Rize Chat Sohbet
adıyaman mobil sohbet chat
bilecik sesli görüntülü sohbet
A6FD5
ReplyDeletesiirt kadınlarla ücretsiz sohbet
Sinop Rastgele Sohbet Siteleri
telefonda görüntülü sohbet
balıkesir parasız sohbet
Amasya Ücretsiz Sohbet Sitesi
Afyon Canli Sohbet
nevşehir mobil sohbet et
ücretsiz görüntülü sohbet
en iyi sesli sohbet uygulamaları
AA3D8
ReplyDeleteGörüntülü Sohbet Parasız
Tiktok İzlenme Hilesi
Btcst Coin Hangi Borsada
Bitcoin Nasıl Kazanılır
Kripto Para Nasıl Üretilir
Hamster Coin Hangi Borsada
Qlc Coin Hangi Borsada
Bitcoin Nasıl Alınır
Bulut Madenciliği Nedir
84A4C
ReplyDeleteGörüntülü Sohbet
Telegram Abone Satın Al
Kripto Para Nasıl Üretilir
Youtube İzlenme Hilesi
Bitcoin Nasıl Oynanır
Bitcoin Hesap Açma
Anc Coin Hangi Borsada
Kripto Para Üretme Siteleri
Twitter Retweet Satın Al
B0C53
ReplyDeletepoocoin
poocoin
trust wallet
dappradar
onekey
roninchain
chainlist
uwu lend
uniswap
4C5F9
ReplyDeleteavalaunch
pancakeswap
phantom wallet
shapeshift
layerzero
uniswap
satoshivm
zkswap
pudgy penguins
72EB3
ReplyDeleteEscobarvip İfşa
Şahinbey
Adilcevaz
Kırıkhan
Eşme
Çiftlikköy
Asarcık
İzmir
Kağıthane
6A5056CB1D
ReplyDeleteskype show