View Source TFLiteElixir.FlatBufferModel (tflite_elixir v0.1.4)

An RAII object that represents a read-only tflite model, copied from disk, or mmapped.

Link to this section Summary

Functions

Build model from caller owned memory buffer

Build model from a given tflite file

Returns the minimum runtime version from the flatbuffer. This runtime version encodes the minimum required interpreter version to run the flatbuffer model. If the minimum version can't be determined, an empty string will be returned.

Raising version of initialized/1.

Return model metadata as a mapping of name & buffer strings.

Link to this section Types

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

Link to this section Functions

Link to this function

build_from_buffer(buffer)

View Source
@spec build_from_buffer(binary()) ::
  %TFLiteElixir.FlatBufferModel{model: term()} | nif_error()

Build model from caller owned memory buffer

Note that buffer will NOT be copied. Caller has the ensure that the buffer lives longer than the returned reference of TFLite.FlatBufferModel

Discussion:

We can copy the data in the NIF, but FlatBufferModel::BuildFromBuffer always assumes that the buffer is owner by the caller, (in this case, the binding code)

However, we would have no way to release the copied memory because we couldn't identify if the allocation_ borrows or owns that memory.

Link to this function

build_from_buffer!(buffer)

View Source

Raising version of build_from_buffer/1.

Link to this function

build_from_file(filename)

View Source
@spec build_from_file(String.t()) ::
  %TFLiteElixir.FlatBufferModel{model: term()} | nif_error()

Build model from a given tflite file

Note that if the tensorflow-lite library was compiled with TFLITE_MCU, then this function will always have return type nif_error()

Link to this function

build_from_file!(filename)

View Source

Raising version of build_from_file/1.

Link to this function

get_minimum_runtime(flat_buffer_model)

View Source
@spec get_minimum_runtime(%TFLiteElixir.FlatBufferModel{model: term()}) ::
  String.t() | nif_error()

Returns the minimum runtime version from the flatbuffer. This runtime version encodes the minimum required interpreter version to run the flatbuffer model. If the minimum version can't be determined, an empty string will be returned.

Note that the returned minimum version is a lower-bound but not a strict lower-bound; ops in the graph may not have an associated runtime version, in which case the actual required runtime might be greater than the reported minimum.

Link to this function

get_minimum_runtime!(self)

View Source

Raising version of get_minimum_runtime/1.

Link to this function

initialized(flat_buffer_model)

View Source
@spec initialized(%TFLiteElixir.FlatBufferModel{model: term()}) ::
  bool() | nif_error()

Raising version of initialized/1.

Link to this function

read_all_metadata(flat_buffer_model)

View Source
@spec read_all_metadata(%TFLiteElixir.FlatBufferModel{model: term()}) ::
  %{required(String.t()) => String.t()} | nif_error()

Return model metadata as a mapping of name & buffer strings.

See Metadata table in TFLite schema.

Link to this function

read_all_metadata!(self)

View Source

Raising version of read_all_metadata/1.