Modifies project to use cookicutter
@YanZhangADS Refactor of project using cookicutter
This commit is contained in:
Родитель
0a43371b08
Коммит
27a9d6f587
68
README.md
68
README.md
|
@ -1,11 +1,13 @@
|
|||
### Authors: Yan Zhang, Mathew Salvaris, and Fidan Boylu Uz
|
||||
[![Build Status](https://dev.azure.com/customai/AKSDeploymentTutorialAML/_apis/build/status/Microsoft.AKSDeploymentTutorialAML?branchName=master)](https://dev.azure.com/customai/AKSDeploymentTutorialAML/_build/latest?definitionId=11&branchName=master)
|
||||
# Deploy Deep Learning CNN on Kubernetes Cluster with GPUs - AML version
|
||||
# Deploy Deep Learning CNN using Azure Machine Learning
|
||||
## Overview
|
||||
In this repository there are a number of tutorials in Jupyter notebooks that have step-by-step instructions on how to deploy a pretrained deep learning model on a GPU enabled Kubernetes cluster throught Azure Machine Learning (AML). The tutorials cover how to deploy models from the following deep learning frameworks:
|
||||
In this repository there are a number of tutorials in Jupyter notebooks that have step-by-step instructions on how to deploy a pretrained deep learning model on a GPU enabled Kubernetes cluster throught Azure Machine Learning (AML). The tutorials cover how to deploy models from the following deep learning frameworks on specific deployment target:
|
||||
|
||||
* [Keras (TensorFlow backend)](Keras_Tensorflow)
|
||||
* [Pytorch](Pytorch) (coming soon)
|
||||
* Keras (TensorFlow backend)
|
||||
- [Azure Kubernetes Service (AKS) Cluster with GPUs](./{{cookiecutter.project_name}}/Keras_Tensorflow/aks)
|
||||
- [Azure IoT Edge](./{{cookiecutter.project_name}}/Keras_Tensorflow/iotedge)
|
||||
* [Pytorch](./{{cookiecutter.project_name}}/Pytorch) (coming soon)
|
||||
|
||||
![alt text](static/example.png "Example Classification")
|
||||
|
||||
|
@ -14,17 +16,21 @@ In this repository there are a number of tutorials in Jupyter notebooks that hav
|
|||
* Model development where we load the pretrained model and test it by using it to score images
|
||||
* Develop the API that will call our model
|
||||
* Building the Docker Image with our REST API and model and testing the image
|
||||
* Creating our Kubernetes cluster and deploying our application to it
|
||||
* Testing the deployed model
|
||||
* Testing the throughput of our model
|
||||
* Cleaning up resources
|
||||
* AKS option
|
||||
* Creating our Kubernetes cluster and deploying our application to it
|
||||
* Testing the deployed model
|
||||
* Testing the throughput of our model
|
||||
* Cleaning up resources
|
||||
* IOT Edge option
|
||||
* Creating IoT hub and IoT Edge device identity, configuring the physical IOT Edge device, and deploying our application to it
|
||||
* Cleaning up resources
|
||||
|
||||
## Design
|
||||
|
||||
The application we will develop is a simple image classification service, where we will submit an image and get back what class the image belongs to. The application flow for the deep learning model is as follows:
|
||||
1) Deep learning model is registered to AML model registry.
|
||||
2) AML creates a docker image including the model and scoring script.
|
||||
3) AML deploys the scoring image on Azure Kubernetes Service (AKS) as a web service.
|
||||
3) AML deploys the scoring image on the chosen deployment compute target (AKS or IoT Edge) as a web service.
|
||||
4) The client sends a HTTP POST request with the encoded image data.
|
||||
5) The web service created by AML preprocesses the image data and sends it to the model for scoring.
|
||||
6) The predicted categories with their scores are then returned to the client.
|
||||
|
@ -36,11 +42,47 @@ The application we will develop is a simple image classification service, where
|
|||
|
||||
|
||||
|
||||
## Setup
|
||||
Please find out the Prerequisites and Setup procedures for different networks:
|
||||
# Getting Started
|
||||
|
||||
* [Keras (TensorFlow backend)](Keras_Tensorflow)
|
||||
* [Pytorch](Pytorch) (coming soon)
|
||||
To get started with the tutorial, please proceed with following steps **in sequential order**.
|
||||
|
||||
* [Prerequisites](#prerequisites)
|
||||
* [Setup](#setup)
|
||||
|
||||
|
||||
<a id='prerequisites'></a>
|
||||
## Prerequisites
|
||||
1. Linux (x64) with GPU enabled.
|
||||
2. [Anaconda Python](https://www.anaconda.com/download)
|
||||
3. [Docker](https://docs.docker.com/v17.12/install/linux/docker-ee/ubuntu) installed.
|
||||
4. [Azure account](https://azure.microsoft.com).
|
||||
|
||||
The tutorial was developed on an [Azure Ubuntu
|
||||
DSVM](https://docs.microsoft.com/en-us/azure/machine-learning/data-science-virtual-machine/dsvm-ubuntu-intro),
|
||||
which addresses the first three prerequisites.
|
||||
|
||||
<a id='setup'></a>
|
||||
## Setup
|
||||
To set up your environment to run these notebooks, please follow these steps.
|
||||
1. Create a _Linux_ Ubuntu DSVM (NC6 or above to use GPU).
|
||||
|
||||
2. Install [cookiecutter](https://cookiecutter.readthedocs.io/en/latest/installation.html), a tool creates projects from project templates.
|
||||
```bash
|
||||
pip install cookiecutter
|
||||
```
|
||||
|
||||
3. Clone and choose a specific framework and deployment option for this repository. You will obtain a repository tailored to your choice of framework and deployment compute target.
|
||||
```bash
|
||||
cookiecutter https://github.com/Microsoft/AKSDeploymentTutorialAML.git
|
||||
```
|
||||
You will be asked to choose or enter information such as *framework*, *project name*, *subsciption id*, *resource group*, etc. in an interactive way. If a dafault value is provided, you can press *Enter* to accept the default value and continue or enter value of your choice. For example, if you want to learn how to deploy deep learning model on AKS Cluster using Keras, you should have values "keras" as the value for variable *framework* and "aks" for variable *deployment_type*. Instead, if you want to learn deploying deep learning model on IoT Edge, you should select "iotedge" for variable *deployment_type*.
|
||||
|
||||
You must provide a value for "subscription_id", otherwise the project will fail with the error "ERROR: The subscription id is missing, please enter a valid subscription id" after all the questions are asked. The full list of questions can be found in [cookiecutter.json](./cookiecutter.json) file.
|
||||
|
||||
Please make sure all entered information are correct, as these information are used to customize the content of your repo.
|
||||
|
||||
|
||||
4. With the generation of the project custom readmes will be created based on [aks-keras](./{{cookiecutter.project_name}}/Keras_Tensorflow/aks/README.md) or [iotedge-keras](./{{cookiecutter.project_name}}/Keras_Tensorflow/iotedge/README.md). Go find a README.md file in your project directory and proceed with instructions specified in it.
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -22,69 +22,102 @@ jobs:
|
|||
displayName: 'Builds source for AKSDeploymentTutorialAML/Keras_Tensorflow'
|
||||
|
||||
- bash: |
|
||||
cd Keras_Tensorflow
|
||||
echo $(pwd)
|
||||
cd {{cookiecutter.project_template}}/Keras_Tensorflow
|
||||
conda env create -f environment.yml
|
||||
source activate aks_deployment_aml
|
||||
source activate deployment_aml
|
||||
conda env list
|
||||
echo Docker Setup
|
||||
#sudo usermod -aG docker $USER
|
||||
echo Login Azure Account
|
||||
az login -t $(sptenent) --service-principal -u $(spidentity) --password $(spsecret)
|
||||
az account set --subscription $(subscriptionid)
|
||||
displayName: 'Build Configuration'
|
||||
|
||||
- bash: |
|
||||
source activate aks_deployment_aml
|
||||
cd Keras_Tensorflow
|
||||
papermill 00_AMLSetup.ipynb 00_AMLSetup_output.ipynb --log-output --no-progress-bar -k python3 -p resource_group $(azureresourcegroup) -p workspace_name $(workspacename) -p workspace_region $(azureregion) -p subscription_id $(subscriptionid) -p image_name 'modelimg' -p aks_name 'aksdeployamlaks' -p aks_service_name 'aksamlsvc' -p aks_location $(azureregion)
|
||||
source activate deployment_aml
|
||||
cd {{cookiecutter.project_template}}/Keras_Tensorflow
|
||||
papermill 00_AMLSetup.ipynb 00_AMLSetup_output.ipynb \
|
||||
--log-output \
|
||||
--no-progress-bar \
|
||||
-k python3 \
|
||||
-p resource_group $(azureresourcegroup) \
|
||||
-p workspace_name $(workspacename) \
|
||||
-p workspace_region $(azureregion) \
|
||||
-p subscription_id $(subscriptionid) \
|
||||
-p image_name 'modelimg' \
|
||||
-p aks_name 'aksdeployamlaks' \
|
||||
-p aks_service_name 'aksamlsvc' \
|
||||
-p aks_location $(azureregion) \
|
||||
displayName : '00_AMLSetup.ipynb'
|
||||
|
||||
- bash: |
|
||||
source activate aks_deployment_aml
|
||||
cd Keras_Tensorflow
|
||||
source activate deployment_aml
|
||||
cd {{cookiecutter.project_template}}/Keras_Tensorflow
|
||||
papermill 01_DevelopModel.ipynb 01_DevelopModel_output.ipynb --log-output --no-progress-bar -k python3
|
||||
displayName : '01_DevelopModel.ipynb'
|
||||
|
||||
- bash: |
|
||||
source activate aks_deployment_aml
|
||||
cd Keras_Tensorflow
|
||||
source activate deployment_aml
|
||||
cd {{cookiecutter.project_template}}/Keras_Tensorflow
|
||||
papermill 02_DevelopModelDriver.ipynb 02_DevelopModelDriver_output.ipynb --log-output --no-progress-bar -k python3
|
||||
displayName : '02_DevelopModelDriver.ipynb'
|
||||
|
||||
- bash: |
|
||||
source activate aks_deployment_aml
|
||||
cd Keras_Tensorflow
|
||||
source activate deployment_aml
|
||||
cd {{cookiecutter.project_template}}/Keras_Tensorflow
|
||||
papermill 03_BuildImage.ipynb 03_BuildImage_output.ipynb --log-output --no-progress-bar -k python3
|
||||
displayName : '03_BuildImage.ipynb'
|
||||
|
||||
- bash: |
|
||||
source activate aks_deployment_aml
|
||||
cd Keras_Tensorflow
|
||||
source activate deployment_aml
|
||||
cd {{cookiecutter.project_template}}/Keras_Tensorflow/aks
|
||||
papermill 04_DeployOnAKS.ipynb 04_DeployOnAKS_output.ipynb --log-output --no-progress-bar -k python3
|
||||
displayName : '04_DeployOnAKS.ipynb'
|
||||
|
||||
- bash: |
|
||||
source activate aks_deployment_aml
|
||||
cd Keras_Tensorflow
|
||||
source activate deployment_aml
|
||||
cd {{cookiecutter.project_template}}/Keras_Tensorflow/aks
|
||||
papermill 05_TestWebApp.ipynb 05_TestWebApp_output.ipynb --log-output --no-progress-bar -k python3
|
||||
displayName : '05_TestWebApp.ipynb'
|
||||
|
||||
- bash: |
|
||||
source activate aks_deployment_aml
|
||||
cd Keras_Tensorflow
|
||||
source activate deployment_aml
|
||||
cd {{cookiecutter.project_template}}/Keras_Tensorflow/aks
|
||||
papermill 06_SpeedTestWebApp.ipynb 06_SpeedTestWebApp_output.ipynb --log-output --no-progress-bar -k python3
|
||||
displayName : '06_SpeedTestWebApp.ipynb'
|
||||
|
||||
- bash: |
|
||||
source activate aks_deployment_aml
|
||||
cd Keras_Tensorflow
|
||||
source activate deployment_aml
|
||||
export PYTHONPATh=$(pwd)/{{cookiecutter.project_template}}/Keras_Tensorflow:${PYTHONPATH}
|
||||
cd {{cookiecutter.project_template}}/Keras_Tensorflow/iotedge
|
||||
papermill 04_DeployOnIOTedge.ipynb 04_DeployOnIOTedge_output.ipynb \
|
||||
--log-output \
|
||||
--no-progress-bar \
|
||||
-k python3 \
|
||||
-p iot_hub_name fstlstnameiothub \
|
||||
-p device_id mygpudevice \
|
||||
-p module_name mygpumodule
|
||||
displayName: '04_DeployOnIOTedge.ipynb'
|
||||
|
||||
- bash: |
|
||||
source activate deployment_aml
|
||||
cd {{cookiecutter.project_template}}/Keras_Tensorflow/aks
|
||||
papermill 07_TearDown.ipynb 07_TearDown_output.ipynb --log-output --no-progress-bar -k python3
|
||||
displayName : '07_TearDown.ipynb'
|
||||
|
||||
- bash: |
|
||||
source activate deployment_aml
|
||||
export PYTHONPATh=$(pwd)/{{cookiecutter.project_template}}/Keras_Tensorflow:${PYTHONPATH}
|
||||
cd {{cookiecutter.project_template}}/Keras_Tensorflow/iotedge
|
||||
papermill 05_TearDown.ipynb 05_TearDown_output.ipynb \
|
||||
--log-output \
|
||||
--no-progress-bar \
|
||||
-k python3
|
||||
displayName: '05_TearDown.ipynb'
|
||||
|
||||
- bash: |
|
||||
echo Remove All Docker Containers
|
||||
#docker stop $(docker ps -a -q)
|
||||
#docker rm $(docker ps -a -q)
|
||||
docker stop $(docker ps -a -q)
|
||||
docker rm $(docker ps -a -q)
|
||||
|
||||
echo Remove Conda Environment
|
||||
conda remove -n aks_deployment_aml --all -q --force -y
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
{
|
||||
"framework":"keras",
|
||||
"project_name":"dlmodeldeploy",
|
||||
"subscription_id": "",
|
||||
"resource_group": "aksdeploykerasrg",
|
||||
"workspace_name": "workspace",
|
||||
"workspace_region": [
|
||||
"eastus",
|
||||
"eastus2"
|
||||
],
|
||||
"image_name": "kerasimage",
|
||||
"deployment_type": [
|
||||
"aks",
|
||||
"iotedge"
|
||||
]
|
||||
}
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
import os
|
||||
import shutil
|
||||
|
||||
PROJECT_DIRECTORY = os.path.realpath(os.path.curdir)
|
||||
|
||||
|
||||
def remove_file(filepath):
|
||||
os.remove(os.path.join(PROJECT_DIRECTORY, filepath))
|
||||
|
||||
|
||||
def remove_dir(dirpath):
|
||||
shutil.rmtree(os.path.join(PROJECT_DIRECTORY, dirpath))
|
||||
|
||||
|
||||
def move_files(parentdir, subdir):
|
||||
root = os.path.join(PROJECT_DIRECTORY, parentdir)
|
||||
for filename in os.listdir(os.path.join(root, subdir)):
|
||||
shutil.move(os.path.join(root, subdir, filename), os.path.join(root, filename))
|
||||
os.rmdir(os.path.join(root, subdir))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
if "{{ cookiecutter.framework }}" == "keras":
|
||||
remove_dir("./Pytorch")
|
||||
|
||||
if "{{ cookiecutter.deployment_type }}" == "aks":
|
||||
remove_dir("./Keras_Tensorflow/iotedge")
|
||||
move_files("./Keras_Tensorflow", "./aks")
|
||||
|
||||
if "{{ cookiecutter.deployment_type }}" == "iotedge":
|
||||
remove_dir("./Keras_Tensorflow/aks")
|
||||
move_files("./Keras_Tensorflow", "./iotedge")
|
||||
|
||||
else:
|
||||
remove_dir("./Keras_Tensorflow")
|
|
@ -0,0 +1,51 @@
|
|||
import re
|
||||
import sys
|
||||
|
||||
|
||||
MODULE_REGEX = r"^[_a-zA-Z][_a-zA-Z0-9]+$"
|
||||
|
||||
|
||||
def check_module(module_name):
|
||||
if not re.match(MODULE_REGEX, module_name):
|
||||
print(
|
||||
"ERROR: The project slug {} is not a valid Python module name. Please do not use a - and use _ instead".format(
|
||||
module_name
|
||||
)
|
||||
)
|
||||
|
||||
# Exit to cancel project
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
def check_sub_id(sub_id):
|
||||
if len(sub_id) == 0:
|
||||
print(
|
||||
"ERROR: The subscription id is missing, please enter a valid subscription id slug"
|
||||
)
|
||||
|
||||
# Exit to cancel project
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
def check_image_name(image_name):
|
||||
if "_" in image_name:
|
||||
print(
|
||||
"ERROR: The image name must not have underscores in it {}".format(
|
||||
image_name
|
||||
)
|
||||
)
|
||||
|
||||
# Exit to cancel project
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
check_module("{{cookiecutter.project_name}}")
|
||||
check_sub_id("{{cookiecutter.subscription_id}}")
|
||||
check_image_name("{{cookiecutter.image_name}}")
|
||||
print("All checks passed")
|
||||
if "{{ cookiecutter.deployment_type }}" == "aks":
|
||||
print("Creating AKS project...")
|
||||
|
||||
if "{{ cookiecutter.deployment_type }}" == "iotedge":
|
||||
print("Creating IOT Edge project...")
|
|
@ -102,17 +102,17 @@
|
|||
"outputs": [],
|
||||
"source": [
|
||||
"# Azure resources\n",
|
||||
"subscription_id = \"<YOUR_SUBSCRIPTION_ID>\"\n",
|
||||
"resource_group = \"<YOUR_RESOURCE_GROUP>\" # e.g. resource_group = 'myamlrg'\n",
|
||||
"workspace_name = \"<YOUR_WORKSPACE_NAME>\" # e.g. workspace_name = 'myamlworkspace'\n",
|
||||
"workspace_region = \"<YOUR_WORKSPACE_REGION>\" # e.g. workspace_region = 'eastus2'\n",
|
||||
"subscription_id = \"{{cookiecutter.subscription_id}}\"\n",
|
||||
"resource_group = \"{{cookiecutter.resource_group}}\" \n",
|
||||
"workspace_name = \"{{cookiecutter.workspace_name}}\" \n",
|
||||
"workspace_region = \"{{cookiecutter.workspace_region}}\" # e.g. workspace_region = \"{{cookiecutter.workspace_region}}\"\n",
|
||||
"\n",
|
||||
"# Docker image and Azure Kubernetes Service (AKS) Cluster - deployment compute\n",
|
||||
"image_name = (\n",
|
||||
" \"<YOUR_IMAGE_NAME>\"\n",
|
||||
") # e.g. image_name = \"image1 (avoid underscore in names)\"\n",
|
||||
" \"{{cookiecutter.image_name}}\"\n",
|
||||
") # e.g. image_name = \"{{cookiecutter.image_name}} (avoid underscore in names)\"\n",
|
||||
"aks_name = \"<YOUR_AKS_NAME>\" # e.g. aks_name = \"my-aks-gpu1\"\n",
|
||||
"aks_location = \"<YOUR_AKS_LOCATION>\" # e.g. aks_location = \"eastus\"\n",
|
||||
"aks_location = \"<YOUR_AKS_LOCATION>\" # e.g. aks_location = \"{{cookiecutter.workspace_region}}\"\n",
|
||||
"aks_service_name = (\n",
|
||||
" \"<YOUR_AKS_SERVICE_NAME>\"\n",
|
||||
") # e.g. aks_service_name =\"my-aks-service-1\""
|
||||
|
@ -223,7 +223,7 @@
|
|||
"formats": "ipynb"
|
||||
},
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3",
|
||||
"display_name": "Python [default]",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
|
@ -237,7 +237,7 @@
|
|||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.6.8"
|
||||
"version": "3.5.5"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
|
@ -11,9 +11,9 @@ Usage:
|
|||
make clean delete env and remove files
|
||||
endef
|
||||
export PROJECT_HELP_MSG
|
||||
|
||||
|
||||
include .dev_env
|
||||
env_location=.dev_env
|
||||
PWD:=$(shell pwd)
|
||||
include ${env_location}
|
||||
|
||||
|
||||
help:
|
||||
|
@ -21,7 +21,7 @@ help:
|
|||
|
||||
|
||||
test: setup test-notebook1 test-notebook2 test-notebook3 test-notebook4 test-notebook5 test-notebook6 test-notebook7 \
|
||||
test-notebook8
|
||||
test-notebook-iot1 test-notebook8 test-notebook-iot2
|
||||
@echo All Notebooks Passed
|
||||
|
||||
setup:
|
||||
|
@ -36,7 +36,7 @@ endif
|
|||
|
||||
|
||||
test-notebook1:
|
||||
source activate aks_deployment_aml
|
||||
source activate deployment_aml
|
||||
@echo Testing 00_AMLSetup.ipynb
|
||||
papermill 00_AMLSetup.ipynb test.ipynb \
|
||||
--log-output \
|
||||
|
@ -52,7 +52,7 @@ test-notebook1:
|
|||
-p aks_service_name ${AKS_SERVICE_NAME}
|
||||
|
||||
test-notebook2:
|
||||
source activate aks_deployment_aml
|
||||
source activate deployment_aml
|
||||
@echo Testing 01_DevelopModel.ipynb
|
||||
papermill 01_DevelopModel.ipynb test.ipynb \
|
||||
--log-output \
|
||||
|
@ -60,7 +60,7 @@ test-notebook2:
|
|||
-k python3
|
||||
|
||||
test-notebook3:
|
||||
source activate aks_deployment_aml
|
||||
source activate deployment_aml
|
||||
@echo Testing 02_DevelopModelDriver.ipynb
|
||||
papermill 02_DevelopModelDriver.ipynb test.ipynb \
|
||||
--log-output \
|
||||
|
@ -68,7 +68,7 @@ test-notebook3:
|
|||
-k python3
|
||||
|
||||
test-notebook4:
|
||||
source activate aks_deployment_aml
|
||||
source activate deployment_aml
|
||||
@echo Testing 03_BuildImage.ipynb
|
||||
papermill 03_BuildImage.ipynb test.ipynb \
|
||||
--log-output \
|
||||
|
@ -76,42 +76,77 @@ test-notebook4:
|
|||
-k python3
|
||||
|
||||
test-notebook5:
|
||||
source activate aks_deployment_aml
|
||||
source activate deployment_aml
|
||||
@echo Testing 04_DeployOnAKS.ipynb
|
||||
papermill 04_DeployOnAKS.ipynb test.ipynb \
|
||||
papermill aks/04_DeployOnAKS.ipynb test.ipynb \
|
||||
--log-output \
|
||||
--no-progress-bar \
|
||||
-k python3
|
||||
|
||||
test-notebook6:
|
||||
source activate aks_deployment_aml
|
||||
source activate deployment_aml
|
||||
@echo Testing 05_TestWebApp.ipynb
|
||||
papermill 05_TestWebApp.ipynb test.ipynb \
|
||||
papermill aks/05_TestWebApp.ipynb test.ipynb \
|
||||
--log-output \
|
||||
--no-progress-bar \
|
||||
-k python3
|
||||
|
||||
test-notebook7:
|
||||
source activate aks_deployment_aml
|
||||
source activate deployment_aml
|
||||
@echo Testing 06_SpeedTestWebApp.ipynb
|
||||
papermill 06_SpeedTestWebApp.ipynb test.ipynb \
|
||||
papermill aks/06_SpeedTestWebApp.ipynb test.ipynb \
|
||||
--log-output \
|
||||
--no-progress-bar \
|
||||
-k python3
|
||||
|
||||
test-notebook-iot1:
|
||||
source activate deployment_aml
|
||||
@echo Testing 04_DeployOnIOTedge.ipynb
|
||||
export PYTHONPATH=${PWD}:${PYTHONPATH}
|
||||
cd iotedge
|
||||
papermill 04_DeployOnIOTedge.ipynb test.ipynb \
|
||||
--log-output \
|
||||
--no-progress-bar \
|
||||
-k python3 \
|
||||
-p iot_hub_name fstlstnameiothub \
|
||||
-p device_id mygpudevice \
|
||||
-p module_name mygpumodule
|
||||
|
||||
test-notebook8:
|
||||
source activate aks_deployment_aml
|
||||
source activate deployment_aml
|
||||
@echo Testing 07_TearDown.ipynb
|
||||
papermill 07_TearDown.ipynb test.ipynb \
|
||||
papermill aks/07_TearDown.ipynb test.ipynb \
|
||||
--log-output \
|
||||
--no-progress-bar \
|
||||
-k python3
|
||||
|
||||
test-notebook-iot2:
|
||||
source activate deployment_aml
|
||||
@echo Testing 05_TearDown.ipynb
|
||||
export PYTHONPATH=${PWD}:${PYTHONPATH}
|
||||
papermill iotedge/05_TearDown.ipynb test.ipynb \
|
||||
--log-output \
|
||||
--no-progress-bar \
|
||||
-k python3
|
||||
|
||||
|
||||
test-cookiecutter-aks:
|
||||
cookiecutter --no-input https://github.com/Microsoft/AKSDeploymentTutorialAML.git --checkout mat_yzhang_cc \
|
||||
subscription_id="${SUBSCRIPTION_ID}" \
|
||||
workspace_region=${WORKSPACE_REGION} \
|
||||
deployment_type="aks"
|
||||
|
||||
test-cookiecutter-iot:
|
||||
cookiecutter --no-input https://github.com/Microsoft/AKSDeploymentTutorialAML.git --checkout mat_yzhang_cc \
|
||||
subscription_id=${SUBSCRIPTION_ID} \
|
||||
workspace_region=${WORKSPACE_REGION} \
|
||||
deployment_type="iotedge"
|
||||
|
||||
remove-notebook:
|
||||
rm -f test.ipynb
|
||||
|
||||
clean: remove-notebook
|
||||
conda remove --name aks_deployment_aml -y --all
|
||||
conda remove --name deployment_aml -y --all
|
||||
rm -rf aml_config
|
||||
rm -rf __pycache__
|
||||
rm -rf .ipynb_checkpoints
|
||||
|
@ -120,11 +155,11 @@ clean: remove-notebook
|
|||
rm driver.py img_env.yml model_resnet_weights.h5
|
||||
|
||||
notebook:
|
||||
source activate aks_deployment_aml
|
||||
source activate deployment_aml
|
||||
jupyter notebook --port 9999 --ip 0.0.0.0 --no-browser
|
||||
|
||||
install-jupytext:
|
||||
source activate aks_deployment_aml
|
||||
source activate deployment_aml
|
||||
conda install -c conda-forge jupytext
|
||||
|
||||
convert-to-py:
|
||||
|
@ -140,4 +175,4 @@ remove-py:
|
|||
rm -r py_scripts
|
||||
|
||||
.PHONY: help test setup clean remove-notebook test-notebook1 test-notebook2 test-notebook3 test-notebook4 \
|
||||
test-notebook5 test-notebook6 test-notebook7 test-notebook8
|
||||
test-notebook5 test-notebook6 test-notebook7 test-notebook-iot test-notebook9
|
|
@ -217,7 +217,7 @@
|
|||
"cell_type": "code",
|
||||
"execution_count": 12,
|
||||
"metadata": {
|
||||
"lines_to_next_cell": 2
|
||||
"lines_to_next_cell": 2.0
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
|
@ -3,13 +3,12 @@
|
|||
To get started with the tutorial, please proceed with following steps **in sequential order**.
|
||||
|
||||
* [Prerequisites](#prerequisites)
|
||||
* [Setup](#setup)
|
||||
* [Steps](#steps)
|
||||
* [Cleaning up](#cleanup)
|
||||
|
||||
<a id='prerequisites'></a>
|
||||
## Prerequisites
|
||||
1. Linux(Ubuntu) with GPU enabled.
|
||||
1. Linux (x64) with GPU enabled.
|
||||
2. [Anaconda Python](https://www.anaconda.com/download)
|
||||
3. [Docker](https://docs.docker.com/v17.12/install/linux/docker-ee/ubuntu) installed.
|
||||
4. [Azure account](https://azure.microsoft.com).
|
||||
|
@ -18,47 +17,41 @@ The tutorial was developed on an [Azure Ubuntu
|
|||
DSVM](https://docs.microsoft.com/en-us/azure/machine-learning/data-science-virtual-machine/dsvm-ubuntu-intro),
|
||||
which addresses the first three prerequisites.
|
||||
|
||||
<a id='setup'></a>
|
||||
## Setup
|
||||
To set up your environment to run these notebooks, please follow these steps. They setup the notebooks to use Docker and Azure seamlessly.
|
||||
1. Create a _Linux_ DSVM (NC6 or above to use GPU).
|
||||
2. Clone, fork, or download the zip file for this repository:
|
||||
```
|
||||
git clone https://github.com/Microsoft/AKSDeploymentTutorialAML.git
|
||||
```
|
||||
3. Add your user to the docker group (after executing this command, exit and start a new bash shell):
|
||||
<a id='steps'></a>
|
||||
## Steps
|
||||
Please follow these steps to set up your environment and run notebooks. They setup the notebooks to use Docker and Azure seamlessly.
|
||||
|
||||
1. Add your user to the docker group (after executing this command, exit and start a new bash shell):
|
||||
```
|
||||
sudo usermod -aG docker $USER
|
||||
```
|
||||
To verify whether you have correct configuration, try executing `docker ps` command. You should not get `permission denied` errors.
|
||||
|
||||
4. Navigate to _./AKSDeploymentTutorial\_AML/Keras\_Tensorflow_ directory
|
||||
2. Navigate to the directory which is the framework you have chosen (e.g. Keras_Tensorflow).
|
||||
|
||||
5. Create the Python virtual environment using the environment.yml:
|
||||
3. Create the Python virtual environment using the environment.yml:
|
||||
```
|
||||
conda env create -f environment.yml
|
||||
```
|
||||
6. Activate the virtual environment:
|
||||
4. Activate the virtual environment:
|
||||
```
|
||||
source activate aks_deployment_aml
|
||||
source activate deployment_aml
|
||||
```
|
||||
7. Login to Azure:
|
||||
5. Login to Azure:
|
||||
```
|
||||
az login
|
||||
```
|
||||
8. If you have more than one Azure subscription, select it:
|
||||
6. If you have more than one Azure subscription, select it:
|
||||
```
|
||||
az account set --subscription <Your Azure Subscription>
|
||||
```
|
||||
9. Start the Jupyter notebook server in the virtual environment:
|
||||
7. Start the Jupyter notebook server in the virtual environment:
|
||||
```
|
||||
jupyter notebook
|
||||
```
|
||||
10. Select correct kernel: set the kernel to be `Python [conda env:aks_deployment_aml]`(or `Python 3` if that option does not show).
|
||||
8. Select correct kernel: set the kernel to be `Python [conda env: deployment_aml]`(or `Python 3` if that option does not show).
|
||||
|
||||
<a id='steps'></a>
|
||||
## Steps
|
||||
After following the setup instructions above, run the Jupyter notebooks in order starting with the first notebook [00_AMLSetup.ipynb](./00_AMLSetup.ipynb).
|
||||
9. After following the setup instructions above, run the Jupyter notebooks in order starting with the first notebook [00_AMLSetup.ipynb](./00_AMLSetup.ipynb).
|
||||
|
||||
<a id='cleanup'></a>
|
||||
## Cleaning up
|
|
@ -1,4 +1,4 @@
|
|||
name: aks_deployment_aml
|
||||
name: deployment_aml
|
||||
dependencies:
|
||||
# The python interpreter version.
|
||||
# Currently Azure ML only supports 3.5.2 and later.
|
Различия файлов скрыты, потому что одна или несколько строк слишком длинны
|
@ -0,0 +1,133 @@
|
|||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# Tear it all down\n",
|
||||
"Once you are done with your task you can use the following commands to clean up resources."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from azureml.core import Workspace\n",
|
||||
"from dotenv import set_key, get_key, find_dotenv\n",
|
||||
"from testing_utilities import get_auth"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"ws = Workspace.from_config(auth=get_auth())\n",
|
||||
"print(ws.name, ws.resource_group, ws.location, ws.subscription_id, sep=\"\\n\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"env_path = find_dotenv(raise_error_if_not_found=True)\n",
|
||||
"resource_group = get_key(env_path, 'resource_group')\n",
|
||||
"iot_hub_name = get_key(env_path, 'iot_hub_name')"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"!sudo systemctl stop iotedge"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"!sudo apt-get remove -y iotedge"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Delete the IoT hub. This step may take a few minutes."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Delete IoT hub\n",
|
||||
"cmd_results = !az iot hub show -n $iot_hub_name -g $resource_group\n",
|
||||
"if 'Not Found' not in cmd_results[0]:\n",
|
||||
" !az iot hub delete --name $iot_hub_name --resource-group $resource_group"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Finally, you should delete the resource group. This also deletes the IoT hub and can be used instead of the above command if the resource group is only used for this purpose."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"cmd_results = !az group show -n $resource_group -o tsv\n",
|
||||
"if \"not be found\" not in cmd_results[0]:\n",
|
||||
" !az group delete --name $resource_group -y"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"!docker stop $(docker ps -qa)\n",
|
||||
"!docker rm $(docker ps -qa)"
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"jupytext": {
|
||||
"formats": "ipynb"
|
||||
},
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
"language_info": {
|
||||
"codemirror_mode": {
|
||||
"name": "ipython",
|
||||
"version": 3
|
||||
},
|
||||
"file_extension": ".py",
|
||||
"mimetype": "text/x-python",
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.6.8"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 2
|
||||
}
|
|
@ -0,0 +1,67 @@
|
|||
{
|
||||
"modulesContent": {
|
||||
"$edgeAgent": {
|
||||
"properties.desired": {
|
||||
"schemaVersion": "1.0",
|
||||
"runtime": {
|
||||
"type": "docker",
|
||||
"settings": {
|
||||
"loggingOptions": "",
|
||||
"minDockerVersion": "v1.25",
|
||||
"registryCredentials": {
|
||||
"amlregistry": {
|
||||
"address": "__REGISTRY_NAME.azurecr.io",
|
||||
"password": "__REGISTRY_PASSWORD",
|
||||
"username": "__REGISTRY_USER_NAME"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"systemModules": {
|
||||
"edgeAgent": {
|
||||
"type": "docker",
|
||||
"settings": {
|
||||
"image": "mcr.microsoft.com/azureiotedge-agent:1.0",
|
||||
"createOptions": ""
|
||||
}
|
||||
},
|
||||
"edgeHub": {
|
||||
"type": "docker",
|
||||
"settings": {
|
||||
"image": "mcr.microsoft.com/azureiotedge-hub:1.0",
|
||||
"createOptions": "{\"HostConfig\":{\"PortBindings\":{\"8883/tcp\":[{\"HostPort\":\"8883\"}],\"443/tcp\":[{\"HostPort\":\"443\"}],\"5671/tcp\":[{\"HostPort\":\"5671\"}]}}}"
|
||||
},
|
||||
"status": "running",
|
||||
"restartPolicy": "always"
|
||||
}
|
||||
},
|
||||
"modules": {
|
||||
"__MODULE_NAME": {
|
||||
"type": "docker",
|
||||
"settings": {
|
||||
"image": "__REGISTRY_IMAGE_LOCATION",
|
||||
"createOptions": "{\"HostConfig\":{\"Runtime\":\"nvidia\",\"PortBindings\":{\"5001/tcp\":[{\"HostPort\":\"5001\"}]}}}"
|
||||
},
|
||||
"version": "1.0",
|
||||
"status": "running",
|
||||
"restartPolicy": "always"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"$edgeHub": {
|
||||
"properties.desired": {
|
||||
"schemaVersion": "1.0",
|
||||
"routes": {
|
||||
"route": "FROM /messages/* INTO $upstream"
|
||||
},
|
||||
"storeAndForwardConfiguration": {
|
||||
"timeToLiveSecs": 7200
|
||||
}
|
||||
}
|
||||
},
|
||||
"__MODULE_NAME": {
|
||||
"properties.desired": {}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,89 @@
|
|||
# Deploy Deep Learning CNN on IoT Edge - Keras
|
||||
|
||||
In this tutorial, we introduce how to deploy an ML/DL (machine learning/deep learning) module through [Azure IoT Edge](https://docs.microsoft.com/en-us/azure/iot-edge/how-iot-edge-works).
|
||||
|
||||
Azure IoT Edge is an Internet of Things (IoT) service that builds on top of Azure IoT Hub. It is a hybrid solution combining the benefits of the two scenarios: *IoT in the Cloud* and *IoT on the Edge*. This service is meant for customers who want to analyze data on devices, a.k.a. "at the edge", instead of in the cloud. By moving parts of your workload to the edge, your devices can spend less time sending messages to the cloud and react more quickly to changes in status. On the other hand, Azure IoT Hub provides centralized way to manage Azure IoT Edge devices, and make it easy to train ML models in the Cloud and deploy the trained models on the Edge devices.
|
||||
|
||||
In this example, we deploy a trained Keras (tensorflow) CNN model to the edge device. When the image data is generated from a process pipeline and fed into the edge device, the deployed model can make predictions right on the edge device without accessing to the cloud. Following diagram shows the major components of an Azure IoT edge device. Source code and full documentation are linked below.
|
||||
|
||||
<p align="center">
|
||||
<img src="azureiotedgeruntime.png" alt="logo" width="90%"/>
|
||||
</p>
|
||||
|
||||
We perform following steps for the deployment.
|
||||
|
||||
- Step 1: Build the trained ML/DL model into docker image. This image will be used to create a docker container running on the edge device.
|
||||
- Step 2: Provision and Configure IoT Edge Device
|
||||
- Step 3: Deploy ML/DL Module on IoT Edge Device
|
||||
- Step 4: Test ML/DL Module
|
||||
|
||||
|
||||
To get started with the tutorial, please proceed with following steps **in sequential order**.
|
||||
|
||||
* [Prerequisites](#prerequisites)
|
||||
* [Steps](#steps)
|
||||
* [Cleaning up](#cleanup)
|
||||
|
||||
<a id='prerequisites'></a>
|
||||
## Prerequisites
|
||||
1. Linux (x64) with GPU enabled.
|
||||
2. [Anaconda Python](https://www.anaconda.com/download)
|
||||
3. [Docker](https://docs.docker.com/v17.12/install/linux/docker-ee/ubuntu) installed.
|
||||
4. [Azure account](https://azure.microsoft.com).
|
||||
|
||||
The tutorial was developed on an [Azure Ubuntu
|
||||
DSVM](https://docs.microsoft.com/en-us/azure/machine-learning/data-science-virtual-machine/dsvm-ubuntu-intro),
|
||||
which addresses the first three prerequisites.
|
||||
|
||||
<a id='steps'></a>
|
||||
## Steps
|
||||
Please follow these steps to set up your environment and run notebooks. They setup the notebooks to use Docker and Azure seamlessly.
|
||||
|
||||
1. Add your user to the docker group (after executing this command, exit and start a new bash shell):
|
||||
```
|
||||
sudo usermod -aG docker $USER
|
||||
```
|
||||
To verify whether you have correct configuration, try executing `docker ps` command. You should not get `permission denied` errors.
|
||||
|
||||
2. Navigate to the directory which is the framework you have chosen (e.g. Keras_Tensorflow).
|
||||
|
||||
3. Create the Python virtual environment using the environment.yml:
|
||||
```
|
||||
conda env create -f environment.yml
|
||||
```
|
||||
4. Activate the virtual environment:
|
||||
```
|
||||
source activate deployment_aml
|
||||
```
|
||||
5. Login to Azure:
|
||||
```
|
||||
az login
|
||||
```
|
||||
6. If you have more than one Azure subscription, select it:
|
||||
```
|
||||
az account set --subscription <Your Azure Subscription>
|
||||
```
|
||||
7. Start the Jupyter notebook server in the virtual environment:
|
||||
```
|
||||
jupyter notebook
|
||||
```
|
||||
8. Select correct kernel: set the kernel to be `Python [conda env: deployment_aml]`(or `Python 3` if that option does not show).
|
||||
|
||||
9. After following the setup instructions above, run the Jupyter notebooks in order starting with the first notebook [00_AMLSetup.ipynb](./00_AMLSetup.ipynb).
|
||||
|
||||
<a id='cleanup'></a>
|
||||
## Cleaning up
|
||||
To remove the conda environment created see [here](https://conda.io/projects/continuumio-conda/en/latest/commands/remove.html). The [last Jupyter notebook](./05_TearDown.ipynb) also gives details on deleting Azure resources associated with this repository.
|
||||
|
||||
# Contributing
|
||||
This project welcomes contributions and suggestions. Most contributions require you to agree to a
|
||||
Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us
|
||||
the rights to use your contribution. For details, visit https://cla.microsoft.com.
|
||||
|
||||
When you submit a pull request, a CLA-bot will automatically determine whether you need to provide
|
||||
a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions
|
||||
provided by the bot. You will only need to do this once across all repositories using our CLA.
|
||||
|
||||
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
|
||||
For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or
|
||||
contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.
|
Двоичные данные
{{cookiecutter.project_name}}/Keras_Tensorflow/iotedge/azureiotedgeruntime.png
Normal file
Двоичные данные
{{cookiecutter.project_name}}/Keras_Tensorflow/iotedge/azureiotedgeruntime.png
Normal file
Двоичный файл не отображается.
После Ширина: | Высота: | Размер: 50 KiB |
|
@ -0,0 +1,53 @@
|
|||
|
||||
# Install the repository configuration. Replace <release> with 16.04 or 18.04 as appropriate for your release of Ubuntu
|
||||
curl https://packages.microsoft.com/config/ubuntu/__release/prod.list > ./microsoft-prod.list
|
||||
|
||||
# Copy the generated list
|
||||
sudo cp ./microsoft-prod.list /etc/apt/sources.list.d/
|
||||
|
||||
#Install Microsoft GPG public key
|
||||
curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.gpg
|
||||
sudo cp ./microsoft.gpg /etc/apt/trusted.gpg.d/
|
||||
|
||||
#################################################################################
|
||||
#Install the container runtime. It can be skipped if Docker is already installed
|
||||
|
||||
# Update the apt package index
|
||||
#sudo apt-get update
|
||||
|
||||
# Install the Moby engine.
|
||||
#sudo apt-get install moby-engine
|
||||
################################################################################
|
||||
|
||||
# Install the Azure IoT Edge Security Daemon
|
||||
# Perform apt update
|
||||
sudo apt-get update
|
||||
|
||||
# Install the Moby command-line interface (CLI). The CLI is useful for development but optional for production deployments.
|
||||
sudo apt-get install moby-cli
|
||||
|
||||
# Install the security daemon. The package is installed at /etc/iotedge/.
|
||||
sudo apt-get install iotedge -y --no-install-recommends
|
||||
################################################################################
|
||||
|
||||
#Configure the Azure IoT Edge Security
|
||||
# Manual provisioning IoT edge device
|
||||
sudo sed -i "s#\(device_connection_string: \).*#\1\"__device_connection_string\"#g" /etc/iotedge/config.yaml
|
||||
|
||||
############################################
|
||||
|
||||
# double check if the IP address of the docker0 interface is 172.17.01 by using ifconfig command
|
||||
sudo sed -i "s#\(management_uri: \).*#\1\"__management_uri\"#g" /etc/iotedge/config.yaml
|
||||
sudo sed -i "s#\(workload_uri: \).*#\1\"__workload_uri\"#g" /etc/iotedge/config.yaml
|
||||
|
||||
# restart the daemon
|
||||
sudo systemctl restart iotedge
|
||||
###########################################
|
||||
|
||||
# Verify successful installation
|
||||
|
||||
# check the status of the IoT Edge Daemon
|
||||
systemctl status iotedge
|
||||
|
||||
# Examine daemon logs
|
||||
journalctl -u iotedge --no-pager --no-full
|
Загрузка…
Ссылка в новой задаче