Get Informed out of Data

Full width home advertisement

Raspbian

DataScience

Post Page Advertisement [Top]

Running Tensorflow Js models on Raspberry Pi 4

Running Tensorflow Js models on Raspberry Pi 4

 Raspberry Pi 4, the modern-day embedded Opensource module that extends every possibility of taking technology to the edge.

Running full-fledge, Machine Learning models is really tough as the continuous flow of large data leads to the requirement of high power devices.

Hopefully, the introduction of the BTRFS file system could solve these issues in the coming days.

But for now, Javascript is the lightweight language to process the data, With TensorFlow js even object detection models are run at a high speed.


Let's get into the details, we need few things ready before running js models

  • Raspbian OS with Node-red 
  • Raspberry Pi Camera or else image sets to test
Node-Red is really an innovation for programmers, as programming with JavaScript for beginners is a real treat.

It is Built on Node.js, you can extend its features by creating your own nodes or taking advantage of the JavaScript and NPM ecosystem.

TensorFlow.js is an open-source JavaScript library to build, train, and run machine learning models in JavaScript environments such as the browser and Node.js.

Combining Node-RED with TensorFlow.js developers and IoT enthusiasts can more easily add machine learning functionality onto their devices.

When you have completed this code pattern, you will understand how to:

  • Create a Node-RED node that includes a TensorFlow.js model
  • Build and deploy a Node-RED application that uses a TensorFlow.js node

1. Clone the repo

First, let's get the code. From the terminal of the system, you plan on running Node-RED from, do the following:

  1. Clone the node-red-tensorflowjs repo:

    $ git clone https://github.com/IBM/node-red-tensorflowjs
    
  2. Move into the directory of the cloned repo:

    $ cd node-red-tensorflowjs
    

2. Install dependencies

cd ~/.node-red
npm install <full path>/node-red-contrib-tfjs-object-detection
npm install node-red-contrib-browser-utils node-red-contrib-play-audio node-red-contrib-image-output

Be sure to restart Node-RED with sudo systemctl restart node-red.service

The Node-RED editor can be accessed from http://localhost:1880.

However, if Node-RED is on the Raspberry Pi, you can connect to it via http://<Raspberry Pi IP>:1880.

3. Import the Node-RED flow

Once installed the node can be added and used in the flow of your Node-RED application. To import the flows available in this repo:

  1. Make sure Node-RED is running
  2. Open a browser and go to your Node-RED Editor
  3. Click on the Node-RED Menu
  4. Click on Import
  5. Select the Clipboard tab
  6. Click on select a file to import
  7. Browse to and select one of the flow files in the cloned repo
    • If trying things out locally on your browser, then use the browser-flow.json.
    • If using a Raspberry Pi with peripherals, then use the raspberrypi-flows.json.
  8. Select Import to new flow
  9. Click Import

4. Deploy the Node-RED flow

Running on a Raspberry Pi

The Raspberry Pi flows use hardware peripherals and Raspberry Pi specific nodes. This assumes you imported the raspberrypi-flows.json file.



No comments:

Post a Comment

Bottom Ad [Post Page]