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
Raising version of build_from_file/2
.
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
@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.
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.
Raising version of build_from_file/2
.
@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.
@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
@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.
@spec initialized(%TFLiteElixir.FlatBufferModel{ initialized: term(), minimum_runtime: term(), model: term() }) :: bool() | nif_error()
Check whether current model has been initialized
Get a list of all associated file(s) in a TFLite model file
@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.
@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.