Machine Learning model APIs and structures#

Model handle structure and init/run/deinit functions for embedded TensorFlow Lite Micro models.

Modules#

sl_ml_model_handle_t

Functions#

sl_status_t
sl_ml_model_init(sl_ml_model_handle_t *handle)

Load the model flatbuffer and initialize the interpreter for inference.

sl_status_t
sl_ml_model_run(sl_ml_model_handle_t *handle)

Run one inference pass on a loaded model.

sl_status_t
sl_ml_model_deinit(sl_ml_model_handle_t *handle)

Unload the model and release interpreter resources held by handle.

Function Documentation#

sl_ml_model_init#

sl_status_t sl_ml_model_init (sl_ml_model_handle_t * handle)

Load the model flatbuffer and initialize the interpreter for inference.

Parameters
TypeDirectionArgument NameDescription
sl_ml_model_handle_t *[in]handle

Pointer to an initialized handle structure; must not be NULL. flatbuffer, opcode_resolver, buffers, and buffer_sizes must also be set.

If the model is already loaded, returns SL_STATUS_OK without reloading the flatbuffer.

To reload the same handle, call sl_ml_model_deinit first, then sl_ml_model_init.

Returns

  • sl_status_t indicating whether the model loaded successfully.

Return values

  • SL_STATUS_OK: The model loaded successfully, or was already loaded.

  • SL_STATUS_INVALID_PARAMETER: handle

  • SL_STATUS_FAIL: Interpreter setup or tensor allocation failed.


sl_ml_model_run#

sl_status_t sl_ml_model_run (sl_ml_model_handle_t * handle)

Run one inference pass on a loaded model.

Parameters
TypeDirectionArgument NameDescription
sl_ml_model_handle_t *[in]handle

Pointer to a loaded model handle; must not be NULL.

Returns

  • sl_status_t indicating whether inference completed successfully.

Return values

  • SL_STATUS_OK: Inference completed successfully.

  • SL_STATUS_INVALID_PARAMETER: handle

  • SL_STATUS_NOT_INITIALIZED

  • SL_STATUS_FAIL: The TFLM


sl_ml_model_deinit#

sl_status_t sl_ml_model_deinit (sl_ml_model_handle_t * handle)

Unload the model and release interpreter resources held by handle.

Parameters
TypeDirectionArgument NameDescription
sl_ml_model_handle_t *[in]handle

Pointer to the model handle to unload; must not be NULL.

Returns

  • sl_status_t indicating whether the model was unloaded successfully.

Return values

  • SL_STATUS_OK: The model was loaded and has been unloaded.

  • SL_STATUS_NOT_INITIALIZED: The model was not loaded;

  • SL_STATUS_INVALID_PARAMETER: handle