Edge Impulse wrapper

The Edge Impulse wrapper provides an implementation for running an embedded machine learning model on a device in nRF Connect SDK. For more information about support for Edge Impulse in nRF Connect SDK, see Edge Impulse integration.

Overview

The wrapper:

  • Buffers input data for the machine learning model.

  • Runs the machine learning model in a separate thread.

  • Provides results through a dedicated callback.

Before using the wrapper, you need to add the machine learning model to your nRF Connect SDK application.

Configuration

Enable the Edge Impulse wrapper by CONFIG_EI_WRAPPER option. The option is enabled by default if CONFIG_EDGE_IMPULSE is set.

The Edge Impulse nRF Connect SDK library can be configured with the following Kconfig options:

For more detailed description of these options, refer to the Kconfig help.

Using Edge Impulse wrapper

After setting Edge Impulse wrapper Configuration options, you can use it in your application. Use the following Edge Impulse wrapper API:

  • Use the ei_wrapper_init() function to initialize the wrapper.

  • Provide the input data using the ei_wrapper_add_data() function. The provided data is appended to an internal circular buffer that is located in RAM.

    Note

    Make sure that:

    • The number of provided input values is divisible by the input frame size for the machine learning model used. Otherwise, an error code is returned.

    • The value for the CONFIG_EI_WRAPPER_DATA_BUF_SIZE Kconfig option is big enough to temporarily store the data provided by your application.

  • Call the ei_wrapper_start_prediction() function to shift the prediction window and start the prediction for the buffered data. If the whole input window is filled with data right after the shift operation, the prediction is started instantly. Otherwise, the prediction is delayed until the missing data is provided.

    Note

    The input data that goes out of the input window is dropped from the input buffer after the shift operation. This part of the input buffer can be reused to store new data.

The Edge Impulse wrapper runs the machine learning model in a dedicated thread. Results are provided through a callback registered during the initialization of the wrapper. You can call the following functions to access results:

Refer to the API documentation for more detailed information about the API provided by the wrapper.

API documentation

Header file: include/ei_wrapper.h
Source files: lib/edge_impulse/
Edge Impulse wrapper