Attend the Women in ML Symposium on December 7 Register now
Stay organized with collections Save and categorize content based on your preferences.

tflite::InterpreterBuilder

#include <interpreter_builder.h>

Build an interpreter capable of interpreting model.

Summary

model: A model whose lifetime must be at least as long as any interpreter(s) created by the builder. In principle multiple interpreters can be made from a single model. op_resolver: An instance that implements the OpResolver interface, which maps custom op names and builtin op codes to op registrations. The lifetime of the provided op_resolver object must be at least as long as the InterpreterBuilder; unlike model and error_reporter, the op_resolver does not need to exist for the duration of any created Interpreter objects. error_reporter: a functor that is called to report errors that handles printf var arg semantics. The lifetime of the error_reporter object must be greater than or equal to the Interpreter created by operator(). options_experimental: Options that can change behavior of interpreter. WARNING: this parameter is an experimental API and is subject to change.

Returns a kTfLiteOk when successful and sets interpreter to a valid Interpreter. Note: The user must ensure the lifetime of the model (and error reporter, if provided) is at least as long as interpreter's lifetime, and a single model instance may safely be used with multiple interpreters.

Constructors and Destructors

InterpreterBuilder(const FlatBufferModel & model, const OpResolver & op_resolver, const InterpreterOptions *options_experimental)
For this constructor, the ErrorReporter will be extracted from the FlatBufferModel.
InterpreterBuilder(const ::tflite::Model *model, const OpResolver & op_resolver, ErrorReporter *error_reporter, const InterpreterOptions *options_experimental)
Builds an interpreter given only the raw flatbuffer Model object (instead of a FlatBufferModel).
InterpreterBuilder(const InterpreterBuilder &)
~InterpreterBuilder()

Public functions

AddDelegate(TfLiteDelegate *delegate)
void
Any delegates added with AddDelegate will be applied to the Interpreter generated by operator(), in the order that they were added.
SetNumThreads(int num_threads)
TfLiteStatus
Sets the number of CPU threads to use for the interpreter.
operator()(std::unique_ptr< Interpreter > *interpreter)
TfLiteStatus
Builds an interpreter and stores it in *interpreter.
operator()(std::unique_ptr< Interpreter > *interpreter, int num_threads)
TfLiteStatus
Same as above, but also sets the number of CPU threads to use (overriding any previous call to SetNumThreads).
operator=(const InterpreterBuilder &)=delete

Public functions

AddDelegate

void AddDelegate(
  TfLiteDelegate *delegate
)

Any delegates added with AddDelegate will be applied to the Interpreter generated by operator(), in the order that they were added.

(The delegate parameter passed to AddDelegate should be non-null, otherwise an error will be reported, and the call to AddDelegate will have no other effect.) The lifetime of the delegate must be at least as long as the lifetime of any Interpreter generated by this InterpreterBuilder.

InterpreterBuilder

 InterpreterBuilder(
  const FlatBufferModel & model,
  const OpResolver & op_resolver,
  const InterpreterOptions *options_experimental
)

For this constructor, the ErrorReporter will be extracted from the FlatBufferModel.

options object is copied during construction. So caller can release it

InterpreterBuilder

 InterpreterBuilder(
  const ::tflite::Model *model,
  const OpResolver & op_resolver,
  ErrorReporter *error_reporter,
  const InterpreterOptions *options_experimental
)

Builds an interpreter given only the raw flatbuffer Model object (instead of a FlatBufferModel).

Mostly used for testing. If error_reporter is null, then DefaultErrorReporter() is used. options object is copied during construction. So caller can release it

InterpreterBuilder

 InterpreterBuilder(
  const InterpreterBuilder &
)=delete

SetNumThreads

TfLiteStatus SetNumThreads(
  int num_threads
)

Sets the number of CPU threads to use for the interpreter.

Returns kTfLiteOk on success, kTfLiteError on error.

operator()

TfLiteStatus operator()(
  std::unique_ptr< Interpreter > *interpreter
)

Builds an interpreter and stores it in *interpreter.

On success, returns kTfLiteOk and sets *interpreter to a valid Interpreter. On failure, returns an error status and sets *interpreter to nullptr.

operator()

TfLiteStatus operator()(
  std::unique_ptr< Interpreter > *interpreter,
  int num_threads
)

Same as above, but also sets the number of CPU threads to use (overriding any previous call to SetNumThreads).

Deprecated: use the SetNumThreads method instead.

operator=

InterpreterBuilder & operator=(
  const InterpreterBuilder &
)=delete

~InterpreterBuilder

 ~InterpreterBuilder()