Docker Machine Learning | Why You Need To Containerize Machine Learning Models


Subscribe Here





Why You Need To Containerize Machine Learning Models


Hey, guys, what’s going on so in today’s video? I’m gonna be walking you through. How to docker eyes one of your Python flask applications. So if you remember in one of the previous videos, we built a machine learning model around text mining using something called tf-idf, so the code for the most part is pretty much the same. So we’re not going to be dealing with this code. Too much. Well, we are going to be doing with is. We’re gonna be dealing with something called a docker file. Which is this as I move this over. What a docker file does is. It’ll actually give some instructions to the docker container to basically tell it what to install, put packages and dependencies to install. And then what command it’s supposed to be running after that, the whole purpose of a container. There’s so many different videos on containers. I’m not gonna go into too much depth, but the whole purpose of a container is it allows you to isolate your environment so that if you have specific requirements or a specific module that are within that container, you don’t have to worry about version control for your modules In which case it may actually break your code now. One of the things that I also like to do. They’re not always necessary. In a docker eyes container is still go ahead and run it in a virtual environment and you may ask well. Why would you run a virtual environment within a docker container? If the purpose of both of them is to isolate your environment, you may have a scenario where you actually may need to create two different docker containers off of the same image. Yet those two different docker containers may have different requirements, so for example. I may have half of my module. Run in one specific docker container that use Tensorflow 1.4 and then I may have the other half of my module or another module or Add-on module or something like that or another application that’s gonna run in Tensorflow 2.0 That could be one of the use cases. I will find that it’s sometimes best practices a virtual machine, But you really don’t have to in this case. So what this docker file does is? I’m going ahead and saying lets. Go ahead and call Python. 3.7 Let’s put in. Let’s put this all in a virtual environment within the actual container. I’m launching a new folder called app, and in this case, I’m basically saying, take all of the file contents within this folder and move it into the folder app. Then we’re gonna go ahead and run our requirement text, and then we’re gonna run the command. Python app Pi. So let’s go ahead and build a soccer container in terminal. So all I do is I open up a terminal application and I’m gonna make this bigger just for the same clarity here, and then the first thing I’m gonna do is I’m gonna go ahead and CD into this environment, So I’m just gonna hit CD, Which means change directory. Go ahead and drag this templates folder, And this is the file that I want. So I want to LS into this. I just have my four files, and that’s exactly what I’m looking for. So first and foremost, we need to make sure that we have docker installed. And if you don’t have doctrine style, Just go to Google Type and docker. And you will find the installation instructions for your operating system. It’s really really straightforward for mac and windows. I believe they have an actual Gui application that you can install if you are on Linux like a boon to or something like that, You can actually do it through command-line so to make sure we have docker running. I’m gonna go ahead and type docker, and this tells me that docker is running in fact because it gives me all of the background commands under docker. So the first thing I want to do is. I want to go ahead and see if I have any images. I’m gonna go over the concept of images containers in just a second, but as you can see, I have two pre-compiled images in here. One is Python and one is nginx, and I’m not gonna be using nginx in this one. I’m just going to be using the Python One and where that Python module really comes from where it says Python 3.7 That’s me calling in my docker file, saying that. Hey, listen! I actually need the Python. 3.7 package installed in my docker file. I’m not using engine X, so I don’t need it in this case. And so what it does Is It goes on to the docker repo, which is at Hub Docker. Calm and it’ll. Go ahead and download that repo for you. Now the other thing is. I do have this image installed, but I need to generate an image from all of this, so all of this code over here still needs to create its own image and what that image is gonna do is it’s gonna give me a few things. It’s gonna give me an instance of Python. It’s gonna give me an instance of a virtual environment and it’s going to install all of my dependencies all within that one container and the whole purpose behind the container is. I can actually run that container on a Mac. I can then export it out into a tar file, go into a Linux or Windows environment. I could then import it as a tar file and then just run that container as is without hafting, having to worry about any kind of dependencies or whether it’s gonna run here or not, it’s basically agnostic to platform, so it’ll run in Windows Mac Linux, you name it so in order to actually generate or create our first docker image First, we’re gonna go ahead and we’re going to say Docker build and here. I’m gonna give it basically a title. I’m gonna call it Doc App and we’ll say something like version 1 that’s a tag and basically I’m telling it to look for the existing folder that it’s in for that docker file. So when I do this, now, it’s gonna do is it’s gonna say, OK? I already have the Python application now. I’m going to install all the modules that I need for the virtual environment. It’s gonna do that now. It’s gonna generate my working directory. Install all my requirements and then. I’m gonna have an image that I can do something with, so we’re gonna give this a second to run. It shouldn’t take too much longer, but there’s a few different requirements within here that I’m actually using and now we’re done so now when I go to docker images which you’ll notice is, I actually have my DA Cap version 1 I have Python version 3.7 and again. I’m not using engine X. So now I have everything within DA Cap that I actually need so now. The question is, how do I go ahead and create a container and again? The container is basically going to be an instance of this image where it’s gonna take everything that is in that. Python file that a PI file that flask application, essentially as soon as I turn on the container, that environment is going to be ready for me to go into, so I can actually go to and then Port 5,000 and it’ll actually bring up my application. If I shut the container, it’ll actually take down my application and the whole purpose behind container izing things is that so I’m not consistently using resources and I don’t have my application running 24/7 otherwise, it’s going to be using CP usage, Ram and all that other kind of stuff. So that is the beauty behind a container. Alright, so now for me to go ahead and create my docker container. I’m gonna write in docker container run, Tak, D and basically what that means is. D means that I’m gonna detach this from my Python terminal or from my terminal in this case, and I’m gonna be able to run it in the background, and I’m gonna be running it on my local host 5,000 in my port or in my docker container. Sorry 5,000 we call the dock app version 1 and so basically, this gives you an ID for it now. The other thing that I wanted, I want to show you is. Actually this tool called Kinematic, which you can download it off of the docker website as well. I’m gonna let it open here right now and what this does is. I’m going to close that because that’s probably an old one. What this does is it’ll. Go ahead and show you the container That’s been Korea, so this container is called elegant. I don’t even want to pronounce that elegant something, but if I want to confirm that that is the docker container that I just created, I can say docker container LS, and it’ll actually say that this is the same one. It was created 34 seconds ago. Which is what we created. So you don’t have to use this application here, but this is a good way for you to start and stop your docker container. You can do it from here as we’ll. Just say Docker stop, and then the docker container name or docker. Start, so let me show you how this works what I’m gonna do is. I’m gonna go ahead and stop this container for now, So let’s stop it the stopping so that it stop. I’m gonna go ahead and bring over a terminal and in this terminal. I’m just gonna hit turn. So is where the application is hosted. So what happens in this case is when I’m not using my application and I don’t need it on a 24 hour basis. I put it in a container and I can shut the container off because I don’t want to be using the RAM and CPU usage. I could be dedicated like to some other kind of application now. Let’s say that the application. I want to actually be able to go in and use it. Another example of this could be say, for example, like a mortgage application. If you’re a financial adviser or somebody at a bank, you don’t necessarily need to have that application open 24/7 You may only want to have it open when you need it and I already start the container not to say that we’re going to tell them to start and stop containers, but there’s a way to do this in the background, but now that you see that this container is actually running. I can go ahead in here and now my application starts and so I can put in something like this is a great website and you can say. I like to browse websites. Let’s submit there, you go. Your cosine similarity is like roughly 26% And now, if I hit enter, you see, the application starts back up as soon as I had stopped [Music] The application stops the so does any resources against it so guys? Hopefully enjoyed this video. This is how you very simply containerize an application. This process can get a lot more complicated. If you really want it to be in practice, you know this is. I’m running the development server off of my localhost in practice. Obviously containerization is a little bit more complicated, but just to get you guys set up if you wanted to run this on a local host. This is one of the ways to do it, So hopefully you liked this video, and if you did, please consider liking and subscribing and I will see you next time. Thanks very much bye [Music]!

0.3.0 | Wor Build 0.3.0 Installation Guide

Transcript: [MUSIC] Okay, so in this video? I want to take a look at the new windows on Raspberry Pi build 0.3.0 and this is the latest version. It's just been released today and this version you have to build by yourself. You have to get your own whim, and then you...

read more