View Source TFLiteElixir.FlatBufferModel (tflite_elixir v0.3.7)

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

Summary

Functions

Build model from caller owned memory buffer

Build model from a given .tflite file

Get the error report of the current FlatBuffer model.

Get associated file(s) from a FlatBuffer model

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.

Check whether current model has been initialized

Get a list of all associated file(s) in a TFLite model file

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

Verifies whether the content of the file is legit, then builds a model based on the file.

Types

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

Functions

Link to this function

build_from_buffer(buffer, opts \\ [])

View Source
@spec build_from_buffer(binary(), Keyword.t()) ::
  %TFLiteElixir.FlatBufferModel{
    initialized: term(),
    minimum_runtime: term(),
    model: term()
  }
  | nif_error()

Build model from caller owned memory buffer

Note that buffer will be copied.

Link to this function

build_from_file(filename, opts \\ [])

View Source

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().

Keyword parameters
  • error_reporter: TFLiteElixir.ErrorReporter.

    Caller retains ownership of error_reporter and must ensure its lifetime is longer than the FlatBufferModel instance.

Link to this function

build_from_file!(filename, opts)

View Source

Raising version of build_from_file/2.

Link to this function

error_reporter(flat_buffer_model)

View Source
@spec error_reporter(%TFLiteElixir.FlatBufferModel{
  initialized: term(),
  minimum_runtime: term(),
  model: reference()
}) :: %TFLiteElixir.ErrorReporter{ref: term()} | {:error, String.t()}

Get the error report of the current FlatBuffer model.

Link to this function

get_associated_file(buffer, filename)

View Source
@spec get_associated_file(binary(), [String.t()] | String.t()) ::
  %{required(String.t()) => String.t()} | String.t() | nif_error()

Get associated file(s) from a FlatBuffer model

Link to this function

get_minimum_runtime(flat_buffer_model)

View Source
@spec get_minimum_runtime(%TFLiteElixir.FlatBufferModel{
  initialized: term(),
  minimum_runtime: term(),
  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

initialized(flat_buffer_model)

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

Check whether current model has been initialized

Link to this function

list_associated_files(buffer)

View Source
@spec list_associated_files(binary()) :: [String.t()] | nif_error()

Get a list of all associated file(s) in a TFLite model file

Link to this function

read_all_metadata(flat_buffer_model)

View Source
@spec read_all_metadata(%TFLiteElixir.FlatBufferModel{
  initialized: term(),
  minimum_runtime: term(),
  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

verify_and_build_from_file(filename, opts \\ [])

View Source
@spec verify_and_build_from_file(String.t(), Keyword.t()) ::
  %TFLiteElixir.FlatBufferModel{
    initialized: term(),
    minimum_runtime: term(),
    model: term()
  }
  | :invalid
  | {:error, String.t()}

Verifies whether the content of the file is legit, then builds a model based on the file.

Keyword parameters
  • error_reporter: TFLiteElixir.ErrorReporter.

    Caller retains ownership of error_reporter and must ensure its lifetime is longer than the FlatBufferModel instance.

Returns :invalid in case of failure.