View Source TFLiteElixir.InterpreterBuilder (tflite_elixir v0.4.0-rc3)

Build an interpreter capable of interpreting model.

Summary

Functions

Attach a delegate to the builder, with the default decline policy.

Attach a delegate to every interpreter this builder goes on to build.

Build the interpreter with the InterpreterBuilder.

Raising version of build/2.

New InterpreterBuilder

Raising version of new/2.

Sets the number of CPU threads to use for the interpreter. Returns true on success, {:error, reason} on error.

Types

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

Functions

Link to this function

add_delegate(self, delegate)

View Source
@spec add_delegate(reference(), reference()) :: :ok | nif_error()

Attach a delegate to the builder, with the default decline policy.

Equivalent to add_delegate(builder, delegate, []).

Link to this function

add_delegate(self, delegate, opts)

View Source
@spec add_delegate(reference(), reference(), Keyword.t() | map()) :: :ok | nif_error()

Attach a delegate to every interpreter this builder goes on to build.

The delegate is applied in the order delegates were added, and it has to outlive every interpreter built from this builder -- which is why there is no way to detach or delete one. Holding the reference is not required: the builder and each interpreter keep the delegate alive for as long as they need it.

Attaching any delegate also suppresses the XNNPACK one that build/2 would otherwise add for you.

Options
  • :on_decline. What to do when a delegate reports that it cannot take the graph, but leaves the graph runnable -- a static-shape delegate meeting a dynamic tensor, say. TfLite discards the whole interpreter in that case.
    • :error (the default) -- the decline surfaces as {:error, reason} from build/2.
    • :fallback -- build/2 builds again without the delegates that were added with this policy, and answers {:ok, :delegate_declined}. Only a decline is retried; every other failure still fails.

Note that an interpreter, and any delegate attached to it, belongs to one process at a time. Nothing here is serialised for you.

Link to this function

add_delegate!(self, delegate)

View Source

Raising version of add_delegate/2.

Link to this function

add_delegate!(self, delegate, opts)

View Source

Raising version of add_delegate/3.

Link to this function

build(self, interpreter)

View Source
@spec build(reference(), reference()) :: :ok | {:ok, :delegate_declined} | nif_error()

Build the interpreter with the InterpreterBuilder.

Note: all Interpreters should be built with the InterpreterBuilder, which allocates memory for the Interpreter and does various set up tasks so that the Interpreter can read the provided model.

Link to this function

build!(self, interpreter)

View Source

Raising version of build/2.

Link to this function

new(flat_buffer_model, resolver)

View Source
@spec new(
  %TFLiteElixir.FlatBufferModel{
    initialized: term(),
    minimum_runtime: term(),
    model: term()
  },
  reference()
) :: nif_resource_ok() | nif_error()

New InterpreterBuilder

Raising version of new/2.

Link to this function

set_num_threads(self, num_threads)

View Source
@spec set_num_threads(reference(), integer()) :: :ok | nif_error()

Sets the number of CPU threads to use for the interpreter. Returns true on success, {:error, reason} on error.

Link to this function

set_num_threads!(self, num_threads)

View Source

Raising version of set_num_threads/2.