Impulses can be deployed as a C++ library. This packages all your signal processing blocks, configuration and learning blocks up into a single package. You can include this package in your own application to run the impulse locally. In this tutorial you'll export an impulse, and build a desktop application to classify sensor data.
Even though this is a C++ library you can link to it from C applications. See 'Using the library from C' below.
This tutorial assumes that you know how to build C++ applications, and works on macOS, Linux and Windows. If you're unfamiliar with these tools you can build binaries directly for your development board from the Deployment page in the studio.
Looking for examples that integrate with sensors? See the Edge Impulse C++ SDK for Linux.
Make sure you followed the Continuous motion recognition tutorial, and have a trained impulse. Also install the following software:
- GNU Make - to build the application.
makeshould be in your PATH.
- A modern C++ compiler. The default LLVM version on macOS works, but on Linux upgrade to LLVM 9 (installation instructions).
- MinGW-W64 which includes both GNU Make and a compiler. Make sure
mingw32-makeis in your PATH. See these instructions for more information.
We created an example repository which contains a Makefile and a small CLI example application, which takes the raw features as an argument, and prints out the final classification. Clone or download this repository at example-standalone-inferencing.
Head over to your Edge Impulse project, and go to Deployment. From here you can create the full library which contains the impulse and all external required libraries. Select C++ library, and click Build to create the library.
.zip file and place the contents in the 'example-standalone-inferencing' folder (which you downloaded above). Your final folder structure should look like this:
example-standalone-inferencing |_ Makefile |_ README.md |_ build.bat |_ build.sh |_ edge-impulse-sdk |_ model-parameters |_ source |_ tflite-model
Then, open a terminal or command prompt, and build the project:
$ sh build.sh
This will first build the inferencing engine, and then build the complete application. After building succeeded you should have a binary in
To verify that the application works head back to the studio and click on Live classification. Then load a validation sample, and click on a row under 'Detailed result'.
To verify that the local application classifies the same, we need the raw features for this timestamp. To do so click on the 'Copy to clipboard' button next to 'Raw features'. This will copy the raw values from this validation file, before any signal processing or inferencing happened.
Then invoke the local application by passing these features as an argument to the application. Open a terminal or command prompt and run:
./build/edge-impulse-standalone "-19.8800, -0.6900, 8.2300, -17.6600, -1.1300, 5.9700, ..."
build\edge-impulse-standalone.exe "-19.8800, -0.6900, 8.2300, -17.6600, -1.1300, 5.9700, ..."
This will run the signal processing pipeline, and then classify the output:
Running neural network... Predictions (time: 0 ms.): idle: 0.015319 snake: 0.000444 updown: 0.006182 wave: 0.978056 Anomaly score (time: 0 ms.): 0.133557 run_classifier_returned: 0 Begin output [0.01532, 0.00044, 0.00618, 0.97806, 0.134] End output
Which matches the values we just saw in the studio. You now have your impulse running locally!
Even though the impulse is deployed as a C++ application, you can link to it from C applications. This is done by compiling the impulse as a shared library with the
EI_C_LINKAGE=1 macros, then link to it from a C application. The
run_classifier can then be invoked from your application. An end-to-end application that demonstrates this and can be used with this tutorial is under example-standalone-inferencing-c.
There's a limited number of arguments that you can pass on the command line, and if your raw features array is larger than this number you will be presented with the error:
Argument list too long. To get around this you can create a file called
features.txt, put your features in there, and then call the script via:
Note you must put a . and file extension in the name. This is how the app tells file from list.
Updated 6 months ago