Deploy machine learning model on IOX-Gateway
This sample usecase demonstrates how a pre trained machine learning model can be deployed on the IOX gateway
IOTMLmodel: Linear Regression ML model building from sample IOT dataset - 'Household power Consumption' dataset downloaded from https://data.world/databeats/household-power-consumption . Two different sample linear regression models are built, trained on the sample data and stored as pickle models for deployment on Edge device i.e, IOX Gateway
IOXMLApp: Demonstrtaes pre-trained ML models ML can be deployed on a webserver with an REST API to predict the 'Global Active Power' of a household based on 'hour'. Two models 'iotmode.pkl' or iotmodel2.pkl' can be used for deployment by changing the file name
sampleclient: Sample rest client application that sends the data in a json format , invokes the API get predicted output and prints the json response on screen (see screenshot below) the ip address of edge ML server and payload is selected in 'sample.data.py'
Clone this repo first and follow the steps to run each Component
git clone https://github.com/wiprodevnet/iot-ml-deployment.git
Run the IOTLMLmodle python program to generate ML models. This will create 2 models that needs to be copied to IOXMLApp folder to create the package. Alternatively you could use the prebuild models 'iotmodel.pkl or iotmodel2.pkl'
cd IOTMLmodel
python3 iot_ml_model.py
Build a docker image ,create a package and deploy the package as follows
Build docker image
sudo docker build -t iox-mldeploy-test .
Check built images
sudo docker images
Create a package for deployment
sudo ioxclient docker package iox-mldeploy-test:latest .
Further reference https://developer.cisco.com/learning/modules/iox-basic/iot-iox-app-docker/step/10
Deploy IOXApp for Docker
With the IOT ML docker image for IOX is built and connection to sandbox is established, next step is to deploy to IOXGateway.
More details on deployment refer to
https://developer.cisco.com/learning/modules/iox-basic/iot-iox-app-docker/step/11
https://developer.cisco.com/learning/modules/iox-basic/iot-iox-app-docker/step/12
Sample rest client application sends the data selected in 'sample_data.py'
python3 iotclientapp.py
1.Sample output for single variable ML Model i.e, iotmodel.pkl
2.Sample output for multiple categorical variable ML Model i.e, iotmodel2.pkl
Previous IOx labs needed to complete this lab
You will need to have completed the learning the following labs:
You should have a basic understanding on how to build and run a docker application.
To create a Docker image and push it to the Docker Hub, you will need the correct Docker tools for your platform which are available at https://www.docker.com/products/overview.
Download and install the correct version for your operating system.
This lab has instructions for using a docker container that sets up a web service you can access from your browser. The web service is a browser based version of Visual Studio Code, developed by Coder Com (https://coder.com) and utilizes docker to run the service. Since it is Visual Studio Code, it it provides a text/code editor and comes pre-built with ioxclient and everything you need to build IOx applications. You will need the Docker Platform on your desktop or developer machine to run this environment.
To access the DevNet Sandbox, you will need to use the Cisco AnyConnect Client for Virtual Private Network (VPN) access to the IOx instance. If you need to install it, you can find it at this link.
Note: If you are working on a DevNet Lab workstation, this software is already installed.
You will need the ioxclient to package and deploy the IOx Application. If you need to download it, you can find it at this link.
Note: If you are working on a DevNet Lab workstation or you are using the "IOx Dev Environment As A Service" container, this software is already installed.
One way to get the application template code is to use git. We have the option to download the code, so this step is optional. If you are working on a DevNet Lab workstation, the git software is already installed. If you need to install it, you can find it at this link.
Note: You can verify the installation of git by opening a command prompt and running:
Additional Note: If you are working on a DevNet Lab workstation or you are using the "IOx Dev Environment As A Service" container, this software is already installed.
Once you have verified the prerequisites to complete this lab you will:
Owner
Contributors
Categories
Programming Languages
PythonLicense
Code Exchange Community
Get help, share code, and collaborate with other developers in the Code Exchange community.View Community