You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
description: Learn how to use Microsoft SEAL to deploy an encrypted prediction service for image classification
5
5
author: luisquintanilla
6
6
ms.author: luquinta
7
-
ms.date: 05/14/2020
7
+
ms.date: 05/17/2020
8
8
services: machine-learning
9
9
ms.service: machine-learning
10
10
ms.subservice: core
@@ -14,47 +14,55 @@ ms.topic: conceptual
14
14
15
15
# How to deploy an encrypted image classification service
16
16
17
-
Learn how to deploy an image classification model as a encrypted inferencing web service in [Azure Container Instances](https://docs.microsoft.com/azure/container-instances/) (ACI). A web service is an image, in this case a Docker image, that encapsulates the scoring logic and the model itself.
17
+
Learn how to deploy an image classification model as an encrypted inferencing web service in [Azure Container Instances](https://docs.microsoft.com/azure/container-instances/) (ACI). The web service is a Docker container image that contains the model and scoring logic.
18
18
19
-
In this part of the tutorial, you use Azure Machine Learning service to:
19
+
In guide, you use Azure Machine Learning service to:
20
20
21
-
> *Set up your testing environment
22
-
> *Retrieve the model from your workspace
23
-
> *Test the model locally
24
-
> *Deploy the model to ACI
25
-
> *Test the deployed model
21
+
> *Configure your environments
22
+
> *Deploy encrypted inferencing web service
23
+
> *Prepare test data
24
+
> *Make encrypted predictions
25
+
> *Clean up resources
26
26
27
27
ACI is a great solution for testing and understanding the workflow. For scalable production deployments, consider using Azure Kubernetes Service. For more information, see [how to deploy and where](https://docs.microsoft.com/azure/machine-learning/service/how-to-deploy-and-where).
28
28
29
+
The encryption method used in this sample is homomorphic encryption (HE). Homomorphic encryption allows for computations to be done on encrypted data without requiring access to a secret (decryption) key. The results of the computations are encrypted and can be revealed only by the owner of the secret key.
30
+
29
31
## Prerequisites
30
32
31
-
Complete the model training in the [Train an image classification model with Azure Machine Learning tutorial](tutorial-train-models-with-aml.md).
33
+
This guide assumes that you have an image classification model registered in Azure Machine Learning. If not, register the model using a [pretrained model](https://github.com/Azure/MachineLearningNotebooks/raw/master/tutorials/image-classification-mnist-data/sklearn_mnist_model.pkl) or create your own by completing the [train an image classification model with Azure Machine Learning tutorial](tutorial-train-models-with-aml.md).
32
34
33
-
```python
34
-
# If you did NOT complete the tutorial, you can instead run this cell
35
-
# This will register a model and download the data needed for this tutorial
36
-
# These prerequisites are created in the training tutorial
37
-
# Feel free to skip this cell if you completed the training tutorial
35
+
## Configure local environment
38
36
39
-
# register a model
40
-
from azureml.core import Workspace
41
-
ws = Workspace.from_config()
37
+
In a Jupyter notebook
42
38
43
-
from azureml.core.model import Model
39
+
1. Import the Python packages needed for this sample.
40
+
41
+
```python
42
+
%matplotlib inline
43
+
import numpy as np
44
+
import matplotlib.pyplot as plt
45
+
46
+
import azureml.core
47
+
48
+
# display the core SDK version number
49
+
print("Azure ML SDK Version: ", azureml.core.VERSION)
50
+
```
51
+
52
+
2. Install homomorphic encryption library for secure inferencing.
44
53
45
-
model_name ="sklearn_mnist"
46
-
model = Model.register(model_path="sklearn_mnist_model.pkl",
> The `encrypted-inference` package is currently in preview.
51
56
57
+
[`encrypted-inference`](https://pypi.org/project/encrypted-inference) is a homomorphic encryption library based on [Microsoft SEAL](https://github.com/Microsoft/SEAL).
52
58
59
+
```python
60
+
!pip install encrypted-inference==0.9
53
61
```
54
62
55
-
### Setup the Environment
63
+
##Configure the inferencing environment
56
64
57
-
Add `encrypted-inference` package as a conda dependency
65
+
Create an environment for inferencing and add `encrypted-inference` package as a conda dependency.
58
66
59
67
```python
60
68
from azureml.core.environment import Environment
@@ -70,52 +78,24 @@ env.python.conda_dependencies = cd
70
78
env.register(workspace= ws)
71
79
```
72
80
73
-
## Set up the environment
74
-
75
-
Start by setting up a testing environment.
76
-
77
-
### Import packages
78
-
79
-
Import the Python packages needed for this tutorial.
80
-
81
-
```python tags=["check version"]
82
-
%matplotlib inline
83
-
import numpy as np
84
-
import matplotlib.pyplot as plt
85
-
86
-
import azureml.core
87
-
88
-
# display the core SDK version number
89
-
print("Azure ML SDK Version: ", azureml.core.VERSION)
90
-
```
91
-
92
-
#### Install Homomorphic Encryption based library for Secure Inferencing
81
+
## Deploy encrypted inferencing web service
93
82
94
-
Our library is based on [Microsoft SEAL](https://github.com/Microsoft/SEAL) and pubished to [PyPi.org](https://pypi.org/project/encrypted-inference) as an easy to use package
95
-
96
-
```python
97
-
!pip install encrypted-inference==0.9
98
-
```
99
-
100
-
## Deploy as web service
101
-
102
-
Deploy the model as a web service hosted in ACI.
83
+
Deploy the model as a web service hosted in ACI.
103
84
104
85
To build the correct environment for ACI, provide the following:
86
+
105
87
* A scoring script to show how to use the model
106
88
* A configuration file to build the ACI
107
-
*The model you trained before
89
+
*A trained model
108
90
109
91
### Create scoring script
110
92
111
-
Create the scoring script, called score.py, used by the web service call to show how to use the model.
93
+
Create the scoring script`score.py` used by the web service for inferencing.
112
94
113
95
You must include two required functions into the scoring script:
114
-
* The `init()` function, which typically loads the model into a global object. This function is run only once when the Docker container is started.
115
-
116
-
* The `run(input_data)` function uses the model to predict a value based on the input data. Inputs and outputs to the run typically use JSON for serialization and de-serialization, but other formats are supported. The function fetches homomorphic encryption based public keys that are uploaded by the service caller.
117
-
118
96
97
+
* The `init()` function, which typically loads the model into a global object. This function is run only once when the Docker container is started.
98
+
* The `run(input_data)` function uses the model to predict a value based on the input data. Inputs and outputs to the run typically use JSON for serialization and de-serialization, but other formats are supported. The function fetches homomorphic encryption based public keys that are uploaded by the service caller.
Get the scoring web service's HTTP endpoint, which accepts REST client calls. This endpoint can be shared with anyone who wants to test the web service or integrate it into an application.
213
193
214
-
```python tags=["get scoring uri"]
194
+
```python
215
195
print(service.scoring_uri)
216
196
```
217
197
218
-
### Download test data
198
+
##Prepare test data
219
199
220
-
Download the test data to the **./data/** directory
200
+
1.Download the test data. In this case, it's saved into a directory called *data*.
####Send the test data to the webservice hosted in ACI
290
+
### Send the test data to the encrypted ACI web service
318
291
319
-
Feed the test dataset to the model to get predictions. We will need to send the connection string to the blob storage where the public keys were uploaded
292
+
Provide the test dataset to the model to get predictions. We will need to send the connection string to the blob storage where the public keys were uploaded.
To keep the resource group and workspace for other tutorials and exploration, you can delete only the ACI deployment using this API call:
334
+
Delete the web service created in this sample:
362
335
363
336
```python tags=["delete web service"]
364
337
service.delete()
365
338
```
366
339
367
-
If you're not going to use what you've created here, delete the resources you just created with this quickstart so you don't incur any charges. In the Azure portal, select and delete your resource group. You can also keep the resource group, but delete a single workspace by displaying the workspace properties and selecting the Delete button.
340
+
If you no longer plan to use the Azure resources you’ve created, delete them. This prevents you from being charged for unutilized resources that are still running. See this guide on how to [clean up resources](how-to-manage-workspace#clean-up-resources) to learn more.
368
341
369
342
## Next steps
370
343
371
-
In this Azure Machine Learning tutorial, you used Python to:
0 commit comments