IoT Programming

Build a simple machine vision application with Node-RED packages

Do you need Image Classification in your IoT project? In this blog article, we will show you an easy way to develop a ...

Do you need Image Classification in your IoT project? In this blog article, we will show you an easy way to develop a simple image classification application using Node-RED packages that are publicly available.

Who is this for? If you're new to low-code IoT programming and machine vision, this blog article will help you learn the ropes quickly and easily. If you've used Node-RED or are familiar with machine vision then you'll likely find our upcoming webinar more insightful as it tackles the challenges surrounding industrial machine vision IoT applications. Register here.

YouTube Thumbnail – 1

Toolkit: Node-RED, TensorFlow and Prescient Designer

We'll be using some open-source packages and libraries in this tutorial, so you can easily access them for this exercise.

Node-RED is an open-source software application that enables low-code programming of an IoT edge device. You'll be able to build this app quickly if you're already familiar with Node-RED. If you haven't used Node-RED before, it's still easy to get started with this introductory video.

TensorFlow.js is an open-source JavaScript library. It helps you build, train and run machine learning models in the browser and Node.js. Here's a short primer if you want to watch it.

Node-RED is focused on a single edge device, while Prescient Designer is built to scale

Node-RED and TensorFlow.js make it possible to design applications for remote monitoring, asset tracking or any other industrial application easily. However, Node-RED by itself only focuses on a single edge device, making it very difficult to scale your application to a large deployment.

However, Node-RED by itself only focuses on a single edge device, making it very difficult to scale your application to a large deployment.

Scaling Node-RED requires knowledge and experience in complex technologies and domain expertise like security, communication, protocols, orchestration and more.

That's where Prescient Designer can help. Prescient Designer is built for enterprise-class applications, with a specific focus on scaling large IoT deployments. It may look similar to Node-RED on the surface, but it's packed with advanced features like distributed programming, end-to-end security, recovery and rollback, remote collaboration built-in communication, application template solutions, and more. You can watch an overview of Prescient Designer's features here.


Getting Started with TensorFlow in Prescient Designer and Node-RED

This tutorial will work if you only have access to Node-RED, but it will be easier and more straight-forward with Prescient Designer. Watch our video tutorial to walk you through this exercise. Let's begin!

Installing Nodes from Palette Manager

Here are the required nodes you need to install from Palette Manager.

  1. node-red-contrib-browser-utils – This provides a file inject node to upload files from the browser
  2. node-red-contrib-image-output – Helps in viewing the image on the Node-RED editor.
  3. @prescient-devices/node-red-contrib-usb-camera - Enables image capturing from within Node-RED
  4. node-red-contrib-TensorFlow – Contains pre-trained TensorFlow models. 

The node-red-contrib-TensorFlow node has 4 pre-trained tensorflow models.

  1. Object Detection -- The node to identify objects in an image
  2. MediaPipe Handpose -- The node to detect fingers in a hand
  3. MobileNet -- The node to classify images with MobileNet
  4. PoseNet Model -- The node to estimate human pose

It has been developed by Kazuhito Yokoi (@kazuhitoyokoi), software engineer at Hitachi and an avid node-red contributor.

If you're using Prescient Designer, import the template using Template Browser.

Things you’ll need to successfully deploy this solution at the edge:
    1. Prescient Designer
    2. Any USB camera
    3. Raspberry pi 3+ or similar device.

If you're using Node-RED only, You can download the flow used in this tutorial here - image-classification.json.

Using MobileNet to classify images

In this demo, we will be using MobileNet to classify Images. If you want to see the full list of supported classes, you can access them here.

First, we’ll drag in the required nodes inside the flow and wire them up.

Then, click on the "Deploy" button

Test your application by adding an arbitrary image using the file-inject node to see the results

There you have it! You just successfully built your first machine vision application using TensorFlow and Node-RED. Wasn't that hard, was it?


Applying your machine vision application to multiple edge devices

If you want to use the same image classification application on many devices, you will need to scale your application. Because Node-RED is a single system app, scaling this object classification solution to many devices will require expertise in vast domains from security to orchestration and everything in between.

Scaling your solution with Prescient Designer

We can use the power of Prescient Designer to deploy this solution to one edge device or thousands of edge devices with a single click of a button.

Instead of uploading images, we'll be using a camera connected to our edge device. It performs these actions:

  • Take a picture
  • Run inference
  • Return back the result

Add (or provision) the edge device with Prescient Designer. Use ssh into the edge device and run the provisioning script found under settings. If you're not sure how to provision your edge device, you can visit our Documentation or simply follow this short tutorial video here.

Next, create a subflow. Add the following nodes to the subflow. The USB-camera node will get triggered on a message from input one and route the image to:

  • Output 1 - Encoded Image for display
  • Output 2 - The result of classification

Your overall flow should look like this:

Next, we’ll convert this sub-flow to a device. The block of code inside the sub-flow will run on the edge device provisioned in the previous step.

Then, you can deploy and test your application.

More resources

You can download the flow used in this tutorial here, or watch this video tutorial demonstration. For more IoT learning, visit our Resource Library.

In our next blog article, I will show you how you can use TensorFlow models to classify custom images based on your application requirements.

Using Machine Vision for IoT

Build a machine vision application in the cloud and run it at the edge

Want to learn more about building machine vision applications? We are hosting a webinar focused on teaching you how to build machine vision applications with TensorFlow and Node-RED on May 26 at 11AM EDT. Discover how you can use machine vision in your IoT projects with our Director of Software Development, Ashish Yadav. Register for this event now.

Similar posts

Stay informed on IoT trends and insights

Discover the business and technology insights of IoT to accelerate the success of your digital transformation strategy. Sign up for our mailing list today.