MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / FlatBufferModel

Class FlatBufferModel

tensorflow/lite/model.h:66–170  ·  view source on GitHub ↗

An RAII object that represents a read-only tflite model, copied from disk, or mmapped. This uses flatbuffers as the serialization format. NOTE: The current API requires that a FlatBufferModel instance be kept alive by the client as long as it is in use by any dependent Interpreter instances. using namespace tflite; StderrReporter error_reporter; auto model = FlatBufferModel::BuildFrom

Source from the content-addressed store, hash-verified

64/// interpreter. This is environment specific and may consist of just the
65/// builtin ops, or some custom operators you defined to extend tflite.
66class FlatBufferModel {
67 public:
68 /// Builds a model based on a file.
69 /// Caller retains ownership of `error_reporter` and must ensure its lifetime
70 /// is longer than the FlatBufferModel instance.
71 /// Returns a nullptr in case of failure.
72 static std::unique_ptr<FlatBufferModel> BuildFromFile(
73 const char* filename,
74 ErrorReporter* error_reporter = DefaultErrorReporter());
75
76 /// Verifies whether the content of the file is legit, then builds a model
77 /// based on the file.
78 /// The extra_verifier argument is an additional optional verifier for the
79 /// file contents. By default, we always check with tflite::VerifyModelBuffer.
80 /// If extra_verifier is supplied, the file contents is also checked against
81 /// the extra_verifier after the check against tflite::VerifyModelBuilder.
82 /// Caller retains ownership of `error_reporter` and must ensure its lifetime
83 /// is longer than the FlatBufferModel instance.
84 /// Returns a nullptr in case of failure.
85 static std::unique_ptr<FlatBufferModel> VerifyAndBuildFromFile(
86 const char* filename, TfLiteVerifier* extra_verifier = nullptr,
87 ErrorReporter* error_reporter = DefaultErrorReporter());
88
89 /// Builds a model based on a pre-loaded flatbuffer.
90 /// Caller retains ownership of the buffer and should keep it alive until
91 /// the returned object is destroyed. Caller also retains ownership of
92 /// `error_reporter` and must ensure its lifetime is longer than the
93 /// FlatBufferModel instance.
94 /// Returns a nullptr in case of failure.
95 /// NOTE: this does NOT validate the buffer so it should NOT be called on
96 /// invalid/untrusted input. Use VerifyAndBuildFromBuffer in that case
97 static std::unique_ptr<FlatBufferModel> BuildFromBuffer(
98 const char* caller_owned_buffer, size_t buffer_size,
99 ErrorReporter* error_reporter = DefaultErrorReporter());
100
101 /// Verifies whether the content of the buffer is legit, then builds a model
102 /// based on the pre-loaded flatbuffer.
103 /// The extra_verifier argument is an additional optional verifier for the
104 /// buffer. By default, we always check with tflite::VerifyModelBuffer. If
105 /// extra_verifier is supplied, the buffer is checked against the
106 /// extra_verifier after the check against tflite::VerifyModelBuilder. The
107 /// caller retains ownership of the buffer and should keep it alive until the
108 /// returned object is destroyed. Caller retains ownership of `error_reporter`
109 /// and must ensure its lifetime is longer than the FlatBufferModel instance.
110 /// Returns a nullptr in case of failure.
111 static std::unique_ptr<FlatBufferModel> VerifyAndBuildFromBuffer(
112 const char* buffer, size_t buffer_size,
113 TfLiteVerifier* extra_verifier = nullptr,
114 ErrorReporter* error_reporter = DefaultErrorReporter());
115
116 /// Builds a model directly from a flatbuffer pointer
117 /// Caller retains ownership of the buffer and should keep it alive until the
118 /// returned object is destroyed. Caller retains ownership of `error_reporter`
119 /// and must ensure its lifetime is longer than the FlatBufferModel instance.
120 /// Returns a nullptr in case of failure.
121 static std::unique_ptr<FlatBufferModel> BuildFromModel(
122 const tflite::Model* caller_owned_model_spec,
123 ErrorReporter* error_reporter = DefaultErrorReporter());

Callers

nothing calls this directly

Calls 1

DefaultErrorReporterFunction · 0.85

Tested by

no test coverage detected