This sample illustrates how to leverage Microsoft Azure Custom Vision Service to create a visual alert system on the browser. It performs the following steps:
-
Trains, and exports the trained neural network to TensorFlow.JS. This saves a .zip with the model which has to be unzipped and pointed to when prompted.
-
Loads the exported model into the browser and predicts on a frame captured by the webcam
This uses React, a Javascript library which is a client-side framework for building very fast web applications. More specifically, this uses the create-react-app
tool which is ideal for single-page websites.
-
Azure Subscription and keys for an Azure Cognitive Services resource
-
Visual Studio 2017 or higher with the
ASP.NET and web development
workload -
.Net Core 2.1 or higher
-
A modern browser capable of accessing the web camera
-
A webcamera setup and ready to go
This code was based on Visual Studio's template when creating a new ASP.NET Core Web Application with the React.js template. The folder ClinetApp is akin to the one made by a create-react-app
application. The experienced React developer can use their own server framework.
File or folder | Description |
---|---|
ClientApp | The folder of the create-react-app application where npm install commands can be run |
src | Folder that has the relavant source code. This folder typically has javascript and styling files |
Home.js | The React component that does all the tasks described at the top |
layout.js | The React component that defines the spatial layout |
index.js | Calls the react-dom and the app from App.js |
App.js | Typically routes react components. |
index.html | The html for the webserver's directory index page |
- Clone or download this repository
- Open the solution ReactInBrowserVisualAlerts.sln in Visual Studio
Hit F5 or run IIS Express. This should install required npm dependencies and launch the browser. It might take about a minute the first time. Enable javascript and allow this site to use the webcam. You can change the webcam being used in your browser's settings. This downloads a .zip and the download must be enabled on the browser.
You will need to have ready the subscription key and endpoint for Cognitive Services. You can find them in the Custom Vision portal
- Fill in these credentials in the landing page
- The last input box in the landing page is for what this visual alert is for. It can be any object or person and this tag must not be empty.
- Capture at least 5 images with and without the object. This would train and export the model and it would prompt download.
- Unzip the downloaded file and when asked, use the file picker to point to the model.json and weights.bin
-
If there are errors associated with the react-dom, run
npm update react, react-dom
in theClientApp
folder on a terminal -
If you want to use your preferred version of .Net Core, you can create a new ASP.NET Core Web Application with the React.js template and simply copy the
ClientApp
folder from this solution
-
You can reuse most of the React code to create mobile applications using
react-native
. One of the changes you would have to make is change<div>
JSX tags to<View>
-
Deploy the webapp using Azure app service