diff --git a/machine-learning-notebooks/gpu-accleration-onedge/img/conf_file_download.JPG b/machine-learning-notebooks/gpu-accleration-onedge/img/conf_file_download.JPG new file mode 100644 index 000000000..de0ae60f1 Binary files /dev/null and b/machine-learning-notebooks/gpu-accleration-onedge/img/conf_file_download.JPG differ diff --git a/machine-learning-notebooks/gpu-accleration-onedge/img/ml-flow-edge.png b/machine-learning-notebooks/gpu-accleration-onedge/img/ml-flow-edge.png new file mode 100644 index 000000000..6f9b1cc0f Binary files /dev/null and b/machine-learning-notebooks/gpu-accleration-onedge/img/ml-flow-edge.png differ diff --git a/machine-learning-notebooks/gpu-accleration-onedge/iotedge-tf-template-gpu.json b/machine-learning-notebooks/gpu-accleration-onedge/iotedge-tf-template-gpu.json new file mode 100644 index 000000000..1d535b329 --- /dev/null +++ b/machine-learning-notebooks/gpu-accleration-onedge/iotedge-tf-template-gpu.json @@ -0,0 +1,157 @@ +{ + + "modulesContent": { + + "$edgeAgent": { + + "properties.desired": { + + "schemaVersion": "1.0", + + "runtime": { + + "type": "docker", + + "settings": { + + "minDockerVersion": "v1.25", + + "loggingOptions": "", + + "registryCredentials": { + + "__REGISTRY_NAME": { + + "username": "__REGISTRY_USER_NAME", + + "password":"__REGISTRY_PASSWORD", + + "address":"__REGISTRY_NAME.azurecr.io" + + } + + } + + } + + }, + + "systemModules": { + + "edgeAgent": { + + "type": "docker", + + "settings": { + + "image": "mcr.microsoft.com/azureiotedge-agent:1.0", + + "createOptions": "{}", + + "env": { + + "UpstreamProtocol": { + + "value": "MQTT" + + } + + } + + } + + }, + + "edgeHub": { + + "type": "docker", + + "status": "running", + + "restartPolicy": "always", + + "settings": { + + "image": "mcr.microsoft.com/azureiotedge-hub:1.0", + + "createOptions": "{\"User\":\"root\",\"HostConfig\":{\"PortBindings\":{\"5671/tcp\":[{\"HostPort\":\"5671\"}], \"8883/tcp\":[{\"HostPort\":\"8883\"}],\"443/tcp\":[{\"HostPort\":\"443\"}]}}}", + + "env": { + + "UpstreamProtocol": { + + "value": "MQTT " + + } + + } + + } + + } + + }, + + "modules": { + + + "__MODULE_NAME": { + + "version": "1.0", + + "type": "docker", + + "status": "running", + + "restartPolicy": "always", + + "settings": { + + "image": "__REGISTRY_IMAGE_LOCATION", + + "createOptions": "{\"HostConfig\":{\"PortBindings\":{\"5001/tcp\":[{\"HostPort\":\"5001\"}], \"8883/tcp\":[{\"HostPort\":\"5002\"}],},\"runtime\":\"nvidia\"},\"WorkingDir\":\"/var/azureml-app\"}" + + + } + + } + + } + + } + + }, + + "$edgeHub": { + + "properties.desired": { + + "schemaVersion": "1.0", + + "routes": { + + + "machineLearningToIoTHub": "FROM /messages/modules/__MODULE_NAME/outputs/amlOutput INTO $upstream" + + }, + + "storeAndForwardConfiguration": { + + "timeToLiveSecs": 7200 + + } + + } + + }, + + + "__MODULE_NAME": { + + "properties.desired": {} + + } + + } + +} \ No newline at end of file diff --git a/machine-learning-notebooks/gpu-accleration-onedge/production-deploy-to-ase-gpu.ipynb b/machine-learning-notebooks/gpu-accleration-onedge/production-deploy-to-ase-gpu.ipynb new file mode 100644 index 000000000..489dc734e --- /dev/null +++ b/machine-learning-notebooks/gpu-accleration-onedge/production-deploy-to-ase-gpu.ipynb @@ -0,0 +1,1079 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Copyright (c) Microsoft Corporation. All rights reserved.\n", + "\n", + "Licensed under the MIT License." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "![Impressions](https://PixelServer20190423114238.azurewebsites.net/api/impressions/MachineLearningNotebooks/how-to-use-azureml/automated-machine-learning/production-deploy-to-aks-gpu/production-deploy-to-aks-gpu.png)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Deploying a ML model as web service on Azure Stack\n", + "This notebook shows the steps to : registering a model, creating an image, provisioning,deploying a service using Iot Edge on Azure Edge. ![aml-flow](img/ml-flow-edge.png)" + ] + }, + { + "cell_type": "code", + "execution_count": 44, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Requirement already up-to-date: azureml-sdk in /anaconda/envs/azureml_py36_automl/lib/python3.6/site-packages (1.12.0)\n", + "Requirement already satisfied, skipping upgrade: azureml-train~=1.12.0 in /anaconda/envs/azureml_py36_automl/lib/python3.6/site-packages (from azureml-sdk) (1.12.0)\n", + "Requirement already satisfied, skipping upgrade: azureml-core~=1.12.0 in /anaconda/envs/azureml_py36_automl/lib/python3.6/site-packages (from azureml-sdk) (1.12.0.post1)\n", + "Requirement already satisfied, skipping upgrade: azureml-pipeline~=1.12.0 in /anaconda/envs/azureml_py36_automl/lib/python3.6/site-packages (from azureml-sdk) (1.12.0)\n", + "Requirement already satisfied, skipping upgrade: azureml-train-automl-client~=1.12.0 in /anaconda/envs/azureml_py36_automl/lib/python3.6/site-packages (from azureml-sdk) (1.12.0.post1)\n", + "Requirement already satisfied, skipping upgrade: azureml-dataset-runtime[fuse]~=1.12.0 in /anaconda/envs/azureml_py36_automl/lib/python3.6/site-packages (from azureml-sdk) (1.12.0)\n", + "Requirement already satisfied, skipping upgrade: azureml-train-core~=1.12.0 in /anaconda/envs/azureml_py36_automl/lib/python3.6/site-packages (from azureml-train~=1.12.0->azureml-sdk) (1.12.0)\n", + "Requirement already satisfied, skipping upgrade: pyopenssl in /anaconda/envs/azureml_py36_automl/lib/python3.6/site-packages (from azureml-core~=1.12.0->azureml-sdk) (19.1.0)\n", + "Requirement already satisfied, skipping upgrade: requests>=2.19.1 in /anaconda/envs/azureml_py36_automl/lib/python3.6/site-packages (from azureml-core~=1.12.0->azureml-sdk) (2.22.0)\n", + "Requirement already satisfied, skipping upgrade: cryptography!=1.9,!=2.0.*,!=2.1.*,!=2.2.* in /anaconda/envs/azureml_py36_automl/lib/python3.6/site-packages (from azureml-core~=1.12.0->azureml-sdk) (2.8)\n", + "Requirement already satisfied, skipping upgrade: msrestazure>=0.4.33 in /anaconda/envs/azureml_py36_automl/lib/python3.6/site-packages (from azureml-core~=1.12.0->azureml-sdk) (0.6.2)\n", + "Requirement already satisfied, skipping upgrade: python-dateutil>=2.7.3 in /anaconda/envs/azureml_py36_automl/lib/python3.6/site-packages (from azureml-core~=1.12.0->azureml-sdk) (2.8.1)\n", + "Requirement already satisfied, skipping upgrade: jsonpickle in /anaconda/envs/azureml_py36_automl/lib/python3.6/site-packages (from azureml-core~=1.12.0->azureml-sdk) (1.2)\n", + "Requirement already satisfied, skipping upgrade: backports.tempfile in /anaconda/envs/azureml_py36_automl/lib/python3.6/site-packages (from azureml-core~=1.12.0->azureml-sdk) (1.0)\n", + "Requirement already satisfied, skipping upgrade: contextlib2 in /anaconda/envs/azureml_py36_automl/lib/python3.6/site-packages (from azureml-core~=1.12.0->azureml-sdk) (0.6.0.post1)\n", + "Requirement already satisfied, skipping upgrade: pathspec in /anaconda/envs/azureml_py36_automl/lib/python3.6/site-packages (from azureml-core~=1.12.0->azureml-sdk) (0.7.0)\n", + "Requirement already satisfied, skipping upgrade: azure-common>=1.1.12 in /anaconda/envs/azureml_py36_automl/lib/python3.6/site-packages (from azureml-core~=1.12.0->azureml-sdk) (1.1.24)\n", + "Requirement already satisfied, skipping upgrade: azure-mgmt-containerregistry>=2.0.0 in /anaconda/envs/azureml_py36_automl/lib/python3.6/site-packages (from azureml-core~=1.12.0->azureml-sdk) (2.8.0)\n", + "Requirement already satisfied, skipping upgrade: ruamel.yaml>=0.15.35 in /anaconda/envs/azureml_py36_automl/lib/python3.6/site-packages (from azureml-core~=1.12.0->azureml-sdk) (0.15.89)\n", + "Requirement already satisfied, skipping upgrade: docker in /anaconda/envs/azureml_py36_automl/lib/python3.6/site-packages (from azureml-core~=1.12.0->azureml-sdk) (4.1.0)\n", + "Requirement already satisfied, skipping upgrade: adal>=1.2.0 in /anaconda/envs/azureml_py36_automl/lib/python3.6/site-packages (from azureml-core~=1.12.0->azureml-sdk) (1.2.2)\n", + "Requirement already satisfied, skipping upgrade: SecretStorage in /anaconda/envs/azureml_py36_automl/lib/python3.6/site-packages (from azureml-core~=1.12.0->azureml-sdk) (3.1.2)\n", + "Requirement already satisfied, skipping upgrade: msrest>=0.5.1 in /anaconda/envs/azureml_py36_automl/lib/python3.6/site-packages (from azureml-core~=1.12.0->azureml-sdk) (0.6.11)\n", + "Requirement already satisfied, skipping upgrade: azure-mgmt-storage>=1.5.0 in /anaconda/envs/azureml_py36_automl/lib/python3.6/site-packages (from azureml-core~=1.12.0->azureml-sdk) (2.0.0)\n", + "Requirement already satisfied, skipping upgrade: jmespath in /anaconda/envs/azureml_py36_automl/lib/python3.6/site-packages (from azureml-core~=1.12.0->azureml-sdk) (0.9.4)\n", + "Requirement already satisfied, skipping upgrade: azure-mgmt-keyvault>=0.40.0 in /anaconda/envs/azureml_py36_automl/lib/python3.6/site-packages (from azureml-core~=1.12.0->azureml-sdk) (1.1.0)\n", + "Requirement already satisfied, skipping upgrade: azure-mgmt-resource>=1.2.1 in /anaconda/envs/azureml_py36_automl/lib/python3.6/site-packages (from azureml-core~=1.12.0->azureml-sdk) (2.2.0)\n", + "Requirement already satisfied, skipping upgrade: urllib3>=1.23 in /anaconda/envs/azureml_py36_automl/lib/python3.6/site-packages (from azureml-core~=1.12.0->azureml-sdk) (1.25.8)\n", + "Requirement already satisfied, skipping upgrade: azure-graphrbac>=0.40.0 in /anaconda/envs/azureml_py36_automl/lib/python3.6/site-packages (from azureml-core~=1.12.0->azureml-sdk) (0.40.0)\n", + "Requirement already satisfied, skipping upgrade: azure-mgmt-authorization>=0.40.0 in /anaconda/envs/azureml_py36_automl/lib/python3.6/site-packages (from azureml-core~=1.12.0->azureml-sdk) (0.50.0)\n", + "Requirement already satisfied, skipping upgrade: PyJWT in /anaconda/envs/azureml_py36_automl/lib/python3.6/site-packages (from azureml-core~=1.12.0->azureml-sdk) (1.7.1)\n", + "Requirement already satisfied, skipping upgrade: ndg-httpsclient in /anaconda/envs/azureml_py36_automl/lib/python3.6/site-packages (from azureml-core~=1.12.0->azureml-sdk) (0.5.1)\n", + "Requirement already satisfied, skipping upgrade: pytz in /anaconda/envs/azureml_py36_automl/lib/python3.6/site-packages (from azureml-core~=1.12.0->azureml-sdk) (2019.3)\n", + "Requirement already satisfied, skipping upgrade: azureml-pipeline-core~=1.12.0 in /anaconda/envs/azureml_py36_automl/lib/python3.6/site-packages (from azureml-pipeline~=1.12.0->azureml-sdk) (1.12.0)\n", + "Requirement already satisfied, skipping upgrade: azureml-pipeline-steps~=1.12.0 in /anaconda/envs/azureml_py36_automl/lib/python3.6/site-packages (from azureml-pipeline~=1.12.0->azureml-sdk) (1.12.0)\n", + "Requirement already satisfied, skipping upgrade: azureml-telemetry~=1.12.0 in /anaconda/envs/azureml_py36_automl/lib/python3.6/site-packages (from azureml-train-automl-client~=1.12.0->azureml-sdk) (1.12.0)\n", + "Requirement already satisfied, skipping upgrade: azureml-automl-core~=1.12.0 in /anaconda/envs/azureml_py36_automl/lib/python3.6/site-packages (from azureml-train-automl-client~=1.12.0->azureml-sdk) (1.12.0)\n", + "Requirement already satisfied, skipping upgrade: pyarrow<2.0.0,>=0.17.0 in /anaconda/envs/azureml_py36_automl/lib/python3.6/site-packages (from azureml-dataset-runtime[fuse]~=1.12.0->azureml-sdk) (1.0.0)\n", + "Requirement already satisfied, skipping upgrade: azureml-dataprep<2.1.0a,>=2.0.1a in /anaconda/envs/azureml_py36_automl/lib/python3.6/site-packages (from azureml-dataset-runtime[fuse]~=1.12.0->azureml-sdk) (2.0.7)\n", + "Requirement already satisfied, skipping upgrade: fusepy<4.0.0,>=3.0.1; extra == \"fuse\" in /anaconda/envs/azureml_py36_automl/lib/python3.6/site-packages (from azureml-dataset-runtime[fuse]~=1.12.0->azureml-sdk) (3.0.1)\n", + "Requirement already satisfied, skipping upgrade: azureml-train-restclients-hyperdrive~=1.12.0 in /anaconda/envs/azureml_py36_automl/lib/python3.6/site-packages (from azureml-train-core~=1.12.0->azureml-train~=1.12.0->azureml-sdk) (1.12.0)\n", + "Requirement already satisfied, skipping upgrade: six>=1.5.2 in /anaconda/envs/azureml_py36_automl/lib/python3.6/site-packages (from pyopenssl->azureml-core~=1.12.0->azureml-sdk) (1.14.0)\n", + "Requirement already satisfied, skipping upgrade: chardet<3.1.0,>=3.0.2 in /anaconda/envs/azureml_py36_automl/lib/python3.6/site-packages (from requests>=2.19.1->azureml-core~=1.12.0->azureml-sdk) (3.0.4)\n", + "Requirement already satisfied, skipping upgrade: idna<2.9,>=2.5 in /anaconda/envs/azureml_py36_automl/lib/python3.6/site-packages (from requests>=2.19.1->azureml-core~=1.12.0->azureml-sdk) (2.8)\n", + "Requirement already satisfied, skipping upgrade: certifi>=2017.4.17 in /anaconda/envs/azureml_py36_automl/lib/python3.6/site-packages (from requests>=2.19.1->azureml-core~=1.12.0->azureml-sdk) (2019.11.28)\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Requirement already satisfied, skipping upgrade: cffi!=1.11.3,>=1.8 in /anaconda/envs/azureml_py36_automl/lib/python3.6/site-packages (from cryptography!=1.9,!=2.0.*,!=2.1.*,!=2.2.*->azureml-core~=1.12.0->azureml-sdk) (1.13.2)\n", + "Requirement already satisfied, skipping upgrade: backports.weakref in /anaconda/envs/azureml_py36_automl/lib/python3.6/site-packages (from backports.tempfile->azureml-core~=1.12.0->azureml-sdk) (1.0.post1)\n", + "Requirement already satisfied, skipping upgrade: websocket-client>=0.32.0 in /anaconda/envs/azureml_py36_automl/lib/python3.6/site-packages (from docker->azureml-core~=1.12.0->azureml-sdk) (0.57.0)\n", + "Requirement already satisfied, skipping upgrade: jeepney>=0.4.2 in /anaconda/envs/azureml_py36_automl/lib/python3.6/site-packages (from SecretStorage->azureml-core~=1.12.0->azureml-sdk) (0.4.2)\n", + "Requirement already satisfied, skipping upgrade: isodate>=0.6.0 in /anaconda/envs/azureml_py36_automl/lib/python3.6/site-packages (from msrest>=0.5.1->azureml-core~=1.12.0->azureml-sdk) (0.6.0)\n", + "Requirement already satisfied, skipping upgrade: requests-oauthlib>=0.5.0 in /anaconda/envs/azureml_py36_automl/lib/python3.6/site-packages (from msrest>=0.5.1->azureml-core~=1.12.0->azureml-sdk) (1.3.0)\n", + "Requirement already satisfied, skipping upgrade: azure-mgmt-nspkg>=2.0.0 in /anaconda/envs/azureml_py36_automl/lib/python3.6/site-packages (from azure-mgmt-storage>=1.5.0->azureml-core~=1.12.0->azureml-sdk) (3.0.2)\n", + "Requirement already satisfied, skipping upgrade: azure-nspkg>=2.0.0 in /anaconda/envs/azureml_py36_automl/lib/python3.6/site-packages (from azure-graphrbac>=0.40.0->azureml-core~=1.12.0->azureml-sdk) (3.0.2)\n", + "Requirement already satisfied, skipping upgrade: pyasn1>=0.1.1 in /anaconda/envs/azureml_py36_automl/lib/python3.6/site-packages (from ndg-httpsclient->azureml-core~=1.12.0->azureml-sdk) (0.4.8)\n", + "Requirement already satisfied, skipping upgrade: applicationinsights in /anaconda/envs/azureml_py36_automl/lib/python3.6/site-packages (from azureml-telemetry~=1.12.0->azureml-train-automl-client~=1.12.0->azureml-sdk) (0.11.9)\n", + "Requirement already satisfied, skipping upgrade: numpy>=1.14 in /anaconda/envs/azureml_py36_automl/lib/python3.6/site-packages (from pyarrow<2.0.0,>=0.17.0->azureml-dataset-runtime[fuse]~=1.12.0->azureml-sdk) (1.16.2)\n", + "Requirement already satisfied, skipping upgrade: dotnetcore2<3.0.0,>=2.1.14 in /anaconda/envs/azureml_py36_automl/lib/python3.6/site-packages (from azureml-dataprep<2.1.0a,>=2.0.1a->azureml-dataset-runtime[fuse]~=1.12.0->azureml-sdk) (2.1.14)\n", + "Requirement already satisfied, skipping upgrade: azureml-dataprep-native<21.0.0,>=20.0.2 in /anaconda/envs/azureml_py36_automl/lib/python3.6/site-packages (from azureml-dataprep<2.1.0a,>=2.0.1a->azureml-dataset-runtime[fuse]~=1.12.0->azureml-sdk) (20.0.2)\n", + "Requirement already satisfied, skipping upgrade: cloudpickle<2.0.0,>=1.1.0 in /anaconda/envs/azureml_py36_automl/lib/python3.6/site-packages (from azureml-dataprep<2.1.0a,>=2.0.1a->azureml-dataset-runtime[fuse]~=1.12.0->azureml-sdk) (1.2.2)\n", + "Requirement already satisfied, skipping upgrade: azure-identity<1.3.0,>=1.2.0 in /anaconda/envs/azureml_py36_automl/lib/python3.6/site-packages (from azureml-dataprep<2.1.0a,>=2.0.1a->azureml-dataset-runtime[fuse]~=1.12.0->azureml-sdk) (1.2.0)\n", + "Requirement already satisfied, skipping upgrade: pycparser in /anaconda/envs/azureml_py36_automl/lib/python3.6/site-packages (from cffi!=1.11.3,>=1.8->cryptography!=1.9,!=2.0.*,!=2.1.*,!=2.2.*->azureml-core~=1.12.0->azureml-sdk) (2.19)\n", + "Requirement already satisfied, skipping upgrade: oauthlib>=3.0.0 in /anaconda/envs/azureml_py36_automl/lib/python3.6/site-packages (from requests-oauthlib>=0.5.0->msrest>=0.5.1->azureml-core~=1.12.0->azureml-sdk) (3.1.0)\n", + "Requirement already satisfied, skipping upgrade: distro>=1.2.0 in /anaconda/envs/azureml_py36_automl/lib/python3.6/site-packages (from dotnetcore2<3.0.0,>=2.1.14->azureml-dataprep<2.1.0a,>=2.0.1a->azureml-dataset-runtime[fuse]~=1.12.0->azureml-sdk) (1.4.0)\n", + "Requirement already satisfied, skipping upgrade: msal-extensions~=0.1.3 in /anaconda/envs/azureml_py36_automl/lib/python3.6/site-packages (from azure-identity<1.3.0,>=1.2.0->azureml-dataprep<2.1.0a,>=2.0.1a->azureml-dataset-runtime[fuse]~=1.12.0->azureml-sdk) (0.1.3)\n", + "Requirement already satisfied, skipping upgrade: azure-core<2.0.0,>=1.0.0 in /anaconda/envs/azureml_py36_automl/lib/python3.6/site-packages (from azure-identity<1.3.0,>=1.2.0->azureml-dataprep<2.1.0a,>=2.0.1a->azureml-dataset-runtime[fuse]~=1.12.0->azureml-sdk) (1.8.0)\n", + "Requirement already satisfied, skipping upgrade: msal<2.0.0,>=1.0.0 in /anaconda/envs/azureml_py36_automl/lib/python3.6/site-packages (from azure-identity<1.3.0,>=1.2.0->azureml-dataprep<2.1.0a,>=2.0.1a->azureml-dataset-runtime[fuse]~=1.12.0->azureml-sdk) (1.4.3)\n", + "Requirement already satisfied, skipping upgrade: portalocker~=1.0 in /anaconda/envs/azureml_py36_automl/lib/python3.6/site-packages (from msal-extensions~=0.1.3->azure-identity<1.3.0,>=1.2.0->azureml-dataprep<2.1.0a,>=2.0.1a->azureml-dataset-runtime[fuse]~=1.12.0->azureml-sdk) (1.7.1)\n" + ] + } + ], + "source": [ + "#upgrade t latest versionof sdk \n", + "!pip install --upgrade azureml-sdk" + ] + }, + { + "cell_type": "code", + "execution_count": 53, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1.12.0\n" + ] + } + ], + "source": [ + "import azureml.core\n", + "print(azureml.core.VERSION)" + ] + }, + { + "attachments": {}, + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Get workspace\n", + "Please create a azure Machine learnign workspace on portal.azure.com before runing this notebook, once created download config.json from your workspace, please place config.json file from portal to same folder as notebook ![Capture_withoverlay.JPG](img/conf_file_download.JPG)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 54, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "MyMlAMLNew\n", + "yadavmML\n", + "westus2\n", + "6b736da6-3246-44dd-a0b8-b5e95484633d\n" + ] + } + ], + "source": [ + "from azureml.core.workspace import Workspace\n", + "\n", + "ws = Workspace.from_config()\n", + "print(ws.name, ws.resource_group, ws.location, ws.subscription_id, sep = '\\n')" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Download the model\n", + "\n", + "Prior to registering the model, you should have a TensorFlow [Saved Model](https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/saved_model/README.md) in the `resnet50` directory. This cell will download a [pretrained resnet50](http://download.tensorflow.org/models/official/20181001_resnet/savedmodels/resnet_v1_fp32_savedmodel_NCHW_jpg.tar.gz) and unpack it to that directory." + ] + }, + { + "cell_type": "code", + "execution_count": 55, + "metadata": {}, + "outputs": [], + "source": [ + "import os\n", + "import requests\n", + "import shutil\n", + "import tarfile\n", + "import tempfile\n", + "\n", + "from io import BytesIO\n", + "\n", + "model_url = \"http://download.tensorflow.org/models/official/20181001_resnet/savedmodels/resnet_v1_fp32_savedmodel_NCHW_jpg.tar.gz\"\n", + "\n", + "archive_prefix = \"./resnet_v1_fp32_savedmodel_NCHW_jpg/1538686758/\"\n", + "target_folder = \"resnet50\"\n", + "\n", + "if not os.path.exists(target_folder):\n", + " response = requests.get(model_url)\n", + " archive = tarfile.open(fileobj=BytesIO(response.content))\n", + " with tempfile.TemporaryDirectory() as temp_folder:\n", + " archive.extractall(temp_folder)\n", + " shutil.copytree(os.path.join(temp_folder, archive_prefix), target_folder)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Register the model\n", + "Register an existing trained model, add description and tags." + ] + }, + { + "cell_type": "code", + "execution_count": 56, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Registering model resnet50\n", + "resnet50 Image classification trained on Imagenet Dataset 8\n" + ] + } + ], + "source": [ + "from azureml.core.model import Model\n", + "\n", + "model = Model.register(model_path=\"resnet50\", # This points to the local directory to upload.\n", + " model_name=\"resnet50\", # This is the name the model is registered as.\n", + " tags={'area': \"Image classification\", 'type': \"classification\"},\n", + " description=\"Image classification trained on Imagenet Dataset\",\n", + " workspace=ws)\n", + "\n", + "print(model.name, model.description, model.version)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Deploy the model as a web service to Edge\n", + "\n", + "We begin by writing a score.py file that will be invoked by the web service call. The init() function is called once when the container is started so we load the model using the Tensorflow session. The run() function is called when the webservice is invoked for inferencing. After running the code below you should see a score.py file in the same folder as this notebook." + ] + }, + { + "cell_type": "code", + "execution_count": 57, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Overwriting score.py\n" + ] + } + ], + "source": [ + "%%writefile score.py\n", + "import tensorflow as tf\n", + "import numpy as np\n", + "import json\n", + "import os\n", + "from azureml.contrib.services.aml_request import AMLRequest, rawhttp\n", + "from azureml.contrib.services.aml_response import AMLResponse\n", + "\n", + "def init():\n", + " global session\n", + " global input_name\n", + " global output_name\n", + " \n", + " session = tf.Session()\n", + "\n", + " # AZUREML_MODEL_DIR is an environment variable created during deployment.\n", + " # It is the path to the model folder (./azureml-models/$MODEL_NAME/$VERSION)\n", + " # For multiple models, it points to the folder containing all deployed models (./azureml-models)\n", + " model_path = os.path.join(os.getenv('AZUREML_MODEL_DIR'), 'resnet50')\n", + " model = tf.saved_model.loader.load(session, ['serve'], model_path)\n", + " if len(model.signature_def['serving_default'].inputs) > 1:\n", + " raise ValueError(\"This score.py only supports one input\")\n", + " input_name = [tensor.name for tensor in model.signature_def['serving_default'].inputs.values()][0]\n", + " output_name = [tensor.name for tensor in model.signature_def['serving_default'].outputs.values()]\n", + " \n", + "\n", + "@rawhttp\n", + "def run(request):\n", + " if request.method == 'POST':\n", + " reqBody = request.get_data(False)\n", + " resp = score(reqBody)\n", + " return AMLResponse(resp, 200)\n", + " if request.method == 'GET':\n", + " respBody = str.encode(\"GET is not supported\")\n", + " return AMLResponse(respBody, 405)\n", + " return AMLResponse(\"bad request\", 500)\n", + "\n", + "def score(data):\n", + " result = session.run(output_name, {input_name: [data]})\n", + " return json.dumps(result[1].tolist())\n", + "\n", + "if __name__ == \"__main__\":\n", + " init()\n", + " with open(\"test_image.jpg\", 'rb') as f:\n", + " content = f.read()\n", + " print(score(content))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Now create the deployment configuration objects " + ] + }, + { + "cell_type": "code", + "execution_count": 58, + "metadata": {}, + "outputs": [], + "source": [ + "# Set the web service configuration (using default here)\n", + "from azureml.core.model import InferenceConfig\n", + "#from azureml.core.webservice import AksWebservice\n", + "from azureml.core.conda_dependencies import CondaDependencies\n", + "from azureml.core.environment import Environment, DEFAULT_GPU_IMAGE\n", + "\n", + "env = Environment('deploytoedgeenv')\n", + "# Please see [Azure ML Containers repository](https://github.com/Azure/AzureML-Containers#featured-tags)\n", + "# for open-sourced GPU base images.\n", + "env.docker.base_image = DEFAULT_GPU_IMAGE\n", + "env.python.conda_dependencies = CondaDependencies.create(conda_packages=['tensorflow-gpu==1.12.0','numpy'],\n", + " pip_packages=['azureml-contrib-services', 'azureml-defaults'])\n", + "\n", + "inference_config = InferenceConfig(entry_script=\"score.py\", environment=env)\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Create container image in Azure ML\n", + "Use Azure ML to create the container image. This step will likely take a few minutes." + ] + }, + { + "cell_type": "code", + "execution_count": 59, + "metadata": {}, + "outputs": [], + "source": [ + "# provide name of azure contaienr image and tag \n", + "imagename= \"tfgpu\"\n", + "imagelabel=\"0.2\"" + ] + }, + { + "cell_type": "code", + "execution_count": 52, + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "2020/08/31 17:23:42 Downloading source code...\n", + "2020/08/31 17:23:43 Finished downloading source code\n", + "2020/08/31 17:23:44 Creating Docker network: acb_default_network, driver: 'bridge'\n", + "2020/08/31 17:23:44 Successfully set up Docker network: acb_default_network\n", + "2020/08/31 17:23:44 Setting up Docker configuration...\n", + "2020/08/31 17:23:45 Successfully set up Docker configuration\n", + "2020/08/31 17:23:45 Logging in to registry: mymlamlnewea54e393.azurecr.io\n", + "2020/08/31 17:23:46 Successfully logged into mymlamlnewea54e393.azurecr.io\n", + "2020/08/31 17:23:46 Executing step ID: acb_step_0. Timeout(sec): 5400, Working directory: '', Network: 'acb_default_network'\n", + "2020/08/31 17:23:46 Launching container with name: acb_step_0\n", + "WARNING! Using --password via the CLI is insecure. Use --password-stdin.\n", + "WARNING! Your password will be stored unencrypted in /acb/home/.docker/config.json.\n", + "Configure a credential helper to remove this warning. See\n", + "https://docs.docker.com/engine/reference/commandline/login/#credentials-store\n", + "\n", + "Login Succeeded\n", + "2020/08/31 17:23:47 Successfully executed container: acb_step_0\n", + "2020/08/31 17:23:47 Executing step ID: acb_step_1. Timeout(sec): 5400, Working directory: '', Network: 'acb_default_network'\n", + "2020/08/31 17:23:47 Scanning for dependencies...\n", + "2020/08/31 17:23:48 Successfully scanned dependencies\n", + "2020/08/31 17:23:48 Launching container with name: acb_step_1\n", + "Sending build context to Docker daemon 62.46kB\n", + "Step 1/10 : FROM mymlamlnewea54e393.azurecr.io/azureml/azureml_44d8f5946ac391cd72138132d04ff02f\n", + "latest: Pulling from azureml/azureml_44d8f5946ac391cd72138132d04ff02f\n", + "f7277927d38a: Pulling fs layer\n", + "8d3eac894db4: Pulling fs layer\n", + "edf72af6d627: Pulling fs layer\n", + "3e4f86211d23: Pulling fs layer\n", + "d6e9603ff777: Pulling fs layer\n", + "5cad422780e2: Pulling fs layer\n", + "8130687c8acb: Pulling fs layer\n", + "c11e9246d621: Pulling fs layer\n", + "0dfae24cbbd9: Pulling fs layer\n", + "0bb049a6d391: Pulling fs layer\n", + "a1369dd12478: Pulling fs layer\n", + "ac2bc8c5eb10: Pulling fs layer\n", + "c4c973f72871: Pulling fs layer\n", + "581053cbb443: Pulling fs layer\n", + "3e4f86211d23: Waiting\n", + "d6e9603ff777: Waiting\n", + "5cad422780e2: Waiting\n", + "8130687c8acb: Waiting\n", + "c11e9246d621: Waiting\n", + "0dfae24cbbd9: Waiting\n", + "0bb049a6d391: Waiting\n", + "a1369dd12478: Waiting\n", + "ac2bc8c5eb10: Waiting\n", + "c4c973f72871: Waiting\n", + "3a80b1c894df: Pulling fs layer\n", + "ce1874c314dd: Pulling fs layer\n", + "581053cbb443: Waiting\n", + "3a80b1c894df: Waiting\n", + "66b6bc713da6: Pulling fs layer\n", + "117132804561: Pulling fs layer\n", + "2718321fea79: Pulling fs layer\n", + "2d4de4acaa6f: Pulling fs layer\n", + "ce1874c314dd: Waiting\n", + "66b6bc713da6: Waiting\n", + "08c6a28803b9: Pulling fs layer\n", + "8af8474b47d6: Pulling fs layer\n", + "5f99ee6feb34: Pulling fs layer\n", + "1c12afe67221: Pulling fs layer\n", + "117132804561: Waiting\n", + "2718321fea79: Waiting\n", + "2d4de4acaa6f: Waiting\n", + "08c6a28803b9: Waiting\n", + "8af8474b47d6: Waiting\n", + "5f99ee6feb34: Waiting\n", + "1c12afe67221: Waiting\n", + "edf72af6d627: Verifying Checksum\n", + "edf72af6d627: Download complete\n", + "8d3eac894db4: Verifying Checksum\n", + "8d3eac894db4: Download complete\n", + "3e4f86211d23: Verifying Checksum\n", + "3e4f86211d23: Download complete\n", + "d6e9603ff777: Verifying Checksum\n", + "d6e9603ff777: Download complete\n", + "8130687c8acb: Verifying Checksum\n", + "8130687c8acb: Download complete\n", + "5cad422780e2: Verifying Checksum\n", + "5cad422780e2: Download complete\n", + "f7277927d38a: Verifying Checksum\n", + "f7277927d38a: Download complete\n", + "c11e9246d621: Verifying Checksum\n", + "c11e9246d621: Download complete\n", + "0bb049a6d391: Verifying Checksum\n", + "0bb049a6d391: Download complete\n", + "a1369dd12478: Verifying Checksum\n", + "a1369dd12478: Download complete\n", + "ac2bc8c5eb10: Verifying Checksum\n", + "ac2bc8c5eb10: Download complete\n", + "c4c973f72871: Verifying Checksum\n", + "c4c973f72871: Download complete\n", + "581053cbb443: Verifying Checksum\n", + "581053cbb443: Download complete\n", + "ce1874c314dd: Verifying Checksum\n", + "ce1874c314dd: Download complete\n", + "0dfae24cbbd9: Verifying Checksum\n", + "0dfae24cbbd9: Download complete\n", + "3a80b1c894df: Verifying Checksum\n", + "3a80b1c894df: Download complete\n", + "66b6bc713da6: Verifying Checksum\n", + "66b6bc713da6: Download complete\n", + "2718321fea79: Verifying Checksum\n", + "2718321fea79: Download complete\n", + "2d4de4acaa6f: Verifying Checksum\n", + "2d4de4acaa6f: Download complete\n", + "f7277927d38a: Pull complete\n", + "08c6a28803b9: Verifying Checksum\n", + "08c6a28803b9: Download complete\n", + "8d3eac894db4: Pull complete\n", + "8af8474b47d6: Verifying Checksum\n", + "8af8474b47d6: Download complete\n", + "117132804561: Verifying Checksum\n", + "117132804561: Download complete\n", + "edf72af6d627: Pull complete\n", + "1c12afe67221: Verifying Checksum\n", + "1c12afe67221: Download complete\n", + "3e4f86211d23: Pull complete\n", + "d6e9603ff777: Pull complete\n", + "5cad422780e2: Pull complete\n", + "8130687c8acb: Pull complete\n", + "\n", + "c11e9246d621: Pull complete\n", + "5f99ee6feb34: Verifying Checksum\n", + "5f99ee6feb34: Download complete\n", + "\n", + "0dfae24cbbd9: Pull complete\n", + "0bb049a6d391: Pull complete\n", + "a1369dd12478: Pull complete\n", + "ac2bc8c5eb10: Pull complete\n", + "c4c973f72871: Pull complete\n", + "581053cbb443: Pull complete\n", + "3a80b1c894df: Pull complete\n", + "ce1874c314dd: Pull complete\n", + "66b6bc713da6: Pull complete\n", + "117132804561: Pull complete\n", + "2718321fea79: Pull complete\n", + "2d4de4acaa6f: Pull complete\n", + "08c6a28803b9: Pull complete\n", + "8af8474b47d6: Pull complete\n", + "\n", + "5f99ee6feb34: Pull complete\n", + "1c12afe67221: Pull complete\n", + "Digest: sha256:a3b27dd75d22c61e7fbec03c620b4aeced1fbae2e903519da3d0b1d275146e1d\n", + "Status: Downloaded newer image for mymlamlnewea54e393.azurecr.io/azureml/azureml_44d8f5946ac391cd72138132d04ff02f:latest\n", + " ---> 53bd17eec633\n", + "Step 2/10 : ENV AZUREML_MODEL_DIR=azureml-models/resnet50/7\n", + " ---> Running in e322d80d238f\n", + "Removing intermediate container e322d80d238f\n", + " ---> 77dbf7d87213\n", + "Step 3/10 : RUN mkdir -p '/var/azureml-app' && /var/azureml-util/download_asset.sh 'https://mymlamlnew8373615065.blob.core.windows.net/azureml/LocalUpload/70a4c5c6/tmpolcq25ed.py?sv=2019-02-02&sr=b&sig=RIesrXM4ED3Td8fymuu1liYhPMi%2FaK%2BIQS04Zv7x%2FzU%3D&st=2020-08-31T17%3A13%3A38Z&se=2020-09-01T01%3A23%3A38Z&sp=r' '/var/azureml-app/tmpolcq25ed.py'\n", + " ---> Running in d76bda7902a2\n", + "Downloading https://mymlamlnew8373615065.blob.core.windows.net/azureml/LocalUpload/70a4c5c6/tmpolcq25ed.py?sv=2019-02-02&sr=b&sig=RIesrXM4ED3Td8fymuu1liYhPMi%2FaK%2BIQS04Zv7x%2FzU%3D&st=2020-08-31T17%3A13%3A38Z&se=2020-09-01T01%3A23%3A38Z&sp=r as /var/azureml-app/tmpolcq25ed.py\n", + "\u001b[91mwget: /azureml-envs/azureml_0827b7ee7d45e44b2b71c805b14ad4d9/lib/libcrypto.so.1.0.0: no version information available (required by wget)\n", + "wget: /azureml-envs/azureml_0827b7ee7d45e44b2b71c805b14ad4d9/lib/libssl.so.1.0.0: no version information available (required by wget)\n", + "wget: /azureml-envs/azureml_0827b7ee7d45e44b2b71c805b14ad4d9/lib/libssl.so.1.0.0: no version information available (required by wget)\n", + "\u001b[0m\u001b[91m--2020-08-31 17:26:59-- https://mymlamlnew8373615065.blob.core.windows.net/azureml/LocalUpload/70a4c5c6/tmpolcq25ed.py?sv=2019-02-02&sr=b&sig=RIesrXM4ED3Td8fymuu1liYhPMi%2FaK%2BIQS04Zv7x%2FzU%3D&st=2020-08-31T17%3A13%3A38Z&se=2020-09-01T01%3A23%3A38Z&sp=r\n", + "\u001b[0m\u001b[91mResolving mymlamlnew8373615065.blob.core.windows.net (mymlamlnew8373615065.blob.core.windows.net)... \u001b[0m\u001b[91m52.239.193.100\n", + "Connecting to mymlamlnew8373615065.blob.core.windows.net (mymlamlnew8373615065.blob.core.windows.net)|52.239.193.100|:443... \u001b[0m\u001b[91mconnected.\n", + "\u001b[0m\u001b[91mHTTP request sent, awaiting response... \u001b[0m\u001b[91m200 OK\n", + "Length: 1064 (1.0K) [application/octet-stream]\n", + "\u001b[0m\u001b[91mSaving to: ‘/var/azureml-app/tmpolcq25ed.py’\n", + "\n", + " 0K 100% 119M=0s\n", + "\n", + "2020-08-31 17:26:59 (119 MB/s) - ‘/var/azureml-app/tmpolcq25ed.py’ saved [1064/1064]\n", + "\n", + "\u001b[0mRemoving intermediate container d76bda7902a2\n", + " ---> 4092ad2c0948\n", + "Step 4/10 : RUN mkdir -p '/var/azureml-app' && /var/azureml-util/download_asset.sh 'https://mymlamlnew8373615065.blob.core.windows.net/azureml/LocalUpload/5f0e6568/score.py?sv=2019-02-02&sr=b&sig=QUifq8cSNu5ygNpOnUvhAx24PhwrSqh4pwhjKA4OKXM%3D&st=2020-08-31T17%3A13%3A38Z&se=2020-09-01T01%3A23%3A38Z&sp=r' '/var/azureml-app/score.py'\n", + " ---> Running in 6b3f3c17633a\n", + "Downloading https://mymlamlnew8373615065.blob.core.windows.net/azureml/LocalUpload/5f0e6568/score.py?sv=2019-02-02&sr=b&sig=QUifq8cSNu5ygNpOnUvhAx24PhwrSqh4pwhjKA4OKXM%3D&st=2020-08-31T17%3A13%3A38Z&se=2020-09-01T01%3A23%3A38Z&sp=r as /var/azureml-app/score.py\n", + "\u001b[91mwget: /azureml-envs/azureml_0827b7ee7d45e44b2b71c805b14ad4d9/lib/libcrypto.so.1.0.0: no version information available (required by wget)\n", + "wget: /azureml-envs/azureml_0827b7ee7d45e44b2b71c805b14ad4d9/lib/libssl.so.1.0.0: no version information available (required by wget)\n", + "wget: /azureml-envs/azureml_0827b7ee7d45e44b2b71c805b14ad4d9/lib/libssl.so.1.0.0: no version information available (required by wget)\n", + "\u001b[0m\u001b[91m--2020-08-31 17:27:03-- https://mymlamlnew8373615065.blob.core.windows.net/azureml/LocalUpload/5f0e6568/score.py?sv=2019-02-02&sr=b&sig=QUifq8cSNu5ygNpOnUvhAx24PhwrSqh4pwhjKA4OKXM%3D&st=2020-08-31T17%3A13%3A38Z&se=2020-09-01T01%3A23%3A38Z&sp=r\n", + "\u001b[0m\u001b[91mResolving mymlamlnew8373615065.blob.core.windows.net (mymlamlnew8373615065.blob.core.windows.net)... \u001b[0m\u001b[91m52.239.193.100\n", + "Connecting to mymlamlnew8373615065.blob.core.windows.net (mymlamlnew8373615065.blob.core.windows.net)|52.239.193.100|:443... \u001b[0m\u001b[91mconnected.\n", + "\u001b[0m\u001b[91mHTTP request sent, awaiting response... \u001b[0m\u001b[91m200 OK\n", + "Length: 1652 (1.6K) [application/octet-stream]\n", + "\u001b[0m\u001b[91mSaving to: ‘/var/azureml-app/score.py’\n", + "\n", + " 0K 100% 183M=0s\n", + "\n", + "2020-08-31 17:27:03 (183 MB/s) - ‘/var/azureml-app/score.py’ saved [1652/1652]\n", + "\n", + "\u001b[0mRemoving intermediate container 6b3f3c17633a\n", + " ---> bba5f7963855\n", + "Step 5/10 : RUN mkdir -p '/var/azureml-app/azureml-models/resnet50/7/resnet50' && /var/azureml-util/download_asset.sh 'https://mymlamlnew8373615065.blob.core.windows.net/azureml/LocalUpload/200831T172308-b5dc6775/resnet50/saved_model.pb?sv=2019-02-02&sr=b&sig=8wj7g6fiz2LvS4vxW1D91eGwbtf6wZgMKlIEyz9LsJ4%3D&st=2020-08-31T17%3A13%3A38Z&se=2020-09-01T01%3A23%3A38Z&sp=r' '/var/azureml-app/azureml-models/resnet50/7/resnet50/saved_model.pb'\n", + " ---> Running in 84554a72556d\n", + "Downloading https://mymlamlnew8373615065.blob.core.windows.net/azureml/LocalUpload/200831T172308-b5dc6775/resnet50/saved_model.pb?sv=2019-02-02&sr=b&sig=8wj7g6fiz2LvS4vxW1D91eGwbtf6wZgMKlIEyz9LsJ4%3D&st=2020-08-31T17%3A13%3A38Z&se=2020-09-01T01%3A23%3A38Z&sp=r as /var/azureml-app/azureml-models/resnet50/7/resnet50/saved_model.pb\n", + "\u001b[91mwget: /azureml-envs/azureml_0827b7ee7d45e44b2b71c805b14ad4d9/lib/libcrypto.so.1.0.0: no version information available (required by wget)\n", + "wget: /azureml-envs/azureml_0827b7ee7d45e44b2b71c805b14ad4d9/lib/libssl.so.1.0.0: no version information available (required by wget)\n", + "wget: /azureml-envs/azureml_0827b7ee7d45e44b2b71c805b14ad4d9/lib/libssl.so.1.0.0: no version information available (required by wget)\n", + "\u001b[0m\u001b[91m--2020-08-31 17:27:07-- https://mymlamlnew8373615065.blob.core.windows.net/azureml/LocalUpload/200831T172308-b5dc6775/resnet50/saved_model.pb?sv=2019-02-02&sr=b&sig=8wj7g6fiz2LvS4vxW1D91eGwbtf6wZgMKlIEyz9LsJ4%3D&st=2020-08-31T17%3A13%3A38Z&se=2020-09-01T01%3A23%3A38Z&sp=r\n", + "\u001b[0m\u001b[91mResolving mymlamlnew8373615065.blob.core.windows.net (mymlamlnew8373615065.blob.core.windows.net)... \u001b[0m\u001b[91m52.239.193.100\n", + "Connecting to mymlamlnew8373615065.blob.core.windows.net (mymlamlnew8373615065.blob.core.windows.net)|52.239.193.100|:443... \u001b[0m\u001b[91mconnected.\n", + "\u001b[0m\u001b[91mHTTP request sent, awaiting response... \u001b[0m\u001b[91m200 OK\n", + "Length: 596222 (582K) [application/octet-stream]\n", + "\u001b[0m\u001b[91mSaving to: ‘/var/azureml-app/azureml-models/resnet50/7/resnet50/saved_model.pb’\n", + "\u001b[0m\u001b[91m\n", + " 0K 100% 57.6M=0.01s\n", + "\n", + "\u001b[0m\u001b[91m2020-08-31 17:27:07 (57.6 MB/s) - ‘/var/azureml-app/azureml-models/resnet50/7/resnet50/saved_model.pb’ saved [596222/596222]\n", + "\n", + "\u001b[0mRemoving intermediate container 84554a72556d\n", + " ---> 6199469091cd\n", + "Step 6/10 : RUN mkdir -p '/var/azureml-app/azureml-models/resnet50/7/resnet50/variables' && /var/azureml-util/download_asset.sh 'https://mymlamlnew8373615065.blob.core.windows.net/azureml/LocalUpload/200831T172308-b5dc6775/resnet50/variables/variables.index?sv=2019-02-02&sr=b&sig=8TP%2BCLEpfAOdqksFuaYsDIg5MUPFXyQ4QOreOZsXvTo%3D&st=2020-08-31T17%3A13%3A38Z&se=2020-09-01T01%3A23%3A38Z&sp=r' '/var/azureml-app/azureml-models/resnet50/7/resnet50/variables/variables.index'\n", + " ---> Running in a2a6c103076c\n", + "Downloading https://mymlamlnew8373615065.blob.core.windows.net/azureml/LocalUpload/200831T172308-b5dc6775/resnet50/variables/variables.index?sv=2019-02-02&sr=b&sig=8TP%2BCLEpfAOdqksFuaYsDIg5MUPFXyQ4QOreOZsXvTo%3D&st=2020-08-31T17%3A13%3A38Z&se=2020-09-01T01%3A23%3A38Z&sp=r as /var/azureml-app/azureml-models/resnet50/7/resnet50/variables/variables.index\n", + "\u001b[91mwget: /azureml-envs/azureml_0827b7ee7d45e44b2b71c805b14ad4d9/lib/libcrypto.so.1.0.0: no version information available (required by wget)\n", + "wget: /azureml-envs/azureml_0827b7ee7d45e44b2b71c805b14ad4d9/lib/libssl.so.1.0.0: no version information available (required by wget)\n", + "wget: /azureml-envs/azureml_0827b7ee7d45e44b2b71c805b14ad4d9/lib/libssl.so.1.0.0: no version information available (required by wget)\n", + "\u001b[0m\u001b[91m--2020-08-31 17:27:11-- https://mymlamlnew8373615065.blob.core.windows.net/azureml/LocalUpload/200831T172308-b5dc6775/resnet50/variables/variables.index?sv=2019-02-02&sr=b&sig=8TP%2BCLEpfAOdqksFuaYsDIg5MUPFXyQ4QOreOZsXvTo%3D&st=2020-08-31T17%3A13%3A38Z&se=2020-09-01T01%3A23%3A38Z&sp=r\n", + "\u001b[0m\u001b[91mResolving mymlamlnew8373615065.blob.core.windows.net (mymlamlnew8373615065.blob.core.windows.net)... \u001b[0m\u001b[91m52.239.193.100\n", + "Connecting to mymlamlnew8373615065.blob.core.windows.net (mymlamlnew8373615065.blob.core.windows.net)|52.239.193.100|:443... \u001b[0m\u001b[91mconnected.\n", + "\u001b[0m\u001b[91mHTTP request sent, awaiting response... \u001b[0m\u001b[91m200 OK\n", + "Length: 9950 (9.7K) [application/octet-stream]\n", + "Saving to: ‘/var/azureml-app/azureml-models/resnet50/7/resnet50/variables/variables.index’\n", + "\u001b[0m\u001b[91m\n", + " 0K 100% 12.2M=0.001s\n", + "\n", + "2020-08-31 17:27:11 (12.2 MB/s) - ‘/var/azureml-app/azureml-models/resnet50/7/resnet50/variables/variables.index’ saved [9950/9950]\n", + "\n", + "\u001b[0mRemoving intermediate container a2a6c103076c\n", + " ---> c1aff9bea69a\n", + "Step 7/10 : RUN mkdir -p '/var/azureml-app/azureml-models/resnet50/7/resnet50/variables' && /var/azureml-util/download_asset.sh 'https://mymlamlnew8373615065.blob.core.windows.net/azureml/LocalUpload/200831T172308-b5dc6775/resnet50/variables/variables.data-00000-of-00001?sv=2019-02-02&sr=b&sig=hbI15tBCSxBUNFK24HLOHUyBFJi71G9ZWoqQ290RREY%3D&st=2020-08-31T17%3A13%3A38Z&se=2020-09-01T01%3A23%3A38Z&sp=r' '/var/azureml-app/azureml-models/resnet50/7/resnet50/variables/variables.data-00000-of-00001'\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + " ---> Running in 0152203c83d5\n", + "Downloading https://mymlamlnew8373615065.blob.core.windows.net/azureml/LocalUpload/200831T172308-b5dc6775/resnet50/variables/variables.data-00000-of-00001?sv=2019-02-02&sr=b&sig=hbI15tBCSxBUNFK24HLOHUyBFJi71G9ZWoqQ290RREY%3D&st=2020-08-31T17%3A13%3A38Z&se=2020-09-01T01%3A23%3A38Z&sp=r as /var/azureml-app/azureml-models/resnet50/7/resnet50/variables/variables.data-00000-of-00001\n", + "\u001b[91mwget: /azureml-envs/azureml_0827b7ee7d45e44b2b71c805b14ad4d9/lib/libcrypto.so.1.0.0: no version information available (required by wget)\n", + "wget: /azureml-envs/azureml_0827b7ee7d45e44b2b71c805b14ad4d9/lib/libssl.so.1.0.0: no version information available (required by wget)\n", + "wget: /azureml-envs/azureml_0827b7ee7d45e44b2b71c805b14ad4d9/lib/libssl.so.1.0.0: no version information available (required by wget)\n", + "\u001b[0m\u001b[91m--2020-08-31 17:27:15-- https://mymlamlnew8373615065.blob.core.windows.net/azureml/LocalUpload/200831T172308-b5dc6775/resnet50/variables/variables.data-00000-of-00001?sv=2019-02-02&sr=b&sig=hbI15tBCSxBUNFK24HLOHUyBFJi71G9ZWoqQ290RREY%3D&st=2020-08-31T17%3A13%3A38Z&se=2020-09-01T01%3A23%3A38Z&sp=r\n", + "\u001b[0m\u001b[91mResolving mymlamlnew8373615065.blob.core.windows.net (mymlamlnew8373615065.blob.core.windows.net)... \u001b[0m\u001b[91m52.239.193.100\n", + "Connecting to mymlamlnew8373615065.blob.core.windows.net (mymlamlnew8373615065.blob.core.windows.net)|52.239.193.100|:443... \u001b[0m\u001b[91mconnected.\n", + "\u001b[0m\u001b[91mHTTP request sent, awaiting response... \u001b[0m\u001b[91m200 OK\n", + "Length: 102448812 (98M) [application/octet-stream]\n", + "\u001b[0m\u001b[91mSaving to: ‘/var/azureml-app/azureml-models/resnet50/7/resnet50/variables/variables.data-00000-of-00001’\n", + "\u001b[0m\u001b[91m\n", + " 0K .\u001b[0m\u001b[91m.\u001b[0m\u001b[91m.\u001b[0m\u001b[91m.\u001b[0m\u001b[91m.\u001b[0m\u001b[91m.\u001b[0m\u001b[91m.\u001b[0m\u001b[91m.\u001b[0m\u001b[91m .\u001b[0m\u001b[91m.\u001b[0m\u001b[91m.\u001b[0m\u001b[91m.\u001b[0m\u001b[91m.\u001b[0m\u001b[91m.\u001b[0m\u001b[91m.\u001b[0m\u001b[91m.\u001b[0m\u001b[91m .\u001b[0m\u001b[91m.\u001b[0m\u001b[91m.\u001b[0m\u001b[91m.\u001b[0m\u001b[91m.\u001b[0m\u001b[91m.\u001b[0m\u001b[91m.\u001b[0m\u001b[91m.\u001b[0m\u001b[91m \u001b[0m\u001b[91m.\u001b[0m\u001b[91m.\u001b[0m\u001b[91m.\u001b[0m\u001b[91m.\u001b[0m\u001b[91m.\u001b[0m\u001b[91m.\u001b[0m\u001b[91m.\u001b[0m\u001b[91m. 32% 50.4M 1s\u001b[0m\u001b[91m\n", + " 32768K .\u001b[0m\u001b[91m.\u001b[0m\u001b[91m.\u001b[0m\u001b[91m.\u001b[0m\u001b[91m.\u001b[0m\u001b[91m.\u001b[0m\u001b[91m.\u001b[0m\u001b[91m.\u001b[0m\u001b[91m .\u001b[0m\u001b[91m.\u001b[0m\u001b[91m.\u001b[0m\u001b[91m.\u001b[0m\u001b[91m.\u001b[0m\u001b[91m.\u001b[0m\u001b[91m.\u001b[0m\u001b[91m.\u001b[0m\u001b[91m .\u001b[0m\u001b[91m.\u001b[0m\u001b[91m.\u001b[0m\u001b[91m.\u001b[0m\u001b[91m.\u001b[0m\u001b[91m.\u001b[0m\u001b[91m.\u001b[0m\u001b[91m.\u001b[0m\u001b[91m .\u001b[0m\u001b[91m.\u001b[0m\u001b[91m.\u001b[0m\u001b[91m.\u001b[0m\u001b[91m.\u001b[0m\u001b[91m.\u001b[0m\u001b[91m.\u001b[0m\u001b[91m. 65% 55.8M 1s\u001b[0m\u001b[91m\n", + " 65536K .\u001b[0m\u001b[91m.\u001b[0m\u001b[91m.\u001b[0m\u001b[91m.\u001b[0m\u001b[91m.\u001b[0m\u001b[91m.\u001b[0m\u001b[91m.\u001b[0m\u001b[91m.\u001b[0m\u001b[91m .\u001b[0m\u001b[91m.\u001b[0m\u001b[91m.\u001b[0m\u001b[91m.\u001b[0m\u001b[91m.\u001b[0m\u001b[91m.\u001b[0m\u001b[91m.\u001b[0m\u001b[91m.\u001b[0m\u001b[91m .\u001b[0m\u001b[91m.\u001b[0m\u001b[91m.\u001b[0m\u001b[91m.\u001b[0m\u001b[91m.\u001b[0m\u001b[91m.\u001b[0m\u001b[91m.\u001b[0m\u001b[91m.\u001b[0m\u001b[91m .\u001b[0m\u001b[91m.\u001b[0m\u001b[91m.\u001b[0m\u001b[91m.\u001b[0m\u001b[91m.\u001b[0m\u001b[91m.\u001b[0m\u001b[91m.\u001b[0m\u001b[91m. 98% 34.6M 0s\u001b[0m\u001b[91m\n", + " 98304K \u001b[0m\u001b[91m.\u001b[0m\u001b[91m 100% 74.6M\u001b[0m\u001b[91m=2.2s\n", + "\n", + "\u001b[0m\u001b[91m2020-08-31 17:27:17 (45.3 MB/s) - ‘/var/azureml-app/azureml-models/resnet50/7/resnet50/variables/variables.data-00000-of-00001’ saved [102448812/102448812]\n", + "\n", + "\u001b[0mRemoving intermediate container 0152203c83d5\n", + " ---> d06c9ee06f1f\n", + "Step 8/10 : RUN mkdir -p '/var/azureml-app' && echo eyJhY2NvdW50Q29udGV4dCI6eyJzdWJzY3JpcHRpb25JZCI6IjZiNzM2ZGE2LTMyNDYtNDRkZC1hMGI4LWI1ZTk1NDg0NjMzZCIsInJlc291cmNlR3JvdXBOYW1lIjoieWFkYXZtbWwiLCJhY2NvdW50TmFtZSI6Im15bWxhbWxuZXciLCJ3b3Jrc3BhY2VJZCI6IjA1YzVlM2MwLTA2ODMtNGJiMS05OWQzLTBkMGQyYThhYWZkNyJ9LCJtb2RlbHMiOnsicmVzbmV0NTAiOnsidmVyc2lvbiI6NywiaWQiOiJyZXNuZXQ1MDo3IiwiaW50ZXJuYWxJZCI6ImQxNmU0YzZkMTNlMzQ4MzFiYWEwYTY3YzJhZTk4Y2Q4In19LCJtb2RlbHNJbmZvIjp7InJlc25ldDUwIjp7IjciOnsidmVyc2lvbiI6NywiaWQiOiJyZXNuZXQ1MDo3IiwiaW50ZXJuYWxJZCI6ImQxNmU0YzZkMTNlMzQ4MzFiYWEwYTY3YzJhZTk4Y2Q4IiwiZGF0YUNvbGxlY3RvclN0b3JhZ2VQYXRoIjoiL21vZGVsZGF0YS82YjczNmRhNi0zMjQ2LTQ0ZGQtYTBiOC1iNWU5NTQ4NDYzM2QveWFkYXZtbWwvbXltbGFtbG5ldy97d2Vic2VydmljZV9uYW1lfS9yZXNuZXQ1MC83LyJ9fX19 | base64 --decode > /var/azureml-app/model_config_map.json\n", + " ---> Running in f589be5a5608\n", + "Removing intermediate container f589be5a5608\n", + " ---> 29fd4d01494a\n", + "Step 9/10 : RUN mv '/var/azureml-app/tmpolcq25ed.py' /var/azureml-app/main.py\n", + " ---> Running in 78839b98362f\n", + "Removing intermediate container 78839b98362f\n", + " ---> 95aeac363e14\n", + "Step 10/10 : CMD [\"runsvdir\",\"/var/runit\"]\n", + " ---> Running in 19f06ea845a6\n", + "Removing intermediate container 19f06ea845a6\n", + " ---> 8fb6151d8a51\n", + "Successfully built 8fb6151d8a51\n", + "Successfully tagged mymlamlnewea54e393.azurecr.io/azureml/azureml_e35d3781f89ea61d18a514feb0f9c27b:latest\n", + "2020/08/31 17:27:33 Successfully executed container: acb_step_1\n", + "2020/08/31 17:27:33 Executing step ID: acb_step_2. Timeout(sec): 5400, Working directory: '', Network: 'acb_default_network'\n", + "2020/08/31 17:27:33 Pushing image: mymlamlnewea54e393.azurecr.io/azureml/azureml_e35d3781f89ea61d18a514feb0f9c27b:latest, attempt 1\n", + "The push refers to repository [mymlamlnewea54e393.azurecr.io/azureml/azureml_e35d3781f89ea61d18a514feb0f9c27b]\n", + "fc01753407fa: Preparing\n", + "cc7e04fd869c: Preparing\n", + "e4c9c8837d21: Preparing\n", + "33883bf794e7: Preparing\n", + "2b77f8422ec2: Preparing\n", + "1d35045d1c1c: Preparing\n", + "198e2e7a7035: Preparing\n", + "a9cca3895fde: Preparing\n", + "a33637615c59: Preparing\n", + "4d55f34c6519: Preparing\n", + "259de21b5f5b: Preparing\n", + "d30e3964c9b8: Preparing\n", + "0b84c38716cb: Preparing\n", + "4622844d38e2: Preparing\n", + "fd55e46360fd: Preparing\n", + "9a3749a6223b: Preparing\n", + "5705f94592d7: Preparing\n", + "9b528e5e3ae3: Preparing\n", + "e650edbb7d27: Preparing\n", + "f08bd7cda03f: Preparing\n", + "cba13f2bedf3: Preparing\n", + "c36fc92de581: Preparing\n", + "524881d0563d: Preparing\n", + "d05c249e6b9f: Preparing\n", + "fc8a172f94e8: Preparing\n", + "48001c8a7ddb: Preparing\n", + "6dce9683cb41: Preparing\n", + "e79142719515: Preparing\n", + "aeda103e78c9: Preparing\n", + "2558e637fbff: Preparing\n", + "f749b9b0fb21: Preparing\n", + "1d35045d1c1c: Waiting\n", + "198e2e7a7035: Waiting\n", + "a9cca3895fde: Waiting\n", + "a33637615c59: Waiting\n", + "4d55f34c6519: Waiting\n", + "c36fc92de581: Waiting\n", + "524881d0563d: Waiting\n", + "259de21b5f5b: Waiting\n", + "d05c249e6b9f: Waiting\n", + "fc8a172f94e8: Waiting\n", + "d30e3964c9b8: Waiting\n", + "48001c8a7ddb: Waiting\n", + "6dce9683cb41: Waiting\n", + "0b84c38716cb: Waiting\n", + "4622844d38e2: Waiting\n", + "e79142719515: Waiting\n", + "aeda103e78c9: Waiting\n", + "fd55e46360fd: Waiting\n", + "2558e637fbff: Waiting\n", + "9a3749a6223b: Waiting\n", + "f749b9b0fb21: Waiting\n", + "5705f94592d7: Waiting\n", + "9b528e5e3ae3: Waiting\n", + "e650edbb7d27: Waiting\n", + "f08bd7cda03f: Waiting\n", + "cba13f2bedf3: Waiting\n", + "fc01753407fa: Pushed\n", + "2b77f8422ec2: Pushed\n", + "33883bf794e7: Pushed\n", + "cc7e04fd869c: Pushed\n", + "a33637615c59: Mounted from azureml/azureml_44d8f5946ac391cd72138132d04ff02f\n", + "198e2e7a7035: Pushed\n", + "a9cca3895fde: Mounted from azureml/azureml_44d8f5946ac391cd72138132d04ff02f\n", + "1d35045d1c1c: Pushed\n", + "4d55f34c6519: Mounted from azureml/azureml_44d8f5946ac391cd72138132d04ff02f\n", + "259de21b5f5b: Mounted from azureml/azureml_44d8f5946ac391cd72138132d04ff02f\n", + "d30e3964c9b8: Mounted from azureml/azureml_44d8f5946ac391cd72138132d04ff02f\n", + "4622844d38e2: Mounted from azureml/azureml_44d8f5946ac391cd72138132d04ff02f\n", + "0b84c38716cb: Mounted from azureml/azureml_44d8f5946ac391cd72138132d04ff02f\n", + "fd55e46360fd: Mounted from azureml/azureml_44d8f5946ac391cd72138132d04ff02f\n", + "9a3749a6223b: Mounted from azureml/azureml_44d8f5946ac391cd72138132d04ff02f\n", + "9b528e5e3ae3: Mounted from azureml/azureml_44d8f5946ac391cd72138132d04ff02f\n", + "5705f94592d7: Mounted from azureml/azureml_44d8f5946ac391cd72138132d04ff02f\n", + "f08bd7cda03f: Mounted from azureml/azureml_44d8f5946ac391cd72138132d04ff02f\n", + "e650edbb7d27: Mounted from azureml/azureml_44d8f5946ac391cd72138132d04ff02f\n", + "cba13f2bedf3: Mounted from azureml/azureml_44d8f5946ac391cd72138132d04ff02f\n", + "c36fc92de581: Mounted from azureml/azureml_44d8f5946ac391cd72138132d04ff02f\n", + "524881d0563d: Mounted from azureml/azureml_44d8f5946ac391cd72138132d04ff02f\n", + "6dce9683cb41: Mounted from azureml/azureml_44d8f5946ac391cd72138132d04ff02f\n", + "e79142719515: Mounted from azureml/azureml_44d8f5946ac391cd72138132d04ff02f\n", + "aeda103e78c9: Mounted from azureml/azureml_44d8f5946ac391cd72138132d04ff02f\n", + "2558e637fbff: Mounted from azureml/azureml_44d8f5946ac391cd72138132d04ff02f\n", + "f749b9b0fb21: Mounted from azureml/azureml_44d8f5946ac391cd72138132d04ff02f\n", + "d05c249e6b9f: Mounted from azureml/azureml_44d8f5946ac391cd72138132d04ff02f\n", + "48001c8a7ddb: Mounted from azureml/azureml_44d8f5946ac391cd72138132d04ff02f\n", + "fc8a172f94e8: Mounted from azureml/azureml_44d8f5946ac391cd72138132d04ff02f\n", + "e4c9c8837d21: Pushed\n", + "latest: digest: sha256:dbe64e49c9930d4352739418756f375bda00720100e528c91a1a4177681bc06d size: 6822\n", + "2020/08/31 17:27:44 Successfully pushed image: mymlamlnewea54e393.azurecr.io/azureml/azureml_e35d3781f89ea61d18a514feb0f9c27b:latest\n", + "2020/08/31 17:27:44 Step ID: acb_step_0 marked as successful (elapsed time in seconds: 1.311997)\n", + "2020/08/31 17:27:44 Step ID: acb_step_1 marked as successful (elapsed time in seconds: 226.184755)\n", + "2020/08/31 17:27:44 Populating digests for step ID: acb_step_1...\n", + "2020/08/31 17:27:46 Successfully populated digests for step ID: acb_step_1\n", + "2020/08/31 17:27:46 Step ID: acb_step_2 marked as successful (elapsed time in seconds: 10.483863)\n", + "2020/08/31 17:27:46 The following dependencies were found:\n", + "2020/08/31 17:27:46 \n", + "- image:\n", + " registry: mymlamlnewea54e393.azurecr.io\n", + " repository: azureml/azureml_e35d3781f89ea61d18a514feb0f9c27b\n", + " tag: latest\n", + " digest: sha256:dbe64e49c9930d4352739418756f375bda00720100e528c91a1a4177681bc06d\n", + " runtime-dependency:\n", + " registry: mymlamlnewea54e393.azurecr.io\n", + " repository: azureml/azureml_44d8f5946ac391cd72138132d04ff02f\n", + " tag: latest\n", + " digest: sha256:a3b27dd75d22c61e7fbec03c620b4aeced1fbae2e903519da3d0b1d275146e1d\n", + " git: {}\n", + "\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Run ID: ccw was successful after 4m5s\n", + "Package creation Succeeded\n", + "ACR: \n", + "Image: mymlamlnewea54e393.azurecr.io/tfgpu@sha256:dbe64e49c9930d4352739418756f375bda00720100e528c91a1a4177681bc06d\n" + ] + } + ], + "source": [ + "# Builds an image in ACR.\n", + "\n", + "package = Model.package(ws, [model], inference_config=inference_config,image_name=imagename, image_label=imagelabel)\n", + "package.wait_for_creation(show_output=True)\n", + "\n", + "print(\"ACR:\", package.get_container_registry)\n", + "print(\"Image:\", package.location)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Setup Azure Stack Edge \n", + "\n", + "Follow [documentation](https://review.docs.microsoft.com/en-us/azure/databox-online/azure-stack-edge-gpu-deploy-sample-module-marketplace?branch=release-preview-ase-gpu) to setup compute and validate if GPU on ASE are up and runing." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Setup Azure IoT Edge device\n", + "\n", + "Follow [documentation](https://docs.microsoft.com/en-us/azure/iot-edge/quickstart-linux) to setup a Linux VM as an Azure IoT Edge device" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Deploy container to Azure IoT Edge device" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "mymlamlnewea54e393.azurecr.io\n", + "6b736da6-3246-44dd-a0b8-b5e95484633d\n", + "mymlamlnewea54e393.azurecr.io/tfgpu:0.2\n" + ] + } + ], + "source": [ + "from azureml.core.image import ContainerImage\n", + "\n", + "acr_name = package.location.split(\"/\")[0]\n", + "reg_name = acr_name.split(\".\")[0]\n", + "subscription_id = ws.subscription_id\n", + "\n", + "print('{}'.format(acr_name))\n", + "print('{}'.format(subscription_id))\n", + "\n", + "# TODO: Derive image_location through code.\n", + "image_location = acr_name + \"/\" + imagename + \":\" + imagelabel\n", + "\n", + "print('{}'.format(image_location))\n", + "\n", + "# Fetch username, password of ACR.\n", + "from azure.mgmt.containerregistry import ContainerRegistryManagementClient\n", + "from azure.mgmt import containerregistry\n", + "\n", + "client = ContainerRegistryManagementClient(ws._auth,subscription_id)\n", + "result= client.registries.list_credentials(ws.resource_group, reg_name, custom_headers=None, raw=False)\n", + "\n", + "username = result.username\n", + "password = result.passwords[0].value\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Create a deployment.json file using the template json. Then push the deployment json file to the IoT Hub, which will then send it to the IoT Edge device. The IoT Edge agent will then pull the Docker images and run them." + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "metadata": {}, + "outputs": [], + "source": [ + "module_name = \"tfgpu\"\n", + "\n", + "file = open('iotedge-tf-template-gpu.json')\n", + "contents = file.read()\n", + "contents = contents.replace('__MODULE_NAME', module_name)\n", + "contents = contents.replace('__REGISTRY_NAME', reg_name)\n", + "contents = contents.replace('__REGISTRY_USER_NAME', username)\n", + "contents = contents.replace('__REGISTRY_PASSWORD', password)\n", + "contents = contents.replace('__REGISTRY_IMAGE_LOCATION', image_location)\n", + "with open('./deployment_gpu.json', 'wt', encoding='utf-8') as output_file:\n", + " output_file.write(contents)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Sending deployment ot the edge device " + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[\r\n", + " {\r\n", + " \"authentication\": {\r\n", + " \"symmetricKey\": {\r\n", + " \"primaryKey\": \"ldQy++gRt5PxGF1irrWn1YkImxgaJiOZ2DD56AXEKR8=\",\r\n", + " \"secondaryKey\": \"p9TAomVy2SJaYMyAp307oQiwl+IJRAyDBRA9bVS8L0I=\"\r\n", + " },\r\n", + " \"type\": \"sas\",\r\n", + " \"x509Thumbprint\": {\r\n", + " \"primaryThumbprint\": null,\r\n", + " \"secondaryThumbprint\": null\r\n", + " }\r\n", + " },\r\n", + " \"cloudToDeviceMessageCount\": 0,\r\n", + " \"connectionState\": \"Disconnected\",\r\n", + " \"connectionStateUpdatedTime\": \"0001-01-01T00:00:00+00:00\",\r\n", + " \"deviceId\": \"juanedge\",\r\n", + " \"etag\": \"ODU4NTk0MTk4\",\r\n", + " \"generationId\": \"637278376910041144\",\r\n", + " \"lastActivityTime\": \"0001-01-01T00:00:00+00:00\",\r\n", + " \"managedBy\": null,\r\n", + " \"moduleId\": \"$edgeAgent\"\r\n", + " },\r\n", + " {\r\n", + " \"authentication\": {\r\n", + " \"symmetricKey\": {\r\n", + " \"primaryKey\": \"LLj2cfaRyNzJiz6vsQUzodVNJ1OWB5zjUg3hR3gXNh8=\",\r\n", + " \"secondaryKey\": \"nRfmS1gRIrOCCEdndu4GPAjhrSd/37f4IBoL3BzhoA0=\"\r\n", + " },\r\n", + " \"type\": \"sas\",\r\n", + " \"x509Thumbprint\": {\r\n", + " \"primaryThumbprint\": null,\r\n", + " \"secondaryThumbprint\": null\r\n", + " }\r\n", + " },\r\n", + " \"cloudToDeviceMessageCount\": 0,\r\n", + " \"connectionState\": \"Connected\",\r\n", + " \"connectionStateUpdatedTime\": \"2020-08-28T03:04:00.884400+00:00\",\r\n", + " \"deviceId\": \"juanedge\",\r\n", + " \"etag\": \"ODU4NTk0MjA0\",\r\n", + " \"generationId\": \"637278376910041144\",\r\n", + " \"lastActivityTime\": \"0001-01-01T00:00:00+00:00\",\r\n", + " \"managedBy\": \"iotEdge\",\r\n", + " \"moduleId\": \"$edgeHub\"\r\n", + " },\r\n", + " {\r\n", + " \"authentication\": {\r\n", + " \"symmetricKey\": {\r\n", + " \"primaryKey\": null,\r\n", + " \"secondaryKey\": null\r\n", + " },\r\n", + " \"type\": \"none\",\r\n", + " \"x509Thumbprint\": {\r\n", + " \"primaryThumbprint\": null,\r\n", + " \"secondaryThumbprint\": null\r\n", + " }\r\n", + " },\r\n", + " \"cloudToDeviceMessageCount\": 0,\r\n", + " \"connectionState\": \"Disconnected\",\r\n", + " \"connectionStateUpdatedTime\": \"0001-01-01T00:00:00+00:00\",\r\n", + " \"deviceId\": \"juanedge\",\r\n", + " \"etag\": \"OTkzMjkwNjMx\",\r\n", + " \"generationId\": \"637278379980600571\",\r\n", + " \"lastActivityTime\": \"0001-01-01T00:00:00+00:00\",\r\n", + " \"managedBy\": \"iotEdge\",\r\n", + " \"moduleId\": \"VisionSampleModule\"\r\n", + " },\r\n", + " {\r\n", + " \"authentication\": {\r\n", + " \"symmetricKey\": {\r\n", + " \"primaryKey\": \"7kfYZjG4bHGVthMQhRWv8kIPjRibUs7jpHkk9/FCnJU=\",\r\n", + " \"secondaryKey\": \"eq6QIaL7+JCDWUauk582zikO3QXNcc9zwaj4RfchpvE=\"\r\n", + " },\r\n", + " \"type\": \"sas\",\r\n", + " \"x509Thumbprint\": {\r\n", + " \"primaryThumbprint\": null,\r\n", + " \"secondaryThumbprint\": null\r\n", + " }\r\n", + " },\r\n", + " \"cloudToDeviceMessageCount\": 0,\r\n", + " \"connectionState\": \"Disconnected\",\r\n", + " \"connectionStateUpdatedTime\": \"2020-08-29T13:29:25.269791+00:00\",\r\n", + " \"deviceId\": \"juanedge\",\r\n", + " \"etag\": \"MTkyMjAzMzYy\",\r\n", + " \"generationId\": \"637342556476560246\",\r\n", + " \"lastActivityTime\": \"0001-01-01T00:00:00+00:00\",\r\n", + " \"managedBy\": \"iotEdge\",\r\n", + " \"moduleId\": \"tfgpu\"\r\n", + " }\r\n", + "]\r\n", + "\u001b[0m" + ] + } + ], + "source": [ + "!az iot edge set-modules --device-id juanedge --hub-name yadavmAiMLGpu --content deployment_gpu.json" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Test the web service\n", + "We test the web sevice by passing the test images content." + ] + }, + { + "cell_type": "code", + "execution_count": 27, + "metadata": {}, + "outputs": [], + "source": [ + "#downloading labels for imagenet that resnet model was trained on \n", + "import requests\n", + "classes_entries = requests.get(\"https://raw.githubusercontent.com/Lasagne/Recipes/master/examples/resnet50/imagenet_classes.txt\").text.splitlines()" + ] + }, + { + "cell_type": "code", + "execution_count": 60, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Found a ::snow leopard, ounce, Panthera uncia\n", + "CPU times: user 4.33 ms, sys: 0 ns, total: 4.33 ms\n", + "Wall time: 26.1 ms\n" + ] + } + ], + "source": [ + "%%time\n", + "import requests\n", + "\n", + "test_sample = open('snowleopardgaze.jpg', 'rb').read()\n", + "\n", + "try:\n", + " scoring_uri = 'http://51.141.178.47:5001/score'\n", + " \n", + " # Set the content type\n", + " headers = {'Content-Type': 'application/json'}\n", + "\n", + " # Make the request\n", + " resp = requests.post(scoring_uri, test_sample, headers=headers) \n", + " \n", + " print(\"Found a ::\" + classes_entries[int(resp.text.strip(\"[]\")) - 1] )\n", + "except KeyError as e:\n", + " print(str(e))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Clean up\n", + "Delete the service, image, model and compute target" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "%%time\n", + "aks_service.delete()\n", + "model.delete()\n", + "gpu_cluster.delete()\n" + ] + } + ], + "metadata": { + "authors": [ + { + "name": "vaidyas" + } + ], + "kernelspec": { + "display_name": "azureml_py36_automl", + "language": "python", + "name": "conda-env-azureml_py36_automl-py" + }, + "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.9" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/machine-learning-notebooks/gpu-accleration-onedge/snowleopardgaze.jpg b/machine-learning-notebooks/gpu-accleration-onedge/snowleopardgaze.jpg new file mode 100644 index 000000000..80450160b Binary files /dev/null and b/machine-learning-notebooks/gpu-accleration-onedge/snowleopardgaze.jpg differ