tflite::impl::FlatBufferModel

Summary

Constructors and Destructors

FlatBufferModel(const FlatBufferModel &)
~FlatBufferModel()

Public static functions

BuildFromAllocation(std::unique_ptr< Allocation > allocation, ErrorReporter *error_reporter)
std::unique_ptr< FlatBufferModel >
Builds a model directly from an allocation.
BuildFromBuffer(const char *caller_owned_buffer, size_t buffer_size, ErrorReporter *error_reporter)
std::unique_ptr< FlatBufferModel >
Builds a model based on a pre-loaded flatbuffer.
BuildFromFile(const char *filename, ErrorReporter *error_reporter)
std::unique_ptr< FlatBufferModel >
Builds a model based on a file.
BuildFromModel(const tflite::Model *caller_owned_model_spec, ErrorReporter *error_reporter)
std::unique_ptr< FlatBufferModel >
Builds a model directly from a flatbuffer pointer Caller retains ownership of the buffer and should keep it alive until the returned object is destroyed.
ByteConvertModel(std::unique_ptr< FlatBufferModel > model, ErrorReporter *error_reporter, bool from_big_endian)
std::unique_ptr< FlatBufferModel >
Convert the TFLite buffers field between LE and BE format in a FlatBufferModel which is not empty and return the converted instance.
ByteSwapBuffer(int8_t tensor_type, size_t buffer_size, uint8_t *buffer, bool from_big_endian)
void
Byte swap a constant buffer in place.
ByteSwapFlatBufferModel(std::unique_ptr< FlatBufferModel > model, ErrorReporter *error_reporter, bool from_big_endian)
std::unique_ptr< FlatBufferModel >
Byte Swap the TFLite buffers field in a FlatBufferModel and return the swapped instance.
ByteSwapSerializedModel(std::string *serialized_model, bool from_big_endian)
void
Byte Swap the serialized String of a TFLite model in place.
ByteSwapTFLiteModel(const tflite::Model *tfl_model, bool from_big_endian)
void
Byte swap the buffers field of a TFLite Model instance in place.
ByteSwapTFLiteModelT(tflite::ModelT *tfl_modelt, bool from_big_endian)
void
Byte swap the buffers field of a TFLite ModelT instance in place.
CheckBufferOutsideModel(const tflite::Model *model)
bool
ReadAllMetadata(const ::tflite::Model *model)
std::map< std::string, std::string >
VerifyAndBuildFromAllocation(std::unique_ptr< Allocation > allocation, TfLiteVerifier *extra_verifier, ErrorReporter *error_reporter)
std::unique_ptr< FlatBufferModel >
Verifies whether the content of the allocation is legit, then builds a model based on the provided allocation.
VerifyAndBuildFromBuffer(const char *caller_owned_buffer, size_t buffer_size, TfLiteVerifier *extra_verifier, ErrorReporter *error_reporter)
std::unique_ptr< FlatBufferModel >
Verifies whether the content of the buffer is legit, then builds a model based on the pre-loaded flatbuffer.
VerifyAndBuildFromFile(const char *filename, TfLiteVerifier *extra_verifier, ErrorReporter *error_reporter)
std::unique_ptr< FlatBufferModel >
Verifies whether the content of the file is legit, then builds a model based on the file.

Public functions

CheckModelIdentifier() const
bool
Returns true if the model identifier is correct (otherwise false and reports an error).
GetMinimumRuntime() const
std::string
GetModel() const
const tflite::Model *
ReadAllMetadata() const
std::map< std::string, std::string >
ValidateModelBuffers(ErrorReporter *error_reporter)
void
allocation() const
const Allocation *
error_reporter() const
initialized() const
bool
operator->() const
const tflite::Model *
operator=(const FlatBufferModel &)=delete
FlatBufferModel &

Public static functions

BuildFromAllocation

std::unique_ptr< FlatBufferModel > BuildFromAllocation(
  std::unique_ptr< Allocation > allocation,
  ErrorReporter *error_reporter
)

Builds a model directly from an allocation.

Ownership of the allocation is passed to the model, but the caller retains ownership of error_reporter and must ensure its lifetime is longer than the FlatBufferModel instance. Returns a nullptr in case of failure (e.g., the allocation is invalid).

BuildFromBuffer

std::unique_ptr< FlatBufferModel > BuildFromBuffer(
  const char *caller_owned_buffer,
  size_t buffer_size,
  ErrorReporter *error_reporter
)

Builds a model based on a pre-loaded flatbuffer.

Caller retains ownership of the buffer and should keep it alive until the returned object is destroyed. Caller also retains ownership of error_reporter and must ensure its lifetime is longer than the FlatBufferModel instance. Returns a nullptr in case of failure. NOTE: this does NOT validate the buffer so it should NOT be called on invalid/untrusted input. Use VerifyAndBuildFromBuffer in that case

BuildFromFile

std::unique_ptr< FlatBufferModel > BuildFromFile(
  const char *filename,
  ErrorReporter *error_reporter
)

Builds a model based on a file.

Caller retains ownership of error_reporter and must ensure its lifetime is longer than the FlatBufferModel instance. Returns a nullptr in case of failure.

BuildFromModel

std::unique_ptr< FlatBufferModel > BuildFromModel(
  const tflite::Model *caller_owned_model_spec,
  ErrorReporter *error_reporter
)

Builds a model directly from a flatbuffer pointer Caller retains ownership of the buffer and should keep it alive until the returned object is destroyed.

Caller retains ownership of error_reporter and must ensure its lifetime is longer than the FlatBufferModel instance. Returns a nullptr in case of failure.

ByteConvertModel

std::unique_ptr< FlatBufferModel > ByteConvertModel(
  std::unique_ptr< FlatBufferModel > model,
  ErrorReporter *error_reporter,
  bool from_big_endian
)

Convert the TFLite buffers field between LE and BE format in a FlatBufferModel which is not empty and return the converted instance.

ByteSwapBuffer

void ByteSwapBuffer(
  int8_t tensor_type,
  size_t buffer_size,
  uint8_t *buffer,
  bool from_big_endian
)

Byte swap a constant buffer in place.

ByteSwapFlatBufferModel

std::unique_ptr< FlatBufferModel > ByteSwapFlatBufferModel(
  std::unique_ptr< FlatBufferModel > model,
  ErrorReporter *error_reporter,
  bool from_big_endian
)

Byte Swap the TFLite buffers field in a FlatBufferModel and return the swapped instance.

ByteSwapSerializedModel

void ByteSwapSerializedModel(
  std::string *serialized_model,
  bool from_big_endian
)

Byte Swap the serialized String of a TFLite model in place.

ByteSwapTFLiteModel

void ByteSwapTFLiteModel(
  const tflite::Model *tfl_model,
  bool from_big_endian
)

Byte swap the buffers field of a TFLite Model instance in place.

ByteSwapTFLiteModelT

void ByteSwapTFLiteModelT(
  tflite::ModelT *tfl_modelt,
  bool from_big_endian
)

Byte swap the buffers field of a TFLite ModelT instance in place.

CheckBufferOutsideModel

bool CheckBufferOutsideModel(
  const tflite::Model *model
)

ReadAllMetadata

std::map< std::string, std::string > ReadAllMetadata(
  const ::tflite::Model *model
)

VerifyAndBuildFromAllocation

std::unique_ptr< FlatBufferModel > VerifyAndBuildFromAllocation(
  std::unique_ptr< Allocation > allocation,
  TfLiteVerifier *extra_verifier,
  ErrorReporter *error_reporter
)

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

The extra_verifier argument is an additional optional verifier for the buffer. By default, we always check with tflite::VerifyModelBuffer. If extra_verifier is supplied, the buffer is checked against the extra_verifier after the check against tflite::VerifyModelBuilder. Ownership of the allocation is passed to the model, but the caller retains ownership of error_reporter and must ensure its lifetime is longer than the FlatBufferModel instance. Returns a nullptr in case of failure.

VerifyAndBuildFromBuffer

std::unique_ptr< FlatBufferModel > VerifyAndBuildFromBuffer(
  const char *caller_owned_buffer,
  size_t buffer_size,
  TfLiteVerifier *extra_verifier,
  ErrorReporter *error_reporter
)

Verifies whether the content of the buffer is legit, then builds a model based on the pre-loaded flatbuffer.

The extra_verifier argument is an additional optional verifier for the buffer. By default, we always check with tflite::VerifyModelBuffer. If extra_verifier is supplied, the buffer is checked against the extra_verifier after the check against tflite::VerifyModelBuilder. The caller retains ownership of the buffer and should keep it alive until the returned object is destroyed. Caller retains ownership of error_reporter and must ensure its lifetime is longer than the FlatBufferModel instance. Returns a nullptr in case of failure.

VerifyAndBuildFromFile

std::unique_ptr< FlatBufferModel > VerifyAndBuildFromFile(
  const char *filename,
  TfLiteVerifier *extra_verifier,
  ErrorReporter *error_reporter
)

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

The extra_verifier argument is an additional optional verifier for the file contents. By default, we always check with tflite::VerifyModelBuffer. If extra_verifier is supplied, the file contents is also checked against the extra_verifier after the check against tflite::VerifyModelBuilder. Caller retains ownership of error_reporter and must ensure its lifetime is longer than the FlatBufferModel instance. Returns a nullptr in case of failure.

Public functions

CheckModelIdentifier

bool CheckModelIdentifier() const 

Returns true if the model identifier is correct (otherwise false and reports an error).

FlatBufferModel

 FlatBufferModel(
  const FlatBufferModel &
)=delete

GetMinimumRuntime

std::string GetMinimumRuntime() const