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
9B330A8412
ReplyDeletedรผลmeyen takipรงi
8E162D2A12
ReplyDeletetiktok takipรงi
Google Haritalara Adres Ekleme
Pasha Fencer Hediye Kodu
Eti Mutlu Kutu Kodlarฤฑ
Erasmus Proje
Google Yorum Satฤฑn Al
Township Promosyon Kodu
Para Kazandฤฑran Oyunlar
M3u Listesi
6F4BC53CF3
ReplyDeletefake takipรงi satฤฑn al
Google Yorum Satฤฑn Al
Dragon City Elmas Kodu
Avast Etkinleลtirme Kodu
Danone Sรผrpriz Kodlarฤฑ
101 Okey Vip Hediye Kodu
Coin Kazan
War Robots Hediye Kodu
Online Oyunlar
1DE7FF4FBC
ReplyDeleteTelegram Coin Botlarฤฑ
Telegram Airdrop Botlarฤฑ
Telegram Para Kazanma Botlarฤฑ
Telegram Para Kazanma Gruplarฤฑ
Binance Hesap Aรงma