Skip to content

Commit a8e72cf

Browse files
Merge pull request #220519 from santiagxf/santiagxf-patch-2
Update how-to-image-processing-batch.md
2 parents 9c49cdf + 893ffeb commit a8e72cf

File tree

1 file changed

+30
-18
lines changed

1 file changed

+30
-18
lines changed

articles/machine-learning/how-to-image-processing-batch.md

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,15 @@ Batch Endpoint can only deploy registered models so we need to register it. You
5454

5555
1. Downloading a copy of the model:
5656

57-
# [Azure ML CLI](#tab/cli)
57+
# [Azure CLI](#tab/cli)
5858

5959
```azurecli
6060
wget https://azuremlexampledata.blob.core.windows.net/data/imagenet/model.zip
6161
mkdir -p imagenet-classifier
6262
unzip model.zip -d imagenet-classifier
6363
```
6464
65-
# [Azure ML SDK for Python](#tab/sdk)
65+
# [Python](#tab/sdk)
6666
6767
```python
6868
import os
@@ -78,14 +78,14 @@ Batch Endpoint can only deploy registered models so we need to register it. You
7878
7979
2. Register the model:
8080
81-
# [Azure ML CLI](#tab/cli)
81+
# [Azure CLI](#tab/cli)
8282
8383
```azurecli
8484
MODEL_NAME='imagenet-classifier'
8585
az ml model create --name $MODEL_NAME --type "custom_model" --path "imagenet-classifier/model"
8686
```
8787
88-
# [Azure ML SDK for Python](#tab/sdk)
88+
# [Python](#tab/sdk)
8989
9090
```python
9191
model_name = 'imagenet-classifier'
@@ -163,11 +163,11 @@ One the scoring script is created, it's time to create a batch deployment for it
163163

164164
1. We need to indicate over which environment we are going to run the deployment. In our case, our model runs on `TensorFlow`. Azure Machine Learning already has an environment with the required software installed, so we can reutilize this environment. We are just going to add a couple of dependencies in a `conda.yml` file.
165165

166-
# [Azure ML CLI](#tab/cli)
166+
# [Azure CLI](#tab/cli)
167167

168168
No extra step is required for the Azure ML CLI. The environment definition will be included in the deployment file.
169169

170-
# [Azure ML SDK for Python](#tab/sdk)
170+
# [Python](#tab/sdk)
171171

172172
Let's get a reference to the environment:
173173

@@ -183,7 +183,7 @@ One the scoring script is created, it's time to create a batch deployment for it
183183
> [!NOTE]
184184
> This example assumes you have an endpoint created with the name `imagenet-classifier-batch` and a compute cluster with name `cpu-cluster`. If you don't, please follow the steps in the doc [Use batch endpoints for batch scoring](how-to-use-batch-endpoint.md).
185185
186-
# [Azure ML CLI](#tab/cli)
186+
# [Azure CLI](#tab/cli)
187187

188188
To create a new deployment under the created endpoint, create a `YAML` configuration like the following:
189189

@@ -220,7 +220,7 @@ One the scoring script is created, it's time to create a batch deployment for it
220220
az ml batch-deployment create -f deployment.yml
221221
```
222222

223-
# [Azure ML SDK for Python](#tab/sdk)
223+
# [Python](#tab/sdk)
224224

225225
To create a new deployment with the indicated environment and scoring script use the following code:
226226

@@ -275,14 +275,14 @@ For testing our endpoint, we are going to use a sample of 1000 images from the o
275275

276276
1. Let's download the associated sample data:
277277

278-
# [Azure ML CLI](#tab/cli)
278+
# [Azure CLI](#tab/cli)
279279

280280
```bash
281281
wget https://azuremlexampledata.blob.core.windows.net/data/imagenet-1000.zip
282282
unzip imagenet-1000.zip -d /tmp/imagenet-1000
283283
```
284284

285-
# [Azure ML SDK for Python](#tab/sdk)
285+
# [Python](#tab/sdk)
286286

287287
```python
288288
!wget https://azuremlexampledata.blob.core.windows.net/data/imagenet-1000.zip
@@ -291,11 +291,12 @@ For testing our endpoint, we are going to use a sample of 1000 images from the o
291291

292292
2. Now, let's create the data asset from the data just downloaded
293293

294-
# [Azure ML CLI](#tab/cli)
294+
# [Azure CLI](#tab/cli)
295295

296296
Create a data asset definition in `YAML`:
297297

298298
__imagenet-sample-unlabeled.yml__
299+
299300
```yaml
300301
$schema: https://azuremlschemas.azureedge.net/latest/data.schema.json
301302
name: imagenet-sample-unlabeled
@@ -310,7 +311,7 @@ For testing our endpoint, we are going to use a sample of 1000 images from the o
310311
az ml data create -f imagenet-sample-unlabeled.yml
311312
```
312313

313-
# [Azure ML SDK for Python](#tab/sdk)
314+
# [Python](#tab/sdk)
314315

315316
```python
316317
data_path = "/tmp/imagenet-1000"
@@ -322,12 +323,23 @@ For testing our endpoint, we are going to use a sample of 1000 images from the o
322323
description="A sample of 1000 images from the original ImageNet dataset",
323324
name=dataset_name,
324325
)
326+
```
327+
328+
Then, create the data asset:
329+
330+
```python
325331
ml_client.data.create_or_update(imagenet_sample)
326332
```
327333

334+
To get the newly created data asset, use:
335+
336+
```python
337+
imagenet_sample = ml_client.data.get(dataset_name, label="latest")
338+
```
339+
328340
3. Now that the data is uploaded and ready to be used, let's invoke the endpoint:
329341

330-
# [Azure ML CLI](#tab/cli)
342+
# [Azure CLI](#tab/cli)
331343

332344
```azurecli
333345
JOB_NAME = $(az ml batch-endpoint invoke --name $ENDPOINT_NAME --input azureml:imagenet-sample-unlabeled@latest | jq -r '.name')
@@ -336,7 +348,7 @@ For testing our endpoint, we are going to use a sample of 1000 images from the o
336348
> [!NOTE]
337349
> The utility `jq` may not be installed on every installation. You can get instructions in [this link](https://stedolan.github.io/jq/download/).
338350
339-
# [Azure ML SDK for Python](#tab/sdk)
351+
# [Python](#tab/sdk)
340352

341353
```python
342354
input = Input(type=AssetTypes.URI_FOLDER, path=imagenet_sample.id)
@@ -352,29 +364,29 @@ For testing our endpoint, we are going to use a sample of 1000 images from the o
352364
353365
4. A batch job is started as soon as the command returns. You can monitor the status of the job until it finishes:
354366

355-
# [Azure ML CLI](#tab/cli)
367+
# [Azure CLI](#tab/cli)
356368

357369
```azurecli
358370
az ml job show --name $JOB_NAME
359371
```
360372

361-
# [Azure ML SDK for Python](#tab/sdk)
373+
# [Python](#tab/sdk)
362374

363375
```python
364376
ml_client.jobs.get(job.name)
365377
```
366378

367379
5. Once the deployment is finished, we can download the predictions:
368380

369-
# [Azure ML CLI](#tab/cli)
381+
# [Azure CLI](#tab/cli)
370382

371383
To download the predictions, use the following command:
372384

373385
```azurecli
374386
az ml job download --name $JOB_NAME --output-name score --download-path ./
375387
```
376388

377-
# [Azure ML SDK for Python](#tab/sdk)
389+
# [Python](#tab/sdk)
378390

379391
```python
380392
ml_client.jobs.download(name=job.name, output_name='score', download_path='./')

0 commit comments

Comments
 (0)