Skip to content

Commit 1613d3f

Browse files
committed
review edits
1 parent d24d52d commit 1613d3f

File tree

1 file changed

+26
-23
lines changed

1 file changed

+26
-23
lines changed

articles/cognitive-services/Custom-Vision-Service/iot-visual-alerts-tutorial.md

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ If you don't have an Azure subscription, create a [free account](https://azure.m
3232
## Prerequisites
3333

3434
* [!INCLUDE [create-resources](includes/create-resources.md)]
35+
> [!IMPORTANT]
36+
> This project needs to be a **Compact** image classification project, because we will be exporting the model to ONNX later.
3537
* You'll also need to [create an IoT Hub resource](https://ms.portal.azure.com/#create/Microsoft.IotHub) on Azure.
3638
* [Visual Studio 2015 or later](https://www.visualstudio.com/downloads/)
3739
* Optionally, an IoT device running Windows 10 IoT Core version 17763 or higher. You can also run the app directly from your PC.
@@ -42,11 +44,11 @@ If you don't have an Azure subscription, create a [free account](https://azure.m
4244
The IoT Visual Alerts app runs in a continuous loop, switching between four different states as appropriate:
4345

4446
* **No Model**: A no-op state. The app will continually sleep for one second and check the camera.
45-
* **Capturing Training Images**: In this state, the app captures a picture and uploads it as a training image to the target Custom Vision project. The app then sleeps for 500 ms and repeats the procedure until the set maximum number of images are captured. Then it starts the training of the Custom Vision model.
47+
* **Capturing Training Images**: In this state, the app captures a picture and uploads it as a training image to the target Custom Vision project. The app then sleeps for 500 ms and repeats the operation until the set target number of images are captured. Then it triggers the training of the Custom Vision model.
4648
* **Waiting For Trained Model**: In this state, the app calls the Custom Vision API every second to check whether the target project contains a trained iteration. When it finds one, it downloads the corresponding ONNX model to a local file and switches to the **Scoring** state.
47-
* **Scoring**: In this state, the app uses Windows ML to evaluate a single frame from the camera against the exported ONNX model. The resulting image classification is displayed on the screen and sent as a message to the IoT Hub. The app then sleeps for one second before scoring a new frame.
49+
* **Scoring**: In this state, the app uses Windows ML to evaluate a single frame from the camera against the local ONNX model. The resulting image classification is displayed on the screen and sent as a message to the IoT Hub. The app then sleeps for one second before scoring a new image.
4850

49-
## Understand source code structure
51+
## Understand the code structure
5052

5153
The following files handle the main functionality of the app.
5254

@@ -58,67 +60,68 @@ The following files handle the main functionality of the app.
5860
| [CustomVision\CustomVisionONNXModel.cs](https://github.com/Azure-Samples/Cognitive-Services-Vision-Solution-Templates/blob/master/IoTVisualAlerts/CustomVision/CustomVisionONNXModel.cs) | This class is a wrapper that handles integration with Windows ML for loading the ONNX model and scoring images against it.|
5961
| [IoTHub\IotHubWrapper.cs](https://github.com/Azure-Samples/Cognitive-Services-Vision-Solution-Templates/blob/master/IoTVisualAlerts/IoTHub/IotHubWrapper.cs) | This class is a wrapper that handles integration with IoT Hub for uploading scoring results to Azure.|
6062

61-
## Setup
63+
## Set up the Visual Alerts app
64+
65+
Follow these steps to get the IoT Visual Alerts app running on your PC or IoT device.
6266

6367
1. Clone or download the [IoTVisualAlerts sample](https://github.com/Azure-Samples/Cognitive-Services-Vision-Solution-Templates/tree/master/IoTVisualAlerts) on GitHub.
6468
1. Open the solution _IoTVisualAlerts.sln_ in Visual Studio
65-
1. Set up the Custom Vision project:
69+
1. Integrate your Custom Vision project:
6670
1. In the _CustomVision\CustomVisionServiceWrapper.cs_ script, update the `ApiKey` variable with your training key.
6771
1. Then update the `Endpoint` variable with the endpoint URL associated with your key.
6872
1. Update the `targetCVSProjectGuid` variable with the corresponding ID of the Custom Vision project that you want to use.
69-
> [!IMPORTANT]
70-
> This project needs to be a **Compact** image classification project, because we will be exporting the model to ONNX later.
7173
1. Set up the IoT Hub resource:
7274
1. In the _IoTHub\IotHubWrapper.cs_ script, update the `s_connectionString` variable with the proper connection string for your device.
7375
1. On the Azure portal, load your IoT Hub instance, click on **IoT devices** under **Explorers**, select on your target device (or create one if needed), and find the connection string under **Primary Connection String**. The string will contain your IoT Hub name, device ID, and shared access key; it has the following format: `{your iot hub name}.azure-devices.net;DeviceId={your device id};SharedAccessKey={your access key}`.
7476

75-
## Run the sample
77+
## Run the app
7678

77-
If you're running the sample on your PC, select **Local Machine** for the target device in Visual Studio, and select **x64** or **x86** for the target platform. Then press F5 to run the program. The app should start and display the live feed from the camera and a status message.
79+
If you're running the app on your PC, select **Local Machine** for the target device in Visual Studio, and select **x64** or **x86** for the target platform. Then press F5 to run the program. The app should start and display the live feed from the camera and a status message.
7880

7981
If you're deploying to a IoT device with an ARM processor, you'll need to select **ARM** as the target platform and **Remote Machine** as the target device. Provide the IP address of your device when prompted (it must be on the same network as your PC). You can get the IP Address from the Windows IoT default app once you boot the device and connect it to the network. Press F5 to run the program.
8082

8183
When you run the app for the first time, it won't have any knowledge of visual states. It will display a status message that no model is available.
8284

8385
## Capture training images
8486

85-
To set up a model, you need to put the app in the **Capturing Training Images** state. Do one of the following steps:
87+
To set up a model, you need to put the app in the **Capturing Training Images** state. Take one of the following steps:
8688
* If you're running the app on PC, use the button on the top-right corner of the UI.
87-
* If you're running the app on an IoT device, call the `EnterLearningMode` method on the device through the IoT Hub. You can call it through the device entry in the IoT Hub menu in Azure, or with a tool such as [IoT Hub Device Explorer](https://github.com/Azure/azure-iot-sdk-csharp/tree/master/tools/DeviceExplorer).
89+
* If you're running the app on an IoT device, call the `EnterLearningMode` method on the device through the IoT Hub. You can call it through the device entry in the IoT Hub menu on the Azure portal, or with a tool such as [IoT Hub Device Explorer](https://github.com/Azure/azure-iot-sdk-csharp/tree/master/tools/DeviceExplorer).
8890

89-
When the app enters the **Capturing Training Images** state, it will capture about two images every second until it's reached the target number of images. By default, this is 30 images, but you can set this parameter by passing the desired number as an argument to the `EnterLearningMode` IoT Hub method.
91+
When the app enters the **Capturing Training Images** state, it will capture about two images every second until it has reached the target number of images. By default, this is 30 images, but you can set this parameter by passing the desired number as an argument to the `EnterLearningMode` IoT Hub method.
9092

9193
While the app is capturing images, you must expose the camera to the types of visual states that you want to detect (for example, an empty room, a room with
9294
people, an empty desk, a desk with a toy truck, and so on).
9395

94-
## Build a Custom Vision model
96+
## Train the Custom Vision model
9597

9698
Once the app has finished capturing images, it will upload them and then switch to the **Waiting For Trained Model** state. At this point, you need to go to the [Custom Vision portal](https://www.customvision.ai/) and build a model based on the new training images. The following animation shows an example of this process.
9799

98100
![Animation: tagging multiple images of bananas](./media/iot-visual-alerts-tutorial/labeling.gif)
99101

100102
To repeat this process with your own scenario:
103+
101104
1. Sign in to the [Custom Vision portal](http://customvision.ai).
102-
1. Find your target project, which should have all the training images that the app uploaded.
103-
1. For each visual state that you want to identify, select the appropriate images and manually apply a tag.
104-
* For example, if your goal is to distinguish between an empty room and a room with people in it, we recommend tagging five or more images with people as a new class (**People**, for instance), and tagging five or more images without people as the **Negative** tag. This will help the model differentiate between the two states.
105+
1. Find your target project, which should now have all the training images that the app uploaded.
106+
1. For each visual state that you want to identify, select the appropriate images and manually apply the tag.
107+
* For example, if your goal is to distinguish between an empty room and a room with people in it, we recommend tagging five or more images with people as a new class, **People**, and tagging five or more images without people as the **Negative** tag. This will help the model differentiate between the two states.
105108
* As another example, if your goal is to approximate how full a shelf is, then you might use tags such as **EmptyShelf**, **PartiallyFullShelf**, and **FullShelf**.
106-
1. When you're finished, select the **Train** button
107-
1. Once training is complete, the app on your PC or IoT device will detect that a trained iteration is available. It will start the process of exporting the trained model to ONNX and downloading it to the device.
109+
1. When you're finished, select the **Train** button.
110+
1. Once training is complete, the app will detect that a trained iteration is available. It will start the process of exporting the trained model to ONNX and downloading it to the device.
108111

109112
## Use the trained model
110113

111114
Once the app downloads the trained model, it will switch to the **Scoring** state and start scoring images from the camera in a continuous loop.
112115

113-
For each captured image, the app will display the top tag on the screen. If it doesn't recognize the visual state, it will display **No Matches**). The app also sends these messages to the IoT Hub as messages, and if there is a class being detected, the message will include the label, the confidence score, and a property called `detectedClassAlert`, which can be used from IoT Hub clients interested in doing fast message routing based on properties.
116+
For each captured image, the app will display the top tag on the screen. If it doesn't recognize the visual state, it will display **No Matches**). The app also sends these messages to the IoT Hub, and if there is a class being detected, the message will include the label, the confidence score, and a property called `detectedClassAlert`, which can be used by IoT Hub clients interested in doing fast message routing based on properties.
114117

115118
In addition, the sample uses a [Sense HAT library](https://github.com/emmellsoft/RPi.SenseHat) to detect when it's running on a Raspberry Pi with a Sense HAT unit, so it can use it as an output display by setting all display lights to red whenever it detects a class and blank when it doesn't detect anything.
116119

117-
## App life cycle
120+
## Reuse the app
118121

119122
If you'd like to reset the app back to its original state, you can do so by clicking on the button on the top-right corner of the UI, or by invoking the method `DeleteCurrentModel` through the IoT Hub.
120123

121-
At any point, you can redo the step of uploading training images by clicking the top-right UI button or calling the `EnterLearningMode` method again.
124+
At any point, you can repeat the step of uploading training images by clicking the top-right UI button or calling the `EnterLearningMode` method again.
122125

123126
If you're running the app on a device and need to retrieve the IP address again (to establish a remote connection through the [Windows IoT Remote Client](https://www.microsoft.com/p/windows-iot-remote-client/9nblggh5mnxz#activetab=pivot:overviewtab), for example), you can call the `GetIpAddress` method through IoT Hub.
124127

@@ -130,10 +133,10 @@ Delete your Custom Vision project if you no longer want to maintain it. On the [
130133

131134
## Next steps
132135

133-
In this tutorial, you set up and ran an application that detects visual state information on an IoT device and sends the results to a central repository. Next, explore the source code on GitHub or make one of the suggested modifications below.
136+
In this tutorial, you set up and ran an application that detects visual state information on an IoT device and sends the results to the IoT Hub. Next, explore the source code further or make one of the suggested modifications below.
134137

135138
> [!div class="nextstepaction"]
136-
> [IoTVisualAlerts sample](https://github.com/Azure-Samples/Cognitive-Services-Vision-Solution-Templates/tree/master/IoTVisualAlerts)
139+
> [IoTVisualAlerts sample (GitHub)](https://github.com/Azure-Samples/Cognitive-Services-Vision-Solution-Templates/tree/master/IoTVisualAlerts)
137140
138141
* Add an IoT Hub method to switch the app directly to the **Waiting For Trained Model** state. This way, you can train the model with images that aren't captured by the device itself and then push the new model to the device on command.
139142
* Follow the [Visualize real-time sensor data](https://docs.microsoft.com/azure/iot-hub/iot-hub-live-data-visualization-in-power-bi) tutorial to create a Power BI Dashboard to visualize the IoT Hub alerts sent by the sample.

0 commit comments

Comments
 (0)