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
This article provides an introduction to field-programmable gate arrays (FPGA), and shows you how to deploy your models using Azure Machine Learning to an Azure FPGA.
20
+
This article provides an introduction to field-programmable gate arrays (FPGA), and shows you how to deploy your models using [Azure Machine Learning](overview-what-is-azure-ml.md) to an Azure FPGA.
21
21
22
22
FPGAs contain an array of programmable logic blocks, and a hierarchy of reconfigurable interconnects. The interconnects allow these blocks to be configured in various ways after manufacturing. Compared to other chips, FPGAs provide a combination of programmability and performance.
23
23
@@ -77,9 +77,9 @@ The following scenarios use FPGAs:
You can deploy a model as a web service on FPGAs with Azure Machine Learning Hardware Accelerated Models. Using FPGAs provides ultra-low latency inference, even with a single batch size. Inference, or model scoring, is the phase where the deployed model is used for prediction, most commonly on production data.
82
+
You can deploy a model as a web service on FPGAs with [Azure Machine Learning Hardware Accelerated Models](https://docs.microsoft.com/python/api/azureml-accel-models/azureml.accel?view=azure-ml-py). Using FPGAs provides ultra-low latency inference, even with a single batch size. Inference, or model scoring, is the phase where the deployed model is used for prediction, most commonly on production data.
83
83
84
84
### Prerequisites
85
85
@@ -114,7 +114,7 @@ You can deploy a model as a web service on FPGAs with Azure Machine Learning Har
114
114
pip install --upgrade azureml-accel-models[cpu]
115
115
```
116
116
117
-
## 1. Create and containerize models
117
+
### 1. Create and containerize models
118
118
119
119
This document will describe how to create a TensorFlow graph to preprocess the input image, make it a featurizer using ResNet 50 on an FPGA, and then run the features through a classifier trained on the ImageNet data set.
120
120
@@ -128,189 +128,170 @@ Follow the instructions to:
128
128
129
129
Use the [Azure Machine Learning SDK for Python](https://docs.microsoft.com/python/api/overview/azure/ml/intro?view=azure-ml-py) to create a service definition. A service definition is a file describing a pipeline of graphs (input, featurizer, and classifier) based on TensorFlow. The deployment command automatically compresses the definition and graphs into a ZIP file, and uploads the ZIP to Azure Blob storage. The DNN is already deployed to run on the FPGA.
The input to the web service is a JPEG image. The first step is to decode the JPEG image and preprocess it. The JPEG images are treated as strings and the result are tensors that will be the input to the ResNet 50 model.
148
-
149
-
```python
150
-
# Input images as a two-dimensional tensor containing an arbitrary number of images represented a strings
151
-
import azureml.accel.models.utils as utils
152
-
tf.reset_default_graph()
153
-
154
-
in_images = tf.placeholder(tf.string)
155
-
image_tensors = utils.preprocess_array(in_images)
156
-
print(image_tensors.shape)
157
-
```
158
-
159
-
### Load featurizer
160
-
161
-
Initialize the model and download a TensorFlow checkpoint of the quantized version of ResNet50 to be used as a featurizer. You may replace "QuantizedResnet50" in the code snippet below with by importing other deep neural networks:
162
-
163
-
- QuantizedResnet152
164
-
- QuantizedVgg16
165
-
- Densenet121
166
-
167
-
```python
168
-
from azureml.accel.models import QuantizedResnet50
This classifier has been trained on the ImageNet data set. Examples for transfer learning and training your customized weights are available in the set of [sample notebooks](https://aka.ms/aml-notebooks).
print("Saving model in {}".format(model_save_path))
194
-
195
-
with tf.Session() as sess:
196
-
model_graph.restore_weights(sess)
197
-
tf.saved_model.simple_save(sess, model_save_path,
198
-
inputs={'images': in_images},
199
-
outputs={'output_alias': classifier_output})
200
-
```
201
-
202
-
### Save input and output tensors
203
-
The input and output tensors that were created during the preprocessing and classifier steps will be needed for model conversion and inference.
204
-
205
-
```python
206
-
input_tensors = in_images.name
207
-
output_tensors = classifier_output.name
208
-
209
-
print(input_tensors)
210
-
print(output_tensors)
211
-
```
212
-
213
-
> [!IMPORTANT]
214
-
> Save the input and output tensors because you will need them for model conversion and inference requests.
215
-
216
-
The available models and the corresponding default classifier output tensors are below, which is what you would use for inference if you used the default classifier.
[Register](concept-model-management-and-deployment.md) the model by using the SDK with the ZIP file in Azure Blob storage. Adding tags and other metadata about the model helps you keep track of your trained models.
Convert the TensorFlow graph to the Open Neural Network Exchange format ([ONNX](https://onnx.ai/)). You will need to provide the names of the input and output tensors, and these names will be used by your client when you consume the web service.
The converted model and all dependencies are added to a Docker image. This Docker image can then be deployed and instantiated. Supported deployment targets include AKS in the cloud or an edge device such as [Azure Data Box Edge](https://docs.microsoft.com/azure/databox-online/data-box-edge-overview). You can also add tags and descriptions for your registered Docker image.
2. Preprocess image. The input to the web service is a JPEG image. The first step is to decode the JPEG image and preprocess it. The JPEG images are treated as strings and the result are tensors that will be the input to the ResNet 50 model.
144
+
145
+
```python
146
+
# Input images as a two-dimensional tensor containing an arbitrary number of images represented a strings
147
+
import azureml.accel.models.utils as utils
148
+
tf.reset_default_graph()
149
+
150
+
in_images = tf.placeholder(tf.string)
151
+
image_tensors = utils.preprocess_array(in_images)
152
+
print(image_tensors.shape)
153
+
```
154
+
155
+
1. Load featurizer. Initialize the model and download a TensorFlow checkpoint of the quantized version of ResNet50 to be used as a featurizer. You may replace "QuantizedResnet50" in the code snippet below with by importing other deep neural networks:
156
+
157
+
- QuantizedResnet152
158
+
- QuantizedVgg16
159
+
- Densenet121
160
+
161
+
```python
162
+
from azureml.accel.models import QuantizedResnet50
1. Add a classifier. This classifier has been trained on the ImageNet data set. Examples for transfer learning and training your customized weights are available in the set of [sample notebooks](https://aka.ms/aml-notebooks).
1. Save the model. Now that the preprocessor, ResNet 50 featurizer, and the classifier have been loaded, save the graph and associated variables as a model.
print("Saving model in {}".format(model_save_path))
184
+
185
+
with tf.Session() as sess:
186
+
model_graph.restore_weights(sess)
187
+
tf.saved_model.simple_save(sess, model_save_path,
188
+
inputs={'images': in_images},
189
+
outputs={'output_alias': classifier_output})
190
+
```
191
+
192
+
1. Save input and output tensors. The input and output tensors that were created during the preprocessing and classifier steps will be needed for model conversion and inference.
193
+
194
+
```python
195
+
input_tensors = in_images.name
196
+
output_tensors = classifier_output.name
197
+
198
+
print(input_tensors)
199
+
print(output_tensors)
200
+
```
201
+
202
+
> [!IMPORTANT]
203
+
> Save the input and output tensors because you will need them for model conversion and inference requests.
204
+
205
+
The available models and the corresponding default classifier output tensors are below, which is what you would use for inference if you used the default classifier.
1. [Register](concept-model-management-and-deployment.md) the model by using the SDKwith the ZIPfilein Azure Blob storage. Adding tags and other metadata about the model helps you keep track of your trained models.
1. Convert the TensorFlow graph to the Open Neural Network Exchange format ([ONNX](https://onnx.ai/)). You will need to provide the names of the input and output tensors, and these names will be used by your client when you consume the web service.
1. Create Docker image from the converted model and all dependencies. This Docker image can then be deployed and instantiated. Supported deployment targets include AKS in the cloud or an edge device such as [Azure Data Box Edge](https://docs.microsoft.com/azure/databox-online/data-box-edge-overview). You can also add tags and descriptions for your registered Docker image.
To deploy your model as a high-scale production web service, use Azure Kubernetes Service (AKS). You can create a new one using the Azure Machine Learning SDK, CLI, or [Azure Machine Learning studio](https://ml.azure.com).
0 commit comments