Model Handle Structure#

Runtime context for one TensorFlow Lite Micro model on an embedded target. Instantiate one handle per deployed model.

The handle holds the serialized model flatbuffer (flatbuffer), operator resolver (opcode_resolver), and tensor arena memory (buffers and buffer_sizes). The embedded interpreter wrapper (TfliteMicroModel, or SLTfliteMicroModel when profiling is enabled) is default-constructed at creation; call sl_ml_model_init before running inference.

Public Attributes#

npu_toolkit::TfliteMicroModel
const uint8_t *
const tflite::MicroOpResolver *
uint8_t **
const int32_t *

Public Functions#

TfLiteTensor *
input_tensor(size_t index) const

Return the input tensor at index.

TfLiteTensor *
output_tensor(size_t index) const

Return the output tensor at index.

sl_ml_model_handle_t(const uint8_t *flatbuffer_in, int flatbuffer_length_in, const tflite::MicroOpResolver *opcode_resolver_in, uint8_t **buffers_in, const int32_t *buffer_sizes_in, int32_t buffer_count_in, int32_t model_buffer_alignment_in, const char **model_buffer_sections_in)

Initialize a model handle with flatbuffer, resolver, and tensor-buffer metadata.

Public Attribute Documentation#

model#

npu_toolkit::TfliteMicroModel sl_ml_model_handle_t::model

Embedded TFLM interpreter; default-constructed until sl_ml_model_init succeeds.


flatbuffer#

const uint8_t* sl_ml_model_handle_t::flatbuffer

Pointer to the serialized model flatbuffer.


flatbuffer_length#

int sl_ml_model_handle_t::flatbuffer_length

Length of flatbuffer in bytes.


opcode_resolver#

const tflite::MicroOpResolver* sl_ml_model_handle_t::opcode_resolver

Operator resolver that registers kernels required by the model.


buffers#

uint8_t** sl_ml_model_handle_t::buffers

Pointers to tensor arena buffers; parallel to buffer_sizes.


buffer_sizes#

const int32_t* sl_ml_model_handle_t::buffer_sizes

Size in bytes of each buffer in buffers.


buffer_count#

int32_t sl_ml_model_handle_t::buffer_count

Number of entries in buffers and buffer_sizes.


model_buffer_alignment#

int32_t sl_ml_model_handle_t::model_buffer_alignment

Byte alignment required for each tensor arena buffer (typically 4).


model_buffer_sections#

const char** sl_ml_model_handle_t::model_buffer_sections

Linker section name for each buffer slot; parallel to buffers. May be NULL.


Public Function Documentation#

input_tensor#

TfLiteTensor * sl_ml_model_handle_t::input_tensor (size_t index)

Return the input tensor at index.

Parameters
TypeDirectionArgument NameDescription
size_t[in]index

Zero-based input tensor index (0 to num_inputs - 1).

The model must be loaded successfully (sl_ml_model_init).

Returns

  • Pointer to the input TfLiteTensor, or NULL if the model is not loaded, index is invalid, or the interpreter is unavailable.


output_tensor#

TfLiteTensor * sl_ml_model_handle_t::output_tensor (size_t index)

Return the output tensor at index.

Parameters
TypeDirectionArgument NameDescription
size_t[in]index

Zero-based output tensor index (0 to num_outputs - 1).

The model must be loaded successfully (sl_ml_model_init).

Returns

  • Pointer to the output TfLiteTensor, or NULL if the model is not loaded, index is invalid, or the interpreter is unavailable.


sl_ml_model_handle_t#

sl_ml_model_handle_t::sl_ml_model_handle_t (const uint8_t * flatbuffer_in, int flatbuffer_length_in, const tflite::MicroOpResolver * opcode_resolver_in, uint8_t ** buffers_in, const int32_t * buffer_sizes_in, int32_t buffer_count_in, int32_t model_buffer_alignment_in, const char ** model_buffer_sections_in)

Initialize a model handle with flatbuffer, resolver, and tensor-buffer metadata.

Parameters
TypeDirectionArgument NameDescription
const uint8_t *[in]flatbuffer_in

Pointer to the serialized model flatbuffer; must not be NULL.

int[in]flatbuffer_length_in

Length of flatbuffer_in in bytes; must be greater than zero.

const tflite::MicroOpResolver *[in]opcode_resolver_in

Operator resolver for kernels used by the model; must not be NULL.

uint8_t **[in]buffers_in

Array of tensor arena buffers; must not be NULL.

const int32_t *[in]buffer_sizes_in

Size in bytes of each buffer in buffers_in; must not be NULL.

int32_t[in]buffer_count_in

Number of elements in buffers_in and buffer_sizes_in; must be greater than zero.

int32_t[in]model_buffer_alignment_in

Required byte alignment for each tensor arena buffer (typically 4).

const char **[in]model_buffer_sections_in

Linker section name for each buffer slot; parallel to buffers_in. May be NULL.

Default-constructs the embedded interpreter wrapper (and profiler when enabled). Call sl_ml_model_init before sl_ml_model_run.