Deploy Machine Learning (ML) models in Google Cloud Platform (Watch till end)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everyone this is satyajit patnak and welcome back to my youtube channel today we shall be discussing about how to deploy machine learning models into google cloud uh so you have trained a machine learning model that you are quite excited about and now you want to share it with the world now building a web application using flask flare or any other technology takes around almost 30 to 40 minutes for build up but how about making the application available on the internet 24x7 after all if no one can see your machine learning model in production who would believe that it exists so let's try to deploy our machine learning model to production on google cloud platform for this particular deployment step our requirements are simple we would just need this computer which we have right now and a google account that's it it's going to be very simple let's go ahead and understand the step-by-step process to deploy our machine learning model into google cloud before moving ahead let's try to understand what is google cloud uh gcp google cloud platform is one of the primary options for cloud-based deployment of machine learning models along with others such as aws microsoft azure alibaba etc with gcp depending on how you choose to have your model deployed there are basically three options which are google ai platform google cloud functions and google application engine so today's topic is all about google application engine but before that let's try to understand what each one of them means now google ai platform is an ai platform that makes it easy for machine learning developers data scientists and data engineers to take their machine learning projects from ideation stage to production and deployment quickly and cost effectively so coming on to the google cloud function it's a it's it's a very similar concept like the azure functions it's a it's one of the simplest way to run code it is an even driven serverless compute platform whereby your function gets executed when needed without the need for server provision while setting up any other related computer sources so we can we can easily configure a google cloud function and make it run by by by having a scheduling options and apart from that the third option is going to be the google app engine which we will be showcasing in this particular video now google's app engine is a platform as a service and cloud computing platform that's mostly used for developing and hosting web applications the auto scaling feature of the application engine automatically allocates more resources for the web application to handle the additional demand this is the choice we experimented for this particular project and let's see how we can create our first google application engine so for that let's console.cloud.google.com now i have already logged into my particular account but when you initially log into your account you can go and add your credit cards now how to add your credit cards you can simply google how to add credit cards in your cloud account and immediately you will be having a bandwidth of almost 23 000 almost 24 000 indian rupees so i have it i already have a google account and i have attached my credit card so you can already see that i have a promotional credits of almost 2 300 hk dollars i stay in hong kong so it's in hk dollars if you convert this currency to inr it's going to be somewhere around 22 000 inr which is more than enough to run any kind of pocs okay now let's try to create our first application to create our first application we'll have to go to the iam and admin and then you will have to go to the manage resources now i already have certain projects but let's try to create a new project create new project and let me provide the project name as breast cancer prediction okay now let me also edit the project id let me give the same project id as the project name location i will not have to choose any organization let's create it project id can have lawyer so let's have breast cancer prediction okay let's let's it's not available 1999. just i'll add a number okay that's fine we have already created and you can see it will be created in just one or two minutes let's give some time it's created let's try to refresh the page uh we can see that breast cancer prediction 1989 has already been created now let's go back to the compute section we'll go to app engine then we'll go to the dashboard now my app is currently let's choose my app okay i have selected my app okay now you can see this is my uh this is my application engine front front screen and you can see that you can also deploy your command using a command line interface now i have already downloaded the sdk but what you can do is you can simply go to this particular sdk and this is how it will look like now you can you can simply follow these steps you click on cloud sdk there you can get this particular option of get started once you click on get started you will have different options called as do you want it for ubuntu do you want it for red hat for mac os or windows i my windows user so i have created for windows and next step you just click on next next next you will have this quick start for windows then like obviously if you're using mac os you will have your different steps but once you have already downloaded this sdk setup you just have to click next next next and you can finish it once this is done you can select uh you will automatically see this particular screen once you click on the finish button now you just click on why you must login to continue now once you click on why a web browser will be opened with your credentials like this is my particular account and just allow and you will be able to log into the cloud sdk okay now now let's go back to my project and let's see now so far my application engine is ready let me if you want uh let me open my application quickly okay so so uh let's go to my particular folder of gcp deployment i have already created a folder called as gcp deployment this is how the folder looks like and this is my main py i hope you have already seen my previous videos which was on flask deployment and hierarchy deployment so in the heroku deployment i was using the file name as app.py but in gcp deployment i have renamed my file name to main dot py because this is this is the basic requirement of gcp the file name has to be main dot py that's that's what the interpreter that's what gcp accepts your main file to be okay very simple to your java functions when your first method is always your main method similarly in when you are deploying your code to gcp uh your main class your main file should be named as main.py okay so this is the script in which the prediction function is written and where all necessary necessary libraries listed in the requirements file needed for end to end data preparation and prediction are imported right here apart from that there is one more requirements which is my requirements.txt very similar to the heroku part i have simply copied and pasted this file from my heroku repo apart from this one more requirement is going to be your app.yaml file now app.yaml file is nothing but uh this is used to configure our app engines application settings in the app.yaml so you have to just mention runtime and your python version if you are using python 3.6 just mention it as python36 i'm using python 3.7.3 so i have mentioned it as python37 okay accordingly if you're using python 3.8 you'll have to mention python38 right so app.yaml file is also a requirement for gcp apart from that everything remains exact same from my heroku code now go back to your home.html if you remember when we were developing the application in flask here we used to have a local host here we used to have something like this right localhost 5000 slash but now instead of localhost we will be having url for predict now what is predict predict is going to be my predict function in the application uh in the main dot uh once again in the main dot py uh this is going to my predict function right so everything remains same i'm just using a pickle file uh model.sav i have already created my breast cancer model now if you are not clear with the flask part you can go back to my flask video and try to understand how this file has been created and now let's not go ahead and understand deep about flask right now we are concerned about uh you know deploying our code into gcp right so i'll just copy this particular path i'll open my command prompt i'll go to that particular location now before that you can go here you can see gcloud app deploy now let's try to uh let's before uh this particular command what you can do is you can do gcloud in it okay it will take one or two minutes let's let's wait i hope till now you have already downloaded the uh google cloud sdk if you haven't you can do that for me i have already downloaded it so that's the reason i am trying to run my gcloud init command let's see hopefully it should be it should be finished now but i don't know why it's taking so much of time let's wait for a couple of minutes so you can see my authentication is already successful i am already logged in in case in your case it is not visible this way it might ask you for an authentication so press y go to your uh upon pressing y automatically one browser will be opened just allow authentication and you will be able to log in now i have already logged in my project is selected as my one of my previous projects so we will change it let's try to create a new con let's reinitial let's try to create a new configuration okay let's just close it let's just close it i'm just terminating it so what i'll do is i will just remember this particular command gcloud app deploy app.yaml project and then i'll have to specify my project id now my project id if i remember it it is breast cancer prediction 1989. so let's try to see if it is working fine if not we'll have to change the project and then it will be able to deploy it let's let's try oh it's it's successful so it's asking for a region where you want your app engine application to be located you can press anything for me let's press 5. asia southeast i should have selected six but it's okay now it's creating app engine application in project breast cancer prediction 1989 and the region is this so it will take around five to seven minutes to create it now once the application is created we can go to the uh dashboard and we can see the web page now you can see the descriptor is this the we can just cross check if the path and everything is correct or not yes this is my path this is my app.yaml file this is my source code target project is this everything is correct and this is your target url which google has provided now just copy it uh do you want to continue uh if you have still if all your settings are okay just select y now see you can see it's uploading eight files so whatever files you have in that particular location in c python gcp deployment all the files will be uploaded to uh google cloud now in couple of minutes the the application will be live so we will be able to see that now before before before it runs just try to confirm once again if your application if your main.py has this particular code because if you are running it on localhost if you even if you write without this code it's it's okay if you write ab.run it will still work because it's your local host but when you are deploying it on hiroku or on gcp or on aws azure you have to mention this because only if your flask name flask application name starts with uh is equals to underscore underscore main underscore underscore then only your app will be run okay or else you will your app will not run uh like yesterday when i was trying this uh i was just having the app.run and the code was failing like the deployment was successful but the target url was uh failing with some bad gateway interface then i had to fix that right so make sure you have that particular code now let's try to wait for a couple of minutes now as i said there are multiple ways to you know deploy your application engine you can see you can see here welcome to application engine get started if you get if you get started here there are different techniques to uh you know deploy your application as well but we are developers right so i i usually uh choose the option of command line it makes me feel that i'm doing something right so that's the reason we have used command line interface but if you want to work with ease you can you can simply opt for this get started option definitely there will be multiple steps which will be asking for some options and then you can go ahead and deploy it right but even the command line interface mode is also not very tough it's like just couple of commands and your work will be done so let's let's wait for a couple of more minutes and we'll we'll see our application live okay i just missed a small step this particular code is present here [Music] now it's live it's live so let's try to see this particular code yo now you can manually open it or you can also uh you can also type g cloud app browse your default app is breast cancer prediction so hopefully that will be opened i'm sorry your default application is so a the other application so we'll have to mention the project equals to breast cancer right so then only it will open that particular application you can do this way or you can do uh this way also your target url is already here just simply copy it and paste it in your browser and it will open now let's wait and hopefully our yeah so the application is ready and uh we have finally uh come to our page so you can keep this particular api open it will be accessible throughout the for all the users anybody can access it and you know get their hands dirty obviously this code is not a very enhanced code because we are just focused on the deployment part and not on the machine learning part but at least something is better than nothing right so let's try to give some random values and submit yeah it should go to the predict function which it has gone slash predict the patient is not diagnosed with breast cancer so this is how your application is ready now the next question is if you are concerned about your billing now let's say if you are just worried about that too much people might have an access to your application they might use it and your money might be utilized so how to disable it now to disable it you can go to application engine go to settings now my default application is set as this particular wait a second breast cancer prediction 1989 i can go to here and now we don't want to delete it just give me a second i think yeah disable application okay so to disable breast cancer prediction type your application id so type your application id here go to disable and application update operation is going on yes your application is disabled now if you just simply refresh it it will give you an error 404 the requested url was not found now if you again want to make it active go and enable it right if you enable it it will be enabled so this is how you can restrict your access and uh so that i mean just for the sake of the billing purpose and so that's uh basically about the entire gcp deployment i hope you enjoyed the video if you enjoyed the video please like it share it among your friends and subscribe to the channel because it motivates me to provide more and more content and the next few videos i shall be coming up with the deployment steps on aws ec instances as well as azure cloud and also i'll also try to deploy machine learning models on alibaba account as well so that's it for today's video and thank you guys
Info
Channel: Satyajit Pattnaik
Views: 7,568
Rating: undefined out of 5
Keywords: google cloud, machine learning google cloud, google cloud deployment, gcp deployment, model deployment gcp, data science, machine learning, gcp satyajit, google cloud console, machine learning model deployment gcp, ml model gcp, cloud hosting, google cloud platform, machine learning models, google cloud certification, ml model deployment gcp, upgrad, ml model, how to deploy a machine learning model to google cloud platform, what is machine learning model deployment, ai code
Id: JCD8hnc25eU
Channel Id: undefined
Length: 22min 52sec (1372 seconds)
Published: Sat Aug 29 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.