Skip to content

Commit e8ab07f

Browse files
committed
treewide: Add documentation for hello_ei sample and Edge Impulse
- Add README for edge_impulse/hello_ei sample. - Make changes in doc/integrations/edge_impulse.rst related to change of form of deployment EI models (use of EI SDK module). - Add section about usage of EI west extension commands. Jira: NCSDK-37082 Signed-off-by: Bartosz Meus <bartosz.meus@nordicsemi.no>
1 parent 2333f12 commit e8ab07f

11 files changed

Lines changed: 258 additions & 22 deletions

File tree

doc/integrations/edge_impulse.rst

Lines changed: 99 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Edge Impulse integration
88
:depth: 2
99

1010
`Edge Impulse`_ is a development platform that can be used to enable `embedded machine learning`_ on |NCS| devices.
11-
You can use this platform to collect data from sensors, train machine learning model, and then deploy it to your Nordic Semiconductor's device.
11+
You can use this platform to collect data from sensors, train a machine learning model, and then deploy it to your Nordic Semiconductor's device.
1212

1313
Integration prerequisites
1414
*************************
@@ -19,16 +19,34 @@ Before you start the |EAI| integration with Edge Impulse, make sure that the fol
1919
* Setup of the required Development Kit (DK).
2020
* Creation of an `Edge Impulse studio account <Edge Impulse studio signup_>`_ and an Edge Impulse project.
2121

22+
Solution architecture
23+
*********************
24+
25+
The Edge Impulse integration consists of three main components:
26+
27+
* **Edge Impulse SDK** - A C++ library that provides the inference engine and digital signal processing (DSP) functions required to run machine learning models on embedded devices.
28+
The SDK is integrated into the build system as a Zephyr module through the west manifest file of the |EAI|.
29+
* **Deployed ML model** - A Zephyr library package generated by Edge Impulse Studio that contains your trained model's parameters.
30+
This is provided as a :file:`zip` archive with C/C++ source files that are compiled together with your application.
31+
* **Application code** - Your |NCS| application that collects sensor data, feeds it to the inference engine through the Edge Impulse SDK API, and processes the classification results.
32+
33+
The typical workflow involves collecting sensor samples, running inference using a sliding window approach, and interpreting the classification results to make decisions or trigger actions.
34+
This is presented in the :ref:`hello_ei_sample` sample.
35+
2236
Integration overview
2337
********************
2438

2539
Before integrating the Edge Impulse machine learning model into an |EAI| application, you must prepare and deploy the machine learning model for your embedded device.
2640
This model is prepared using the `Edge Impulse studio`_ external web tool.
2741
It relies on sensor data that can be provided by different sources, for example data forwarder.
28-
Check the :ref:`ei_data_forwarder_sample` sample for a demonstration of how you can send sensor data to Edge Impulse studio using `Edge Impulse's data forwarder`_.
2942

30-
The machine learning model is distributed as a single :file:`zip` archive that includes C++ library sources.
31-
This file is used by the |NCS| build system to build the Edge Impulse library.
43+
.. note::
44+
You can collect data using either a development board that is supported directly by Edge Impulse or your mobile phone.
45+
Alternatively, you can modify the :ref:`ei_data_forwarder_sample` sample to forward data from a sensor that is connected to any board available in the |NCS|.
46+
47+
The machine learning model is distributed as a single :file:`zip` archive that includes C/C++ machine learning model sources.
48+
You must include these files in your |EAI| application.
49+
Apart from that, you must also enable the `Edge Impulse`_ SDK (see :ref:`ug_edge_impulse_building`).
3250

3351
Integration steps
3452
*****************
@@ -45,46 +63,105 @@ Complete the following steps to generate the archive and add it to the build sys
4563
Preparing the machine learning model
4664
====================================
4765

48-
To prepare the machine learning model, use `Edge Impulse studio`_ and follow one of the tutorials described in `Edge Impulse getting started guide`_.
49-
For example, you can try the `Continuous motion recognition tutorial`_.
50-
This tutorial will guide you through the following steps:
66+
1. Prepare your own machine learning model.
5167

52-
1. Collecting data from sensors and uploading the data to Edge Impulse studio.
68+
To prepare a machine learning model, use `Edge Impulse studio`_ and follow one of the tutorials described in `Edge Impulse getting started guide`_.
69+
For example, to test the solution, you can try the `Continuous motion recognition tutorial`_.
70+
You will complete the following steps:
5371

54-
.. note::
55-
You can use one of the development boards supported directly by Edge Impulse or your mobile phone to collect the data.
56-
You can also modify the :ref:`ei_data_forwarder_sample` application and use it to forward data from a sensor that is connected to any board available in the |NCS|.
72+
a. Collect data from sensors and upload them to the Edge Impulse studio.
73+
74+
#. Design your machine learning model (an *impulse*).
75+
76+
#. Deploy your machine learning model to use it on an embedded device by following one of the two methods:
77+
78+
You can obtain a library in two ways:
79+
80+
.. tabs::
81+
82+
.. group-tab:: Using |EIS| web interface
83+
84+
Go to the :guilabel:`Deployment` tab and select :guilabel:`Zephyr library`.
85+
This will generate a :file:`zip` file that contains source files defining the |EI| ML model.
86+
87+
.. figure:: ./images/ei_deploy.png
88+
:scale: 50 %
89+
:alt: Model deployment in |EIS| dashboard
90+
91+
Model deployment in |EIS| dashboard
92+
93+
.. note::
94+
Edge Impulse supports multiple deployment formats, some of which are compatible with |NCS| applications.
95+
However, this instruction focuses on the Zephyr library deployment format.
96+
97+
.. group-tab:: Using |EI| west extensions
5798

58-
#. Designing your machine learning model (an *impulse*).
59-
#. Deploying the machine learning model to use it on an embedded device.
60-
As part of this step, you must select the :guilabel:`C++ library` to generate the required :file:`zip` file that contains the source files for building the Edge Impulse library in |EAI|.
99+
|EI| provides west command extensions that let you build and deploy the machine learning model from |EIS| using the command line instead of the web interface.
100+
The commands are already configured in the |EAI| west manifest and are ready to use.
101+
102+
a. Find two parameters that are required by the commands:
103+
104+
* ``Project ID`` - You can find it in the :guilabel:`Project info` panel under :guilabel:`Dashboard`.
105+
106+
.. figure:: ./images/ei_project_id.png
107+
:scale: 50 %
108+
:alt: Project ID in |EIS| dashboard
109+
110+
Project ID in |EIS| dashboard
111+
112+
* ``API key`` - You can find it under the :guilabel:`Keys` tab in the |EI| project dashboard.
113+
114+
.. figure:: ./images/ei_api_key.png
115+
:scale: 50 %
116+
:alt: API key under the Keys tab in |EIS|
117+
118+
API key under the Keys tab in |EIS|
119+
120+
#. Build the machine learning model by running the following command:
121+
122+
.. code-block:: console
123+
124+
west ei-build -p <PROJECT_ID> -k <API_KEY>
125+
126+
#. Deploy the machine learning model by running the following command:
127+
128+
.. code-block:: console
129+
130+
west ei-deploy -p <PROJECT_ID> -k <API_KEY>
131+
132+
As a result, file :file:`ei_model.zip` is downloaded to your working directory.
133+
134+
For more details on how to use these commands, see `Automated Deployment with West Commands`_ documentation.
61135

62136
.. _ug_edge_impulse_adding_building:
63137

64138
.. rst-class:: numbered-step
65139

66-
Building the machine learning model in |EAI|
67-
============================================
140+
Building an application with machine learning model
141+
===================================================
68142

69-
After preparing the :file:`zip` archive, you can use the |NCS| build system to build the C++ library with the machine learning model.
70-
Complete the following steps to configure the building process:
143+
You have to complete the following configuration steps to be able to build your application including the deployed |EI| machine learning model:
71144

72-
1. Make sure that the following Kconfig options are **enabled**:
145+
1. Make sure that the following Kconfig options are enabled:
73146

74147
* ``CONFIG_CPP``
75148
* ``CONFIG_STD_CPP11``
76149
* ``CONFIG_REQUIRES_FULL_LIBCPP``
150+
* ``CONFIG_EDGE_IMPULSE_SDK``
77151

78152
.. note::
79153
The ``CONFIG_FPU`` Kconfig option is implied by default if floating point unit (FPU) is supported by the hardware.
80154
Using FPU speeds up calculations.
81155

82-
#. Make sure that the ``CONFIG_FP16`` Kconfig option is **disabled**.
83-
The Edge Impulse library is not compatible with half-precision floating point support introduced in Zephyr.
156+
#. Make sure that the ``CONFIG_FP16`` Kconfig option is disabled.
157+
The |EI| library is not compatible with half-precision floating point support introduced in Zephyr.
158+
159+
.. _ug_edge_impulse_building:
84160

85161
Applications and samples
86162
************************
87163

88164
The following samples demonstrate the Edge Impulse integration in the |EAI|:
89165

90-
* :ref:`ei_data_forwarder_sample` sample - demonstrates how you can send sensor data to Edge Impulse studio using `Edge Impulse's data forwarder`_.
166+
* :ref:`ei_data_forwarder_sample` sample - Demonstrates how you can send sensor data to |EIS| using `Edge Impulse's data forwarder`_.
167+
* :ref:`hello_ei_sample` sample - Demonstrates the deployment of models in |EI| and usage of the inference engine provided by |EI| SDK.
174 KB
Loading
248 KB
Loading
208 KB
Loading

doc/links.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
.. _`Building an application`: https://docs.nordicsemi.com/bundle/ncs-3.2.0/page/nrf/app_dev/config_and_build/building.html#building
5050
.. _`Programming`: https://docs.nordicsemi.com/bundle/ncs-3.2.0/page/nrf/app_dev/programming.html#programming
5151
.. _`Testing and optimization`: https://docs.nordicsemi.com/bundle/ncs-3.2.0/page/nrf/test_and_optimize.html#testing
52+
.. _`Providing CMake options`: https://docs.nordicsemi.com/bundle/ncs-3.2.0/page/nrf/app_dev/config_and_build/cmake/index.html#providing_cmake_options
5253

5354
.. _`Simulated sensor driver`: https://docs.nordicsemi.com/bundle/ncs-3.2.0/page/nrf/drivers/sensor_sim.html
5455

@@ -68,6 +69,8 @@
6869
.. _`nRF Connect SDK simulated sensor machine learning model`: https://studio.edgeimpulse.com/public/18121/latest
6970
.. _`nRF Connect SDK hardware accelerometer machine learning model`: https://studio.edgeimpulse.com/public/33129/latest
7071
.. _`Nordic Semi nRF54L15 DK page`: https://docs.edgeimpulse.com/docs/nordic-semi-nrf54L15-dk
72+
.. _`Edge Impulse Zephyr Module Deployment`: https://docs.edgeimpulse.com/hardware/deployments/run-zephyr-module
73+
.. _`Automated Deployment with West Commands`: https://docs.edgeimpulse.com/hardware/deployments/run-zephyr-module#automated-deployment-with-west-commands-early-access-preview
7174

7275
.. ### Source: github.com
7376

doc/samples.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ The samples demonstrate typical workflows using the nRF Edge AI components such
2121
* DSP - Demonstrates using the nRF Edge AI Digital Signal Processing (DSP) primitives for signal processing.
2222
* NN - Demonstrates using the nRF Edge AI Neural Network (NN) engine for running its standalone models.
2323

24+
There are also additional samples demonstrating the integration of `Edge Impulse`_ with |EAI|:
25+
26+
* |EI|: Data forwarder - Demonstrates using `Edge Impulse's data forwarder`_.
27+
* |EI|: Hello Edge Impulse - Demonstrates deployment of models in |EI| and usage of the inference engine provided by |EI| SDK.
28+
2429
.. toctree::
2530
:maxdepth: 2
2631

doc/samples/edge_impulse.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ This section lists the available |EAI| samples presenting integration with `Edge
1010
:caption: Subpages
1111

1212
/../samples/edge_impulse/data_forwarder/README.rst
13+
/../samples/edge_impulse/hello_ei/README.rst

doc/shortcuts.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
.. |EAI| replace:: Edge AI Add-on
33
.. |nRFVSC| replace:: nRF Connect for VS Code extension
44
.. |EI| replace:: Edge Impulse
5+
.. |EIS| replace:: Edge Impulse Studio
56

67
.. ### Configuration and testing shortcuts
78

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
.. _hello_ei_sample:
2+
3+
Edge Impulse: Hello Edge Impulse
4+
################################
5+
6+
.. contents::
7+
:local:
8+
:depth: 2
9+
10+
The Hello Edge Impulse sample demonstrates how to use the `Edge Impulse`_ SDK and custom machine learning model when :ref:`integrating Edge Impulse with the nRF Connect SDK <edge_impulse_integration>`.
11+
12+
Requirements
13+
************
14+
15+
The sample supports the following development kits:
16+
17+
.. table-from-sample-yaml::
18+
19+
Overview
20+
********
21+
22+
This sample runs a pre-trained `Edge Impulse`_ machine learning model using two input data series that represent a sine wave and a triangle wave with added noise.
23+
Sample's main purpose is to:
24+
25+
1. Provide input data to the |EI| model.
26+
#. Start predictions using the machine learning model.
27+
#. Display the prediction results and time measurements.
28+
29+
Configuration
30+
*************
31+
32+
|config|
33+
34+
The sample can be configured using the following Kconfig options:
35+
36+
.. options-from-kconfig::
37+
:show-type:
38+
39+
.. _hello_ei_sample_building_and_running:
40+
41+
Building and running
42+
********************
43+
44+
.. |sample path| replace:: :file:`samples/edge_impulse/hello_ei`
45+
46+
.. include:: /includes/build_and_run.txt
47+
48+
Testing
49+
=======
50+
51+
|test_sample|
52+
53+
1. |connect_kit|
54+
#. |connect_terminal_kit|
55+
#. Reset the kit.
56+
#. Observe the following UART output:
57+
58+
.. code-block:: console
59+
60+
*** Booting nRF Connect SDK v3.2.0-5dcc6bd39b0f ***
61+
*** Using Zephyr OS v4.2.99-a57ad913cf4e ***
62+
I: === Model info ===
63+
I: Input frame size: 3
64+
I: Input window size: 312
65+
I: Input frequency: 52
66+
I: Label count: 3
67+
I: Has anomaly: yes
68+
I: #########################
69+
I: Running inference on sine wave input data
70+
I: #########################
71+
I: === Inference result ===
72+
I: idle => 0.00000
73+
I: sine => 0.99603
74+
I: triangle => 0.00397
75+
I: anomaly: -0.12298
76+
I: === Inference time profiling ===
77+
I: Full inference completed in 6564 us
78+
I: Classification completed in 766 us
79+
I: DSP operations completed in 5562 us
80+
I: Anomaly detection completed in 63 us
81+
I: #########################
82+
I: === Inference result ===
83+
I: idle => 0.00000
84+
I: sine => 0.99648
85+
I: triangle => 0.00352
86+
I: anomaly: -0.12898
87+
I: === Inference time profiling ===
88+
I: Full inference completed in 6560 us
89+
I: Classification completed in 762 us
90+
I: DSP operations completed in 5562 us
91+
I: Anomaly detection completed in 61 us
92+
...
93+
94+
The observed classification results depend on machine learning model and input data.
95+
96+
Using your custom machine learning model
97+
========================================
98+
99+
If you wish to run this sample using a pre-trained model, go to the :ref:`hello_ei_sample_building_and_running` section.
100+
Otherwise, if you wish to use a custom machine learning model, you must complete the following setup:
101+
102+
1. :ref:`Train and deploy your own machine learning model <ug_edge_impulse_adding_preparing>`.
103+
Choose |EIS| web interface method (a Zephyr library format).
104+
105+
#. Select the |EI| model.
106+
107+
Set the ``CONFIG_EDGE_IMPULSE_PATH`` to an absolute or relative path to a file in the local filesystem.
108+
The file must be a ZIP archive generated by |EIS|, and it must contain the source files that define the |EI| ML model.
109+
The relative path is tracked from the application source directory (``APPLICATION_SOURCE_DIR``).
110+
Any CMake variables included in the path are expanded.
111+
112+
#. Define input data for the machine learning model in the :file:`samples/edge_impulse/hello_ei/src/include/input_data.h` file.
113+
#. Check the example input data in your |EIS| project:
114+
115+
a. Go to the :guilabel:`Live classification` tab.
116+
#. In the :guilabel:`Classify existing test sample` panel, select one of the test samples.
117+
#. Click :guilabel:`Load sample` to display the raw data preview.
118+
119+
.. figure:: ./doc/images/ei_load_test_sample.png
120+
:scale: 50 %
121+
:alt: Loading test sample input data in |EIS|
122+
123+
Loading test sample input data in |EIS|
124+
125+
The classification results will be displayed along with a preview of raw data.
126+
127+
.. figure:: ./doc/images/ei_raw_features.png
128+
:scale: 50 %
129+
:alt: Raw data preview in |EIS|
130+
131+
Raw data preview in |EIS|
132+
133+
#. Copy information from the :guilabel:`Raw features` list into an array defined in the :file:`input_data.h` file.
134+
135+
.. note::
136+
If you provide more input data than a single input window can hold, the prediction will be triggered multiple times.
137+
The input window will be shifted by one input frame between subsequent predictions.
138+
The prediction will be retriggered until there is no more input data available.
139+
140+
Dependencies
141+
************
142+
143+
This sample uses the following Zephyr libraries:
144+
145+
* `Logging`_
146+
147+
This sample uses the following external components:
148+
149+
* `Edge Impulse`_ SDK
100 KB
Loading

0 commit comments

Comments
 (0)