.. _hello_ei_sample: Hello Edge Impulse ################## .. contents:: :local: :depth: 2 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 `. Requirements ************ The sample supports the following development kits: .. table-from-sample-yaml:: Overview ******** 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. Sample's main purpose is to: 1. Provide input data to the |EI| model. #. Start predictions using the machine learning model. #. Display the prediction results and time measurements. .. note:: When building the ``nrf54lm20dk/nrf54lm20b/cpuapp`` target, the sample uses an `Axon NPU`_-accelerated model for inference by default. On other supported boards, the model runs on the CPU. Configuration options ********************* |config| The sample can be configured using the following Kconfig options: .. options-from-kconfig:: :show-type: Build types =========== The ``nrf54lm20dk/nrf54lm20b/cpuapp`` board target supports the following build types. See `Custom build types`_ and `Providing CMake options`_ for more information. .. list-table:: Hello Edge Impulse build types for ``nrf54lm20dk/nrf54lm20b/cpuapp`` :widths: auto :header-rows: 1 * - Build type - File suffix - Description * - Axon NPU inference (default) - -- - Runs inference on the `Axon NPU`_ using a model compiled for hardware acceleration. * - CPU inference - ``model_cpu`` - Runs inference on the CPU instead of the Axon NPU. Other supported boards always execute on the CPU. Using your custom machine learning model ======================================== If you wish to run this sample using a pre-trained model, go to the :ref:`hello_ei_sample_building_and_running` section. Otherwise, if you wish to use a custom machine learning model, you must complete the following setup: 1. :ref:`Train and deploy your own machine learning model `. Choose |EIS| web interface method (a Zephyr library format). #. Select the |EI| model by setting the ``CONFIG_EDGE_IMPULSE_MODEL_PATH`` to an absolute or relative path to a file in the local filesystem. The file must be a ZIP archive generated by |EIS|, and it must contain the source files that define the |EI| ML model. The relative path is tracked from the application source directory (``APPLICATION_SOURCE_DIR``). Any CMake variables included in the path are expanded. #. Define input data for the machine learning model in the :file:`samples/edge_impulse/hello_ei/src/include/input_data.h` file. #. Check the example input data in your |EIS| project: a. Go to the :guilabel:`Live classification` tab. #. In the :guilabel:`Classify existing test sample` panel, select one of the test samples. #. Click :guilabel:`Load sample` to display the raw data preview. .. figure:: ../../../../../samples/edge_impulse/hello_ei/images/ei_load_test_sample.png :scale: 50 % :alt: Loading test sample input data in |EIS| Loading test sample input data in |EIS| The classification results will be displayed along with a preview of raw data. .. figure:: ../../../../../samples/edge_impulse/hello_ei/images/ei_raw_features.png :scale: 50 % :alt: Raw data preview in |EIS| Raw data preview in |EIS| #. Copy information from the :guilabel:`Raw features` list into an array defined in the :file:`input_data.h` file. .. note:: If you provide more input data than a single input window can hold, the prediction will be triggered multiple times. The input window will be shifted by one input frame between subsequent predictions. The prediction will be retriggered until there is no more input data available. .. _hello_ei_sample_building_and_running: Building and running ******************** .. |sample path| replace:: :file:`samples/edge_impulse/hello_ei` .. include:: /includes/build_and_run.txt Testing ======= |test_sample| 1. |connect_kit| #. |connect_terminal_kit| #. Reset the kit. #. Observe the following UART output: .. code-block:: console *** Booting nRF Connect SDK v3.2.0-5dcc6bd39b0f *** *** Using Zephyr OS v4.2.99-a57ad913cf4e *** I: === Model info === I: Input frame size: 3 I: Input window size: 312 I: Input frequency: 52 I: Label count: 3 I: Has anomaly: yes I: ######################### I: Running inference on sine wave input data I: ######################### I: === Inference result === I: idle => 0.00000 I: sine => 0.99603 I: triangle => 0.00397 I: anomaly: -0.12298 I: === Inference time profiling === I: Full inference completed in 6564 us I: Classification completed in 766 us I: DSP operations completed in 5562 us I: Anomaly detection completed in 63 us I: ######################### I: === Inference result === I: idle => 0.00000 I: sine => 0.99648 I: triangle => 0.00352 I: anomaly: -0.12898 I: === Inference time profiling === I: Full inference completed in 6560 us I: Classification completed in 762 us I: DSP operations completed in 5562 us I: Anomaly detection completed in 61 us ... The observed classification results depend on machine learning model and input data. Dependencies ************ This sample uses the following Zephyr libraries: * `Logging`_ This sample uses the following external components: * `Edge Impulse`_ SDK