tensorflow/lite/g3doc/api_docs/cc/class/tflite/impl/interpreter.html
|
|
| --- |
| Interpreter(ErrorReporter *error_reporter)
|
| Interpreter(const Interpreter &)
|
| ~Interpreter()
|
|
|
| --- |
| TfLiteDelegatePtr | using
std::unique_ptr< TfLiteDelegate, void(*)(TfLiteDelegate *)>
|
|
|
| --- |
| kTensorsCapacityHeadroom = 16 |
constexpr int
The capacity headroom of tensors_ vector before calling ops' prepare and invoke function.
|
| kTensorsReservedCapacity = 128 |
constexpr int
|
|
|
| --- |
| tflite::impl::InterpreterBuilder |
friend class
|
|
|
| --- |
| AddProfiler(Profiler *profiler) |
void
\warning This is an experimental API and subject to change.
|
| AddProfiler(std::unique_ptr< Profiler > profiler) |
void
\warning This is an experimental API and subject to change.
|
| AllocateTensors() |
TfLiteStatus
Update allocations for all tensors.
|
| ApplyOptions(InterpreterOptions *options) |
TfLiteStatus
\warning This is an experimental API and subject to change.
|
| Cancel() |
TfLiteStatus
\warning This is an experimental API and subject to change.
|
| EnsureTensorDataIsReadable(int tensor_index) |
TfLiteStatus
\warning This is an experimental API and subject to change.
|
| GetAllowFp16PrecisionForFp32() const |
bool
\warning Experimental interface, subject to change.
|
| GetAsyncSignatureRunner(const char *signature_key) |
async::AsyncSignatureRunner *
\warning Experimental interface, subject to change.
|
| GetBufferHandle(int tensor_index, TfLiteBufferHandle *buffer_handle, TfLiteDelegate **delegate) |
TfLiteStatus
\warning This is an experimental API and subject to change.
|
| GetInputName(int index) const |
const char *
Return the name of a given input.
|
| GetOutputName(int index) const |
const char *
Return the name of a given output.
|
| GetProfiler() |
Profiler *
\warning This is an experimental API and subject to change.
|
| GetSignatureRunner(const char *signature_key) |
SignatureRunner *
\warning Experimental interface, subject to change.
|
| GetSubgraphIndexFromSignature(const char *signature_key) const |
int
\warning Experimental interface, subject to change.
|
| Invoke() |
TfLiteStatus
Invoke the interpreter (run the whole graph in dependency order).
|
| ModifyGraphWithDelegate(TfLiteDelegate *delegate) |
TfLiteStatus
Allow a delegate to look at the graph and modify the graph to handle parts of the graph themselves.
|
| ModifyGraphWithDelegate(std::unique_ptr< Delegate, Deleter > delegate) |
TfLiteStatus
\warning This is an experimental API and subject to change.
|
| ModifyGraphWithDelegate(std::unique_ptr< TfLiteDelegate > delegate)=delete |
TfLiteStatus
This overload is never OK.
|
| OpProfilingString(const TfLiteRegistration & op_reg, const TfLiteNode *node) const |
const char *
Retrieve an operator's description of its work, for profiling purposes.
|
| ReleaseNonPersistentMemory() |
TfLiteStatus
\warning Experimental interface, subject to change.
|
| ResetVariableTensors() |
TfLiteStatus
\warning This is an experimental API and subject to change.
|
| ResizeInputTensor(int tensor_index, const std::vector< int > & dims) |
TfLiteStatus
Change the dimensionality of a given tensor.
|
| ResizeInputTensorStrict(int tensor_index, const std::vector< int > & dims) |
TfLiteStatus
Change the dimensionality of a given tensor.
|
| SetAllowBufferHandleOutput(bool allow_buffer_handle_output) |
void
\warning This is an experimental API and subject to change.
|
| SetAllowFp16PrecisionForFp32(bool allow) |
void
Allow float16 precision for FP32 calculation when possible.
|
| SetBufferHandle(int tensor_index, TfLiteBufferHandle buffer_handle, TfLiteDelegate *delegate) |
TfLiteStatus
\warning This is an experimental API and subject to change.
|
| SetBufferHandle(TfLiteTensor *tensor, TfLiteBufferHandle buffer_handle, TfLiteDelegate *delegate) |
TfLiteStatus
\warning This is an experimental API and subject to change.
|
| SetCancellationFunction(void *data, bool(*)(void *) check_cancelled_func) |
void
\warning This is an experimental API and subject to change.
|
| SetCustomAllocationForTensor(int tensor_index, const TfLiteCustomAllocation & allocation, int64_t flags) |
TfLiteStatus
Assigns (or reassigns) a custom memory allocation for the given tensor.
|
| SetExternalContext(TfLiteExternalContextType type, TfLiteExternalContext *ctx) |
void
|
| SetNumThreads(int num_threads) |
TfLiteStatus
Set the number of threads available to the interpreter.
|
| SetProfiler(Profiler *profiler) |
void
\warning This is an experimental API and subject to change.
|
| SetProfiler(std::unique_ptr< Profiler > profiler) |
void
\warning This is an experimental API and subject to change.
|
| error_reporter() const |
ErrorReporter *
\warning Experimental interface, subject to change.
|
| execution_plan() const |
const std::vector< int > &
\warning Experimental interface, subject to change.
|
| input_tensor(size_t index) |
TfLiteTensor *
Return a mutable pointer to the given input tensor.
|
| input_tensor(size_t index) const |
const TfLiteTensor *
Return an immutable pointer to the given input tensor.
|
| input_tensor_by_signature(const char *signature_input_name, const char *signature_key) |
TfLiteTensor *
\warning Experimental interface, subject to change.
|
| inputs() const |
const std::vector< int > &
Read only access to list of inputs.
|
| node_and_registration(int node_index) const |
const std::pair< TfLiteNode, TfLiteRegistration > *
Returns a pointer to an operation and registration data structure if in bounds from the primary subgraph(subgraph_[0]).
|
| node_and_registration(int subgraph_index, int node_index) const |
const std::pair< TfLiteNode, TfLiteRegistration > *
Returns a pointer to an operation and registration data structure if in bounds.
|
| nodes_size() const |
size_t
Return the number of ops in the model.
|
| operator=(const Interpreter &)=delete |
Interpreter &
|
| output_tensor(size_t index) |
TfLiteTensor *
Return a mutable pointer to the given output tensor.
|
| output_tensor(size_t index) const |
const TfLiteTensor *
Return an immutable pointer to the given output tensor.
|
| output_tensor_by_signature(const char *signature_output_name, const char *signature_key) const |
const TfLiteTensor *
\warning Experimental interface, subject to change.
|
| outputs() const |
const std::vector< int > &
Read only access to list of outputs.
|
| signature_inputs(const char *signature_key) const |
const std::map< std::string, uint32_t > &
\warning Experimental interface, subject to change.
|
| signature_keys() const |
std::vector< const std::string * >
\warning Experimental interface, subject to change.
|
| signature_outputs(const char *signature_key) const |
const std::map< std::string, uint32_t > &
\warning Experimental interface, subject to change.
|
| tensor(int tensor_index) |
TfLiteTensor *
Get a mutable tensor data structure.
|
| tensor(int tensor_index) const |
const TfLiteTensor *
Get an immutable tensor data structure.
|
| tensors_size() const |
size_t
Return the number of tensors in the model.
|
| typed_input_tensor(int index) |
T *
Return a mutable pointer into the data of a given input tensor.
|
| typed_input_tensor(int index) const |
const T *
Return an immutable pointer into the data of a given input tensor.
|
| typed_output_tensor(int index) |
T *
Return a mutable pointer into the data of a given output tensor.
|
| typed_output_tensor(int index) const |
const T *
Return an immutable pointer into the data of a given output tensor.
|
| typed_tensor(int tensor_index) |
T *
Perform a checked cast to the appropriate tensor type (mutable pointer version).
|
| typed_tensor(int tensor_index) const |
const T *
Perform a checked cast to the appropriate tensor type (immutable pointer version).
|
| variables() const |
const std::vector< int > &
Read only access to list of variable tensors. |
std::unique_ptr< TfLiteDelegate, void(*)(TfLiteDelegate *)> TfLiteDelegatePtr
constexpr int kTensorsCapacityHeadroom = 16
The capacity headroom of tensors_ vector before calling ops' prepare and invoke function.
In these functions, it's guaranteed allocating up to kTensorsCapacityHeadroom more tensors won't invalidate pointers to existing tensors.
constexpr int kTensorsReservedCapacity = 128
friend class tflite::impl::InterpreterBuilder
void AddProfiler(
Profiler *profiler
)
\warning This is an experimental API and subject to change.
\n Adds the profiler to tracing execution. The caller retains ownership of the profiler and must ensure its validity. nullptr profiler will be ignored.
void AddProfiler(
std::unique_ptr< Profiler > profiler
)
\warning This is an experimental API and subject to change.
\n Adds the profiler to tracing execution. Transfers ownership of the profiler to the interpreter. nullptr profiler will be ignored.
TfLiteStatus AllocateTensors()
Update allocations for all tensors.
This will redim dependent tensors using the input tensor dimensionality as given. This is relatively expensive. This must be called after the interpreter has been created and before running inference (and accessing tensor buffers), and must be called again if (and only if) an input tensor is resized. Returns status of success or failure. Will fail if any of the ops in the model (other than those which were rewritten by delegates, if any) are not supported by the Interpreter's OpResolver.
TfLiteStatus ApplyOptions(
InterpreterOptions *options
)
\warning This is an experimental API and subject to change.
\n Apply InterpreterOptions which tunes behavior of the interpreter.
TfLiteStatus Cancel()
\warning This is an experimental API and subject to change.
\n Attempts to cancel in flight invocation if any. This will not affect Invokes that happends after the cancellation. Non blocking. Thread safe. Returns kTfLiteError if cancellation is not enabled, otherwise returns kTfLiteOk.
TfLiteStatus EnsureTensorDataIsReadable(
int tensor_index
)
\warning This is an experimental API and subject to change.
\n Ensure the data in tensor.data is readable. In case delegate is used, it might require to copy the data from delegate buffer to raw memory.
bool GetAllowFp16PrecisionForFp32() const
\warning Experimental interface, subject to change.
\n Get the half precision flag.
async::AsyncSignatureRunner * GetAsyncSignatureRunner(
const char *signature_key
)
\warning Experimental interface, subject to change.
\n Returns a pointer to the AsyncSignatureRunner instance to run the part of the graph identified by a SignatureDef. The nullptr is returned if the given signature key is not valid. The async delegate should be applied before calling this function.
TfLiteStatus GetBufferHandle(
int tensor_index,
TfLiteBufferHandle *buffer_handle,
TfLiteDelegate **delegate
)
\warning This is an experimental API and subject to change.
\n Get the delegate buffer handle, and the delegate which can process the buffer handle.
const char * GetInputName(
int index
) const
Return the name of a given input.
The given index must be between 0 and inputs().size().
const char * GetOutputName(
int index
) const
Return the name of a given output.
The given index must be between 0 and outputs().size().
Profiler * GetProfiler()
\warning This is an experimental API and subject to change.
\n Gets the profiler used for op tracing.
SignatureRunner * GetSignatureRunner(
const char *signature_key
)
\warning Experimental interface, subject to change.
\n Returns a pointer to the SignatureRunner instance to run the part of the graph identified by a SignatureDef. The nullptr is returned if the given signature key is not valid. If you need to specify delegates, you have to do that before calling this function. This function will additionally apply default delegates. Thus, applying delegates after that might lead to undesirable behaviors. Note, the pointed instance has lifetime same as the Interpreter object and the SignatureRunner class is not thread-safe.
int GetSubgraphIndexFromSignature(
const char *signature_key
) const
\warning Experimental interface, subject to change.
\n Return the subgraph index that corresponds to a SignatureDef, defined by 'signature_key'. If invalid name passed, -1 will be returned.
Interpreter([ErrorReporter](/lite/api_docs/cc/class/tflite/error-reporter.html#classtflite_1_1_error_reporter)*error_reporter
)
Interpreter(
const Interpreter &
)=delete
TfLiteStatus Invoke()
Invoke the interpreter (run the whole graph in dependency order).
NOTE: It is possible that the interpreter is not in a ready state to evaluate (i.e. if a ResizeTensor() has been performed without an AllocateTensors(). Returns status of success or failure.
TfLiteStatus ModifyGraphWithDelegate(
TfLiteDelegate *delegate
)
Allow a delegate to look at the graph and modify the graph to handle parts of the graph themselves.
After this is called, the graph may contain new nodes that replace 1 more nodes. 'delegate' must outlive the interpreter. Returns one of the following status codes:
TfLiteStatus ModifyGraphWithDelegate(
std::unique_ptr< Delegate, Deleter > delegate
)
\warning This is an experimental API and subject to change.
\n Same as ModifyGraphWithDelegate except this interpreter takes ownership of the provided delegate.
TfLiteStatus ModifyGraphWithDelegate(
std::unique_ptr< TfLiteDelegate > delegate
)=delete
This overload is never OK.
TfLiteDelegate is a C structure, so it has no virtual destructor. The default deleter of the unique_ptr does not know how to delete C++ objects deriving from TfLiteDelegate.
const char * OpProfilingString(
const TfLiteRegistration & op_reg,
const TfLiteNode *node
) const
Retrieve an operator's description of its work, for profiling purposes.
TfLiteStatus ReleaseNonPersistentMemory()
\warning Experimental interface, subject to change.
\n This releases memory held by non-persistent tensors. It does NOT re-perform memory planning. AllocateTensors needs to be called before next invocation.
TfLiteStatus ResetVariableTensors()
\warning This is an experimental API and subject to change.
\n Reset all variable tensors to the default value. If a variable tensor doesn't have a buffer, reset it to zero. TODO(b/115961645): Implement - If a variable tensor has a buffer, reset it to the value of the buffer.
TfLiteStatus ResizeInputTensor(
int tensor_index,
const std::vector< int > & dims
)
Change the dimensionality of a given tensor.
Note, this is only acceptable for tensor indices that are inputs or variables. Returns status of failure or success. Note that this doesn't actually resize any existing buffers. A call to AllocateTensors() is required to change the tensor input buffer.
TfLiteStatus ResizeInputTensorStrict(
int tensor_index,
const std::vector< int > & dims
)
Change the dimensionality of a given tensor.
This is only acceptable for tensor indices that are inputs or variables. Only unknown dimensions can be resized with this function. Unknown dimensions are indicated as -1 in the dims_signature attribute of a TfLiteTensor. Returns status of failure or success. Note that this doesn't actually resize any existing buffers. A call to AllocateTensors() is required to change the tensor input buffer.
void SetAllowBufferHandleOutput(
bool allow_buffer_handle_output
)
\warning This is an experimental API and subject to change.
\n Set if buffer handle output is allowed.
When using hardware delegation, Interpreter will make the data of output tensors available in tensor->data by default. If the application can consume the buffer handle directly (e.g. reading output from OpenGL texture), it can set this flag to false, so Interpreter won't copy the data from buffer handle to CPU memory.
void SetAllowFp16PrecisionForFp32(
bool allow
)
Allow float16 precision for FP32 calculation when possible.
Default: not allow.
WARNING: This API is deprecated: prefer controlling this via delegate options, e.g. tflite::StatefulNnApiDelegate::Options::allow\_fp16' or TfLiteGpuDelegateOptionsV2::is_precision_loss_allowed`. This method will be removed in a future release.
TfLiteStatus SetBufferHandle(
int tensor_index,
TfLiteBufferHandle buffer_handle,
TfLiteDelegate *delegate
)
\warning This is an experimental API and subject to change.
\n Set the delegate buffer handle to a tensor. It can be called in the following cases:
TfLiteStatus SetBufferHandle(
TfLiteTensor *tensor,
TfLiteBufferHandle buffer_handle,
TfLiteDelegate *delegate
)
\warning This is an experimental API and subject to change.
\n Set the delegate buffer handle to the given tensor.
void SetCancellationFunction(
void *data,
bool(*)(void *) check_cancelled_func
)
\warning This is an experimental API and subject to change.
\n Sets the cancellation function pointer in order to cancel a request in the middle of a call to Invoke(). The interpreter queries this function during inference, between op invocations; when it returns true, the interpreter will abort execution and return kTfLiteError. The data parameter contains any data used by the cancellation function, and if non-null, remains owned by the caller.
TfLiteStatus SetCustomAllocationForTensor(
int tensor_index,
const TfLiteCustomAllocation & allocation,
int64_t flags
)
Assigns (or reassigns) a custom memory allocation for the given tensor.
flags is a bitmask, see TfLiteCustomAllocationFlags. The runtime does NOT take ownership of the underlying memory.
NOTE: User needs to call AllocateTensors() after this. Invalid/insufficient buffers will cause an error during AllocateTensors or Invoke (in case of dynamic shapes in the graph).
Parameters should satisfy the following conditions:
flags. \warning This is an experimental API and subject to change. \nvoid SetExternalContext(
TfLiteExternalContextType type,
TfLiteExternalContext *ctx
)
TfLiteStatus SetNumThreads(
int num_threads
)
Set the number of threads available to the interpreter.
NOTE: num_threads should be >= -1. Setting num_threads to 0 has the effect to disable multithreading, which is equivalent to setting num_threads to 1. If set to the value -1, the number of threads used will be implementation-defined and platform-dependent.
As TfLite interpreter could internally apply a TfLite delegate by default (i.e. XNNPACK), the number of threads that are available to the default delegate should be set via InterpreterBuilder APIs as follows:
std::unique_ptr interpreter; tflite::InterpreterBuilder builder(tflite model, op resolver); builder.SetNumThreads(...) ASSERT\_EQ(builder(&interpreter), kTfLiteOk);
WARNING: This API is deprecated: prefer using InterpreterBuilder::SetNumThreads, as documented above.
void SetProfiler(
Profiler *profiler
)
\warning This is an experimental API and subject to change.
\n Sets the profiler to tracing execution. The caller retains ownership of the profiler and must ensure its validity. Previously registered profilers will be unregistered. If profiler is nullptr, all previously installed profilers will be removed.
void SetProfiler(
std::unique_ptr< Profiler > profiler
)
\warning This is an experimental API and subject to change.
\n Same as SetProfiler except this interpreter takes ownership of the provided profiler. Previously registered profilers will be unregistered. If profiler is nullptr, all previously installed profilers will be removed.
[ErrorReporter](/lite/api_docs/cc/class/tflite/error-reporter.html#classtflite_1_1_error_reporter)* error_reporter() const
\warning Experimental interface, subject to change.
\n Get the error reporter associated with this interpreter.
const std::vector< int > & execution_plan() const
\warning Experimental interface, subject to change.
TfLiteTensor * input_tensor(
size_t index
)
Return a mutable pointer to the given input tensor.
The given index must be between 0 and inputs().size().
const TfLiteTensor * input_tensor(
size_t index
) const
Return an immutable pointer to the given input tensor.
The given index must be between 0 and inputs().size().
TfLiteTensor * input_tensor_by_signature(
const char *signature_input_name,
const char *signature_key
)
\warning Experimental interface, subject to change.
\n Returns the input tensor identified by 'signature_input_name' in the signature identified by 'signature_key'. Returns nullptr if not found.
const std::vector< int > & inputs() const
Read only access to list of inputs.
const std::pair< TfLiteNode, TfLiteRegistration > * node_and_registration(
int node_index
) const
Returns a pointer to an operation and registration data structure if in bounds from the primary subgraph(subgraph_[0]).
const std::pair< TfLiteNode, TfLiteRegistration > * node_and_registration(
int subgraph_index,
int node_index
) const
Returns a pointer to an operation and registration data structure if in bounds.
size_t nodes_size() const
Return the number of ops in the model.
[Interpreter](/lite/api_docs/cc/namespace/tflite.html#namespacetflite_1a2d6d829bce5eba5b241987ca5b4f0f40)& operator=(
const[Interpreter](/lite/api_docs/cc/namespace/tflite.html#namespacetflite_1a2d6d829bce5eba5b241987ca5b4f0f40)&
)=delete
TfLiteTensor * output_tensor(
size_t index
)
Return a mutable pointer to the given output tensor.
The given index must be between 0 and outputs().size().
const TfLiteTensor * output_tensor(
size_t index
) const
Return an immutable pointer to the given output tensor.
The given index must be between 0 and outputs().size().
const TfLiteTensor * output_tensor_by_signature(
const char *signature_output_name,
const char *signature_key
) const
\warning Experimental interface, subject to change.
\n Returns the output tensor identified by 'signature_output_name' in the signature identified by 'signature_key'. Returns nullptr if not found.
const std::vector< int > & outputs() const
Read only access to list of outputs.
const std::map< std::string, uint32_t > & signature_inputs(
const char *signature_key
) const
\warning Experimental interface, subject to change.
\n Returns the mapping of inputs to tensor index in the signature specified through 'signature_key'. If invalid name passed, an empty list will be returned.
std::vector< const std::string * > signature_keys() const
\warning Experimental interface, subject to change.
\n Returns list of all keys of different method signatures defined in the model. Note, pointers returned have lifetime same as the Interpreter object.
const std::map< std::string, uint32_t > & signature_outputs(
const char *signature_key
) const
\warning Experimental interface, subject to change.
\n Returns the mapping of outputs to tensor index in the signature specified through 'signature_key'. If invalid name passed, an empty list will be returned.
TfLiteTensor * tensor(
int tensor_index
)
Get a mutable tensor data structure.
const TfLiteTensor * tensor(
int tensor_index
) const
Get an immutable tensor data structure.
size_t tensors_size() const
Return the number of tensors in the model.
T * typed_input_tensor(
int index
)
Return a mutable pointer into the data of a given input tensor.
The given index must be between 0 and inputs().size().
const T * typed_input_tensor(
int index
) const
Return an immutable pointer into the data of a given input tensor.
The given index must be between 0 and inputs().size().
T * typed_output_tensor(
int index
)
Return a mutable pointer into the data of a given output tensor.
The given index must be between 0 and outputs().size().
const T * typed_output_tensor(
int index
) const
Return an immutable pointer into the data of a given output tensor.
The given index must be between 0 and outputs().size().
T * typed_tensor(
int tensor_index
)
Perform a checked cast to the appropriate tensor type (mutable pointer version).
const T * typed_tensor(
int tensor_index
) const
Perform a checked cast to the appropriate tensor type (immutable pointer version).
const std::vector< int > & variables() const
Read only access to list of variable tensors.
~Interpreter()