Deployment
We will learn how to deploy a machine learning model, for this we will explore
Deploy and host from local system using ngrok
Deploy on PaaS using Heroku and Azure Apps
Deploy on Serverless using AWS Lambda and Azure Functions
Deploy on Virtual Machines using Azure VM
Deploy on contained using Docker
Deploy and host from local system
The simplest way to undestand deployment is like functions in any programming language. We create / develop a function with / without parameters and it executes when called for example here. This is done to avoid repeating same line of code else where in program. Similarly, we will put our main Machine Learning code inside such a function, thereby giving capability of sending input data for prediction, classification or clustering task.
Psudo Code
// Some code: File: ML.py ( path C:\Users\Laptop\desktop\ml\mlfile\ml.py )
def predict():
> preprocessing
> x = predict
return x
// File: main.py ( path C:\Users\Laptop\desktop\ml\main.py )
from mlfile.ml import predict
from flask import Flask
app = Flask(__name__)
@app.route('/')
def index():
predict() # this is where we try to execute the code
return 'Web App with Python Flask!'
Example
Here we will just try to create a basic image segmentation machine learning model but here we will already provide the correct path to our image to the ML code. If needed we can always create Flask app that provide ability to upload image file that needs to be segmented.
Create a folder on Desktop name mldeploy
Create Python Virtual Environment here named project
Inside virtual environment download necessary modules to run ML model, Flask app etc.
Create a app.py file inside project folder where our basic Flask app will reside ( Code here )
Create another folder inside project named ML with 3 sub directories Data, Model, Output like this for inputting data, creating model.py file and saving output respectively.
Last updated
Was this helpful?