View Source TFLiteElixir.Interpreter (tflite_elixir v0.3.7)
An interpreter for a graph of nodes that input and output from tensors.
Summary
Functions
Allocate memory for tensors in the graph
Raising version of allocate_tensors/1
.
Return the execution plan of the model.
Get the name of the input tensor
Raising version of get_input_name/2
.
Get the name of the output tensor
Raising version of get_output_name/2
.
Get SignatureDef map from the Metadata of a TfLite flatbuffer buffer.
Raising version of get_signature_defs/1
.
Fill data to the specified input tensor
Raising version of input_tensor/3
.
Get the list of input tensors.
Raising version of inputs/1
.
Run forwarding
Raising version of invoke/1
.
New interpreter
New interpreter with model filepath
Raising version of new/1
.
New interpreter with model buffer
Return the number of ops in the model.
Get the data of the output tensor
Raising version of output_tensor/2
.
Get the list of output tensors.
Raising version of outputs/1
.
Fill input data to corresponding input tensor of the interpreter,
call Interpreter.invoke
and return output tensor(s)
Provide a list of tensor indexes that are inputs to the model. Each index is bound check and this modifies the consistent_ flag of the interpreter.
Set the number of threads available to the interpreter.
Raising version of set_num_threads/2
.
Provide a list of tensor indexes that are outputs to the model. Each index is bound check and this modifies the consistent_ flag of the interpreter.
Provide a list of tensor indexes that are variable tensors. Each index is bound check and this modifies the consistent_ flag of the interpreter.
Returns list of all keys of different method signatures defined in the model.
Get any tensor in the graph by its id
Return the number of tensors in the model.
Get the list of variable tensors.
Types
Functions
Allocate memory for tensors in the graph
Raising version of allocate_tensors/1
.
@spec execution_plan(reference()) :: [non_neg_integer()] | nif_error()
Return the execution plan of the model.
Experimental interface, subject to change.
@spec get_input_name(reference(), non_neg_integer()) :: {:ok, String.t()} | nif_error()
Get the name of the input tensor
Note that the index here means the index in the result list of inputs/1
. For example,
if inputs/1
returns [42, 314]
, then 0
should be passed here to get the name of
tensor 42
Raising version of get_input_name/2
.
@spec get_output_name(reference(), non_neg_integer()) :: {:ok, String.t()} | nif_error()
Get the name of the output tensor
Note that the index here means the index in the result list of outputs/1
. For example,
if outputs/1
returns [42, 314]
, then 0
should be passed here to get the name of
tensor 42
Raising version of get_output_name/2
.
Get SignatureDef map from the Metadata of a TfLite flatbuffer buffer.
self
: TFLiteElixir.Interpreter
TFLite model buffer to get the signature_def.
Returns:
Map containing serving names to SignatureDefs if exists, otherwise, nil
.
Raising version of get_signature_defs/1
.
@spec input_tensor(reference(), non_neg_integer(), binary()) :: :ok | nif_error()
Fill data to the specified input tensor
Note: although we have typed_input_tensor
available in C++, here what we really passed
to the NIF is binary
data, therefore, I'm not pretend that we have type information.
Raising version of input_tensor/3
.
@spec inputs(reference()) :: {:ok, [non_neg_integer()]} | nif_error()
Get the list of input tensors.
return a list of input tensor id
Raising version of inputs/1
.
Run forwarding
Raising version of invoke/1
.
@spec new() :: nif_resource_ok() | nif_error()
New interpreter
@spec new(String.t()) :: nif_resource_ok() | nif_error()
New interpreter with model filepath
Raising version of new/0
.
Raising version of new/1
.
@spec new_from_buffer(binary()) :: nif_resource_ok() | nif_error()
New interpreter with model buffer
@spec nodes_size(reference()) :: non_neg_integer() | nif_error()
Return the number of ops in the model.
@spec output_tensor(reference(), non_neg_integer()) :: {:ok, binary()} | nif_error()
Get the data of the output tensor
Note that the index here means the index in the result list of outputs/1
. For example,
if outputs/1
returns [42, 314]
, then 0
should be passed here to get the name of
tensor 42
Raising version of output_tensor/2
.
@spec outputs(reference()) :: {:ok, [non_neg_integer()]} | nif_error()
Get the list of output tensors.
return a list of output tensor id
Raising version of outputs/1
.
@spec predict(reference(), binary() | [binary()] | map()) :: binary() | [binary()] | map() | nif_error()
Fill input data to corresponding input tensor of the interpreter,
call Interpreter.invoke
and return output tensor(s)
Provide a list of tensor indexes that are inputs to the model. Each index is bound check and this modifies the consistent_ flag of the interpreter.
Set the number of threads available to the interpreter.
NOTE: num_threads should be >= 1.
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:
interpreter = Interpreter.new!()
builder = InterpreterBuilder.new!(tflite model, op resolver)
InterpreterBuilder.set_num_threads(builder, ...)
assert :ok == InterpreterBuilder.build!(builder, interpreter)
Raising version of set_num_threads/2
.
Provide a list of tensor indexes that are outputs to the model. Each index is bound check and this modifies the consistent_ flag of the interpreter.
Provide a list of tensor indexes that are variable tensors. Each index is bound check and this modifies the consistent_ flag of the interpreter.
Returns list of all keys of different method signatures defined in the model.
WARNING: Experimental interface, subject to change
@spec tensor(reference(), non_neg_integer()) :: %TFLiteElixir.TFLiteTensor{ index: term(), name: term(), quantization_params: term(), reference: term(), shape: term(), shape_signature: term(), sparsity_params: term(), type: term() } | nif_error()
Get any tensor in the graph by its id
Note that the tensor_index
here means the id of a tensor. For example,
if inputs/1
returns [42, 314]
, then 42
should be passed here to get tensor 42
.
@spec tensors_size(reference()) :: non_neg_integer() | nif_error()
Return the number of tensors in the model.
@spec variables(reference()) :: {:ok, [non_neg_integer()]} | nif_error()
Get the list of variable tensors.