Skip to content

Commit 053c4a4

Browse files
committed
Improved exception handling in custom vision sample
1 parent 55c6312 commit 053c4a4

File tree

1 file changed

+25
-25
lines changed

1 file changed

+25
-25
lines changed

articles/iot-edge/tutorial-deploy-custom-vision.md

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ services: iot-edge
55
author: kgremban
66
manager: philmea
77
ms.author: kgremban
8-
ms.date: 10/15/2019
8+
ms.date: 01/15/2020
99
ms.topic: tutorial
1010
ms.service: iot-edge
1111
ms.custom: mvc
@@ -38,31 +38,31 @@ In this tutorial, you learn how to:
3838
>[!TIP]
3939
>This tutorial is a simplified version of the [Custom Vision and Azure IoT Edge on a Raspberry Pi 3](https://github.com/Azure-Samples/Custom-vision-service-iot-edge-raspberry-pi) sample project. This tutorial was designed to run on a cloud VM and uses static images to train and test the image classifier, which is useful for someone just starting to evaluate Custom Vision on IoT Edge. The sample project uses physical hardware and sets up a live camera feed to train and test the image classifier, which is useful for someone who wants to try a more detailed, real-life scenario.
4040
41-
Before beginning this tutorial, you should have gone through the previous tutorial to set up your environment for Linux container development: [Develop IoT Edge modules for Linux devices](tutorial-develop-for-linux.md). By completing that tutorial, you should have the following prerequisites in place:
41+
Before beginning this tutorial, you should have gone through the previous tutorial to set up your environment for Linux container development: [Develop IoT Edge modules for Linux devices](tutorial-develop-for-linux.md). By completing that tutorial, you should have the following prerequisites in place:
4242

4343
* A free or standard-tier [IoT Hub](../iot-hub/iot-hub-create-through-portal.md) in Azure.
4444
* A [Linux device running Azure IoT Edge](quickstart-linux.md)
4545
* A container registry, like [Azure Container Registry](https://docs.microsoft.com/azure/container-registry/).
4646
* [Visual Studio Code](https://code.visualstudio.com/) configured with the [Azure IoT Tools](https://marketplace.visualstudio.com/items?itemName=vsciot-vscode.azure-iot-tools).
4747
* [Docker CE](https://docs.docker.com/install/) configured to run Linux containers.
4848

49-
To develop an IoT Edge module with the Custom Vision service, install the following additional prerequisites on your development machine:
49+
To develop an IoT Edge module with the Custom Vision service, install the following additional prerequisites on your development machine:
5050

5151
* [Python](https://www.python.org/downloads/)
5252
* [Git](https://git-scm.com/downloads)
53-
* [Python extension for Visual Studio Code](https://marketplace.visualstudio.com/items?itemName=ms-python.python)
53+
* [Python extension for Visual Studio Code](https://marketplace.visualstudio.com/items?itemName=ms-python.python)
5454

5555
## Build an image classifier with Custom Vision
5656

5757
To build an image classifier, you need to create a Custom Vision project and provide training images. For more information about the steps that you take in this section, see [How to build a classifier with Custom Vision](../cognitive-services/custom-vision-service/getting-started-build-a-classifier.md).
5858

59-
Once your image classifier is built and trained, you can export it as a Docker container and deploy it to an IoT Edge device.
59+
Once your image classifier is built and trained, you can export it as a Docker container and deploy it to an IoT Edge device.
6060

6161
### Create a new project
6262

6363
1. In your web browser, navigate to the [Custom Vision web page](https://customvision.ai/).
6464

65-
2. Select **Sign in** and sign in with the same account that you use to access Azure resources.
65+
2. Select **Sign in** and sign in with the same account that you use to access Azure resources.
6666

6767
3. Select **New project**.
6868

@@ -82,39 +82,39 @@ Once your image classifier is built and trained, you can export it as a Docker c
8282

8383
### Upload images and train your classifier
8484

85-
Creating an image classifier requires a set of training images, as well as test images.
85+
Creating an image classifier requires a set of training images, as well as test images.
8686

87-
1. Clone or download sample images from the [Cognitive-CustomVision-Windows](https://github.com/Microsoft/Cognitive-CustomVision-Windows) repo onto your local development machine.
87+
1. Clone or download sample images from the [Cognitive-CustomVision-Windows](https://github.com/Microsoft/Cognitive-CustomVision-Windows) repo onto your local development machine.
8888

8989
```cmd/sh
9090
git clone https://github.com/Microsoft/Cognitive-CustomVision-Windows.git
9191
```
9292

93-
2. Return to your Custom Vision project and select **Add images**.
93+
2. Return to your Custom Vision project and select **Add images**.
9494

95-
3. Browse to the git repo that you cloned locally, and navigate to the first image folder, **Cognitive-CustomVision-Windows / Samples / Images / Hemlock**. Select all 10 images in the folder and then **Open**.
95+
3. Browse to the git repo that you cloned locally, and navigate to the first image folder, **Cognitive-CustomVision-Windows / Samples / Images / Hemlock**. Select all 10 images in the folder and then **Open**.
9696

97-
4. Add the tag **hemlock** to this group of images and press **enter** to apply the tag.
97+
4. Add the tag **hemlock** to this group of images and press **enter** to apply the tag.
9898

99-
5. Select **Upload 10 files**.
99+
5. Select **Upload 10 files**.
100100

101101
![Upload hemlock tagged files to Custom Vision](./media/tutorial-deploy-custom-vision/upload-hemlock.png)
102102

103103
6. When the images are uploaded successfully, select **Done**.
104104

105105
7. Select **Add images** again.
106106

107-
8. Browse to the second image folder, **Cognitive-CustomVision-Windows / Samples / Images / Japanese Cherry**. Select all 10 images in the folder and then **Open**.
107+
8. Browse to the second image folder, **Cognitive-CustomVision-Windows / Samples / Images / Japanese Cherry**. Select all 10 images in the folder and then **Open**.
108108

109-
9. Add the tag **japanese cherry** to this group of images and press **enter** to apply the tag.
109+
9. Add the tag **japanese cherry** to this group of images and press **enter** to apply the tag.
110110

111-
10. Select **Upload 10 files**. When the images are uploaded successfully, select **Done**.
111+
10. Select **Upload 10 files**. When the images are uploaded successfully, select **Done**.
112112

113-
11. When both sets of images are tagged and uploaded, select **Train** to train the classifier.
113+
11. When both sets of images are tagged and uploaded, select **Train** to train the classifier.
114114

115115
### Export your classifier
116116

117-
1. After training your classifier, select **Export** on the Performance page of the classifier.
117+
1. After training your classifier, select **Export** on the Performance page of the classifier.
118118

119119
![Export your trained image classifier](./media/tutorial-deploy-custom-vision/export.png)
120120

@@ -259,7 +259,8 @@ In this section, you add a new module to the same CustomVisionSolution and provi
259259
print("Response from classification service: (" + str(response.status_code) + ") " + json.dumps(response.json()) + "\n")
260260
except Exception as e:
261261
print(e)
262-
print("Response from classification service: (" + str(response.status_code))
262+
print("No response from classification service")
263+
return None
263264

264265
return json.dumps(response.json())
265266

@@ -278,7 +279,8 @@ In this section, you add a new module to the same CustomVisionSolution and provi
278279

279280
while True:
280281
classification = sendFrameForProcessing(imagePath, imageProcessingEndpoint)
281-
send_to_hub(classification)
282+
if classification:
283+
send_to_hub(classification)
282284
time.sleep(10)
283285

284286
except KeyboardInterrupt:
@@ -322,15 +324,15 @@ Instead of using a real camera to provide an image feed for this scenario, we're
322324

323325
3. Browse to your IoT Edge solution directory and paste the test image in the **modules** / **cameraCapture** folder. The image should be in the same folder as the main.py file that you edited in the previous section.
324326

325-
3. In Visual Studio Code, open the **Dockerfile.amd64** file for the cameraCapture module.
327+
4. In Visual Studio Code, open the **Dockerfile.amd64** file for the cameraCapture module.
326328

327-
4. After the line that establishes the working directory, `WORKDIR /app`, add the following line of code:
329+
5. After the line that establishes the working directory, `WORKDIR /app`, add the following line of code:
328330

329331
```Dockerfile
330332
ADD ./test_image.jpg .
331333
```
332334

333-
5. Save the Dockerfile.
335+
6. Save the Dockerfile.
334336

335337
### Prepare a deployment manifest
336338

@@ -354,7 +356,7 @@ The IoT Edge extension for Visual Studio Code provides a template in each IoT Ed
354356

355357
If you named your Custom Vision module something other than *classifier*, update the image-processing endpoint value to match.
356358

357-
5. At the bottom of the file, update the **routes** parameter for the $edgeHub module. You want to route the prediction results from cameraCapture to IoT Hub.
359+
6. At the bottom of the file, update the **routes** parameter for the $edgeHub module. You want to route the prediction results from cameraCapture to IoT Hub.
358360

359361
```json
360362
"routes": {
@@ -406,7 +408,6 @@ From Visual Studio Code, right-click on the name of your IoT Edge device and sel
406408

407409
The results from the Custom Vision module, which are sent as messages from the cameraCapture module, include the probability that the image is of either a hemlock or cherry tree. Since the image is hemlock, you should see the probability as 1.0.
408410

409-
410411
## Clean up resources
411412

412413
If you plan to continue to the next recommended article, you can keep the resources and configurations that you created and reuse them. You can also keep using the same IoT Edge device as a test device.
@@ -415,7 +416,6 @@ Otherwise, you can delete the local configurations and the Azure resources that
415416

416417
[!INCLUDE [iot-edge-clean-up-cloud-resources](../../includes/iot-edge-clean-up-cloud-resources.md)]
417418

418-
419419
## Next steps
420420

421421
In this tutorial, you trained a Custom Vision model and deployed it as a module onto an IoT Edge device. Then you built a module that can query the image classification service and report its results back to IoT Hub.

0 commit comments

Comments
 (0)