From ce3214b7c6af8b114473311bc6b2b481cc479d35 Mon Sep 17 00:00:00 2001 From: Sheri Gilley Date: Tue, 16 Oct 2018 17:33:24 -0500 Subject: [PATCH] fix name --- .../how-to-deploy-to-aci.py | 4 +-- docs/how-to-deploy-to-aci/utils.py | 27 +++++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 docs/how-to-deploy-to-aci/utils.py diff --git a/docs/how-to-deploy-to-aci/how-to-deploy-to-aci.py b/docs/how-to-deploy-to-aci/how-to-deploy-to-aci.py index 0ff289d2..13252ddd 100644 --- a/docs/how-to-deploy-to-aci/how-to-deploy-to-aci.py +++ b/docs/how-to-deploy-to-aci/how-to-deploy-to-aci.py @@ -6,10 +6,10 @@ print('SDK version' + azureml.core.VERSION) # PREREQ: load workspace info # import azureml.core -# +# from azureml.core import Workspace ws = Workspace.from_config() -# +# scorepy_content = "import json\nimport numpy as np\nimport os\nimport pickle\nfrom sklearn.externals import joblib\nfrom sklearn.linear_model import LogisticRegression\n\nfrom azureml.core.model import Model\n\ndef init():\n global model\n # retreive the path to the model file using the model name\n model_path = Model.get_model_path('sklearn_mnist')\n model = joblib.load(model_path)\n\ndef run(raw_data):\n data = np.array(json.loads(raw_data)['data'])\n # make prediction\n y_hat = model.predict(data)\n return json.dumps(y_hat.tolist())" print(scorepy_content) diff --git a/docs/how-to-deploy-to-aci/utils.py b/docs/how-to-deploy-to-aci/utils.py new file mode 100644 index 00000000..98170ada --- /dev/null +++ b/docs/how-to-deploy-to-aci/utils.py @@ -0,0 +1,27 @@ +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. + +import gzip +import numpy as np +import struct + + +# load compressed MNIST gz files and return numpy arrays +def load_data(filename, label=False): + with gzip.open(filename) as gz: + struct.unpack('I', gz.read(4)) + n_items = struct.unpack('>I', gz.read(4)) + if not label: + n_rows = struct.unpack('>I', gz.read(4))[0] + n_cols = struct.unpack('>I', gz.read(4))[0] + res = np.frombuffer(gz.read(n_items[0] * n_rows * n_cols), dtype=np.uint8) + res = res.reshape(n_items[0], n_rows * n_cols) + else: + res = np.frombuffer(gz.read(n_items[0]), dtype=np.uint8) + res = res.reshape(n_items[0], 1) + return res + + +# one-hot encode a 1-D array +def one_hot_encode(array, num_of_classes): + return np.eye(num_of_classes)[array.reshape(-1)]