Skip to content
heliaRT
API reference
HELIA HUB

MicroInterpreter

Allocate tensors, invoke a model and access inputs/outputs.

Machine-readable model

class

tensorflow/lite/micro/micro_interpreter.h:46

class MicroInterpreter
method

The lifetime of the model, op resolver, tensor arena, error reporter, resource variables, and profiler must be at least as long as that of the interpreter obje…

tensorflow/lite/micro/micro_interpreter.h:56

tflite::MicroInterpreter::MicroInterpreter(
const Model *model,
const MicroOpResolver &op_resolver,
uint8_t *tensor_arena,
size_t tensor_arena_size,
MicroResourceVariables *resource_variables = nullptr,
MicroProfilerInterface *profiler = nullptr,
bool preserve_all_tensors = false
)

The lifetime of the model, op resolver, tensor arena, error reporter, resource variables, and profiler must be at least as long as that of the interpreter object, since the interpreter may need to access them at any time. This means that you should usually create them with the same scope as each other, for example having them all allocated on the stack as local variables through a top-level function. The interpreter doesn’t do any deallocation of any of the pointed-to objects, ownership remains with the caller.

Parameters of MicroInterpreter
NameTypeDefaultDescription
modelconst Model *Required
op_resolverconst MicroOpResolver &Required
tensor_arenauint8_t *Required
tensor_arena_sizesize_tRequired
resource_variablesMicroResourceVariables *nullptr
profilerMicroProfilerInterface *nullptr
preserve_all_tensorsboolfalse
method

Create an interpreter instance using an existing MicroAllocator instance.

tensorflow/lite/micro/micro_interpreter.h:67

tflite::MicroInterpreter::MicroInterpreter(
const Model *model,
const MicroOpResolver &op_resolver,
MicroAllocator *allocator,
MicroResourceVariables *resource_variables = nullptr,
MicroProfilerInterface *profiler = nullptr
)

Create an interpreter instance using an existing MicroAllocator instance. This constructor should be used when creating an allocator that needs to have allocation handled in more than one interpreter or for recording allocations inside the interpreter. The lifetime of the allocator must be as long as that of the interpreter object.

Parameters of MicroInterpreter
NameTypeDefaultDescription
modelconst Model *Required
op_resolverconst MicroOpResolver &Required
allocatorMicroAllocator *Required
resource_variablesMicroResourceVariables *nullptr
profilerMicroProfilerInterface *nullptr
method

Runs through the model and allocates all necessary input, output and intermediate tensors.

tensorflow/lite/micro/micro_interpreter.h:76

TfLiteStatus tflite::MicroInterpreter::AllocateTensors()

Runs through the model and allocates all necessary input, output and intermediate tensors.

method

In order to support partial graph runs for strided models, this can return values other than kTfLiteOk and kTfLiteError.

tensorflow/lite/micro/micro_interpreter.h:81

TfLiteStatus tflite::MicroInterpreter::Invoke()

In order to support partial graph runs for strided models, this can return values other than kTfLiteOk and kTfLiteError. TODO(b/149795762): Add this to the TfLiteStatus enum.

method

This is the recommended API for an application to pass an external payload pointer as an external context to kernels.

tensorflow/lite/micro/micro_interpreter.h:87

TfLiteStatus tflite::MicroInterpreter::SetMicroExternalContext(void *external_context_payload)

This is the recommended API for an application to pass an external payload pointer as an external context to kernels. The life time of the payload pointer should be at least as long as this interpreter. TFLM supports only one external context.

Parameters of SetMicroExternalContext
NameTypeDefaultDescription
external_context_payloadvoid *Required
method

Returns a pointer to the tensor for the corresponding tensorindex.

tensorflow/lite/micro/micro_interpreter.h:126

TfLiteEvalTensor * tflite::MicroInterpreter::GetTensor(int tensor_index, int subgraph_index = 0)

Returns a pointer to the tensor for the corresponding tensor_index.

Parameters of GetTensor
NameTypeDefaultDescription
tensor_indexintRequired
subgraph_indexint0
method

Zeros out a single variable tensor in a specified subgraph in the model.

tensorflow/lite/micro/micro_interpreter.h:129

TfLiteStatus tflite::MicroInterpreter::ResetVariableTensor(int tensor_index, int subgraph_index = 0)

Zeros out a single variable tensor in a specified subgraph in the model.

Parameters of ResetVariableTensor
NameTypeDefaultDescription
tensor_indexintRequired
subgraph_indexint0
method

Reset the state to be what you would expect when the interpreter is first created.

tensorflow/lite/micro/micro_interpreter.h:133

TfLiteStatus tflite::MicroInterpreter::Reset()

Reset the state to be what you would expect when the interpreter is first created. i.e. after Init and Prepare is called for the very first time.

method

Populates node and registration pointers representing the inference graph of the model from values inside the flatbuffer (loaded from the TfLiteModel instance).

tensorflow/lite/micro/micro_interpreter.h:141

TfLiteStatus tflite::MicroInterpreter::PrepareNodeAndRegistrationDataFromFlatbuffer()

Populates node and registration pointers representing the inference graph of the model from values inside the flatbuffer (loaded from the TfLiteModel instance). Persistent data (e.g. operator data) is allocated from the arena.

method

For debugging only.

tensorflow/lite/micro/micro_interpreter.h:149

size_t tflite::MicroInterpreter::arena_used_bytes() const

For debugging only. Returns the actual used arena in bytes. This method gives the optimal arena size. It’s only available after AllocateTensors has been called. Note that normally tensor_arena requires 16 bytes alignment to fully utilize the space. If it’s not the case, the optimal arena size would be arena_used_bytes() + 16.

method

Returns True if all Tensors are being preserved TODO(b/297106074) : revisit making C++ example or test for preservealltensors

tensorflow/lite/micro/micro_interpreter.h:154

bool tflite::MicroInterpreter::preserve_all_tensors() const

Returns True if all Tensors are being preserved TODO(b/297106074) : revisit making C++ example or test for preserve_all_tensors

method

Set the alternate MicroProfilerInterface.

tensorflow/lite/micro/micro_interpreter.h:164

TfLiteStatus tflite::MicroInterpreter::SetAlternateProfiler(MicroProfilerInterface *alt_profiler)

Set the alternate MicroProfilerInterface. This value is passed through to the MicroContext. This can be used to profile subsystems simultaneously with the profiling of kernels during the Eval phase. See (b/379584353). The alternate MicroProfilerInterface is currently used by the tensor decompression subsystem.

Parameters of SetAlternateProfiler
NameTypeDefaultDescription
alt_profilerMicroProfilerInterface *Required
method

Set the alternate decompression memory regions.

tensorflow/lite/micro/micro_interpreter.h:174

TfLiteStatus tflite::MicroInterpreter::SetDecompressionMemory(
const MicroContext::AlternateMemoryRegion *regions,
size_t count
)

Set the alternate decompression memory regions. Can only be called during the MicroInterpreter kInit state (i.e. must be called before MicroInterpreter::AllocateTensors). The regions pointer argument is the start of a MicroContext::AlternateMemoryRegion array where the length of the array is given by the count argument. The lifetime of the MicroContext::AlternateMemoryRegion array must be at least that of the MicroInterpreter.

Parameters of SetDecompressionMemory
NameTypeDefaultDescription
regionsconst MicroContext::AlternateMemoryRegion *Required
countsize_tRequired