View Source TFLiteElixir.SignatureRunner (tflite_elixir v0.4.0-rc6)

A runner for one of a model's signatures.

A signature names a subgraph together with its inputs and outputs, so tensors are addressed by name instead of by index and the order of a model's outputs no longer has to be worked out. Obtain one with TFLiteElixir.Interpreter.get_signature_runner/2.

A runner belongs to the interpreter it came from and keeps that interpreter alive, so it stays usable even if nothing else refers to the interpreter any more. Like the interpreter it is not safe to use from more than one process at a time.

Summary

Functions

Allocate the tensors of the signature's subgraph.

Cancel an in-flight invocation.

The names of the signature's inputs.

Raising version of input_names/1.

How many inputs the signature has.

Raising version of input_size/1.

Write data into the named input.

Run the signature.

The names of the signature's outputs.

Raising version of output_names/1.

How many outputs the signature has.

Raising version of output_size/1.

Read the named output.

Feed the signature its inputs, run it and read every output back.

Raising version of predict/2.

Change the dimensions of the named input.

Change the dimensions of the named input, keeping the rank fixed.

The key this runner was obtained with.

Types

@type nif_error() :: {:error, String.t()}

Functions

@spec allocate_tensors(reference()) :: :ok | nif_error()

Allocate the tensors of the signature's subgraph.

@spec cancel(reference()) :: :ok | nif_error()

Cancel an in-flight invocation.

@spec input_names(reference()) :: {:ok, [String.t()]} | nif_error()

The names of the signature's inputs.

Raising version of input_names/1.

@spec input_size(reference()) :: {:ok, non_neg_integer()} | nif_error()

How many inputs the signature has.

Raising version of input_size/1.

Link to this function

input_tensor(self, input_name, data)

View Source
@spec input_tensor(reference(), String.t(), binary()) :: :ok | nif_error()

Write data into the named input.

allocate_tensors/1 has to have been called first.

@spec invoke(reference()) :: :ok | nif_error()

Run the signature.

@spec output_names(reference()) :: {:ok, [String.t()]} | nif_error()

The names of the signature's outputs.

Raising version of output_names/1.

@spec output_size(reference()) :: {:ok, non_neg_integer()} | nif_error()

How many outputs the signature has.

Raising version of output_size/1.

Link to this function

output_tensor(self, output_name)

View Source
@spec output_tensor(reference(), String.t()) :: {:ok, binary()} | nif_error()

Read the named output.

Link to this function

output_tensor!(self, output_name)

View Source

Raising version of output_tensor/2.

@spec predict(reference(), %{required(String.t()) => binary()}) ::
  {:ok, %{required(String.t()) => binary()}} | nif_error()

Feed the signature its inputs, run it and read every output back.

Inputs and outputs are maps keyed by the names the signature declares, which is what makes a signature worth using: neither side depends on the order the model happens to list its tensors in.

Raising version of predict/2.

Link to this function

resize_input_tensor(self, input_name, dims)

View Source
@spec resize_input_tensor(reference(), String.t(), [integer()]) :: :ok | nif_error()

Change the dimensions of the named input.

allocate_tensors/1 has to be called again afterwards.

Link to this function

resize_input_tensor_strict(self, input_name, dims)

View Source
@spec resize_input_tensor_strict(reference(), String.t(), [integer()]) ::
  :ok | nif_error()

Change the dimensions of the named input, keeping the rank fixed.

Only dimensions the model left unknown can be changed.

@spec signature_key(reference()) :: {:ok, String.t()} | nif_error()

The key this runner was obtained with.

Raising version of signature_key/1.