Skip to content

Latest commit

 

History

History
148 lines (93 loc) · 6.52 KB

File metadata and controls

148 lines (93 loc) · 6.52 KB

Edge Impulse Linux SDK for Node.js

This library lets you run machine learning models and collect sensor data on Linux machines using Node.js. This SDK is part of Edge Impulse where we enable developers to create the next generation of intelligent device solutions with embedded machine learning. Start here to learn more and train your first model.

Installation guide

Add the library to your application via:

$ npm install edge-impulse-linux

Windows offline installer (for locked-down environments)

For corporate-managed Windows devices where npm install is blocked (TLS interception, no build tools, restricted package access), this repo also supports a prebuilt Windows installer artifact via GitHub Actions.

What this installer includes

  • Bundled node.exe runtime (no separate Node.js install required)
  • Prebuilt node_modules from CI (no local node-gyp / Python toolchain required)
  • Installed CLI shims in PATH:
    • edge-impulse-linux
    • edge-impulse-linux-runner
    • edge-impulse-camera-debug

End-user requirements

  • Windows 10/11 (x64 or arm64 artifact)
  • Administrator rights to install (writes to Program Files and system PATH)
  • WSL is not required for installation, but recommended for full Linux CLI behavior

Important runtime note

This is still the Linux CLI package, packaged for Windows installation. Some commands or hardware flows that depend on Linux-specific behavior or drivers may still require Linux/WSL at runtime.

For full functionality, install WSL first from an elevated Command Prompt:

wsl --install

Build and download installer artifacts

Use the workflow in this repository:

  • ActionsBuild Windows Linux-CLI Installer

Artifacts produced:

  • edge-impulse-linux-cli-windows-x64
  • edge-impulse-linux-cli-windows-arm64

Each artifact zip contains a .exe installer.

Collecting data

Before you can classify data you'll first need to collect it. If you want to collect data from the camera or microphone on your system you can use the Edge Impulse CLI, and if you want to collect data from different sensors (like accelerometers or proprietary control systems) you can do so in a few lines of code.

Collecting data from the camera or microphone

  1. Install the Edge Impulse CLI for Linux:

    $ npm install edge-impulse-linux -g --unsafe-perm
    
  2. Start the CLI and follow the instructions:

    $ edge-impulse-linux
    
  3. That's it. Your device is now connected to Edge Impulse and you can capture data from the camera and microphone.

Collecting data from other sensors

To collect data from other sensors you'll need to write some code where you instantiate a DataForwarder object, write data samples, and finally call finalize() which uploads the data to Edge Impulse. Here's an end-to-end example.

CLI Options

You can pass in options to the CLI. Here are the key ones:

  • --disable-camera - disables the camera.
  • --disable-microphone - disable the microphone.
  • --clean - clear credentials, and re-authenticate. Use this to switch projects or devices.
  • --api-key <apikey> - set an API key, useful for automatic authentication with a new project.
  • --greengrass - utilize the AWS IoT Greengrass authentication context and AWS Secrets Manager to authenticate with a new project. See additional Greegrass notes below.
  • --help - see all options.

Greengrass Integration Note

edge-impulse-linux and edge-impulse-linux-runner can be run as a service via a custom AWS IoT Greengrass component(s). When provided with the "--greengrass" option, both services will utilize the AWS IoT Greengrass authentication context (ONLY present when launched as a AWS IoT Greengrass custom component) as well as AWS Secrets Manager to extract the api key to be used to authenticate to a new project. If the authentication context is abscent and/or incorrect, both services will simply ignore the "--greengrass" option that was provided and continue with any of the other provided options normally.

Classifying data

To classify data (whether this is from the camera, the microphone, or a custom sensor) you'll need a model file. This model file contains all signal processing code, classical ML algorithms and neural networks - and typically contains hardware optimizations to run as fast as possible. To grab a model file:

  1. Train your model in Edge Impulse.

  2. Install the Edge Impulse CLI:

    $ npm install edge-impulse-linux -g --unsafe-perm
    
  3. Download the model file via:

    $ edge-impulse-linux-runner --download modelfile.eim
    

    This downloads the file into modelfile.eim. (Want to switch projects? Add --clean)

For VLM models on certain Qualcomm targets (RB3 Gen 2, IQ-9), you can enable GPU acceleration by passing --enable-gpu to edge-impulse-linux-runner. OpenCL drivers should be configured for this to work.

Then you can start classifying realtime sensor data. We have examples for:

  • Audio - grabs data from the microphone and classifies it in realtime.
  • Audio (moving average filter) - as above, but shows how to use the moving-average filter to smooth your data and reduce false positives.
  • Camera - grabs data from a webcam and classifies it in realtime.
  • Custom data - classifies custom sensor data.

Moving average filter

To smooth your results and reduce false positives there's an implementation of a moving-average filter in this library. To use it:

const { MovingAverageFilter } = require("edge-impulse-linux");

let movingAverageFilter = new MovingAverageFilter(
    4 /* filter size, smooths over X results */,
    model.modelParameters.labels);

// classify item
let res = await runner.classify(features);

// run the filter
let filteredRes = movingAverageFilter.run(res);

Development tips

Auto-reload the runner

If you're working on something in the runner, and want to auto-recompile on changes; start with:

npm run watch-runner -- "--model-file /Users/yourname/Downloads/yourmodel-v36.eim --run-http-server 1338"