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

Function TfLiteInterpreterCreate

tensorflow/lite/experimental/c/c_api.cc:96–141  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

94}
95
96TfLiteInterpreter* TfLiteInterpreterCreate(
97 const TfLiteModel* model,
98 const TfLiteInterpreterOptions* optional_options) {
99 if (!model || !model->impl) {
100 return nullptr;
101 }
102
103 std::unique_ptr<tflite::ErrorReporter> optional_error_reporter;
104 if (optional_options && optional_options->error_reporter != nullptr) {
105 optional_error_reporter.reset(
106 new CallbackErrorReporter(optional_options->error_reporter,
107 optional_options->error_reporter_user_data));
108 }
109
110 // TODO(b/111881878): Allow use of C API without pulling in all builtin ops.
111 tflite::ops::builtin::BuiltinOpResolver resolver;
112 if (optional_options) {
113 resolver.AddAll(optional_options->op_resolver);
114 }
115 tflite::ErrorReporter* error_reporter = optional_error_reporter
116 ? optional_error_reporter.get()
117 : tflite::DefaultErrorReporter();
118 tflite::InterpreterBuilder builder(model->impl->GetModel(), resolver,
119 error_reporter);
120
121 std::unique_ptr<tflite::Interpreter> interpreter;
122 if (builder(&interpreter) != kTfLiteOk) {
123 return nullptr;
124 }
125
126 if (optional_options) {
127 if (optional_options->num_threads !=
128 TfLiteInterpreterOptions::kDefaultNumThreads) {
129 interpreter->SetNumThreads(optional_options->num_threads);
130 }
131
132 for (auto* delegate : optional_options->delegates) {
133 if (interpreter->ModifyGraphWithDelegate(delegate) != kTfLiteOk) {
134 return nullptr;
135 }
136 }
137 }
138
139 return new TfLiteInterpreter{model->impl, std::move(optional_error_reporter),
140 std::move(interpreter)};
141}
142
143void TfLiteInterpreterDelete(TfLiteInterpreter* interpreter) {
144 delete interpreter;

Callers 3

TESTFunction · 0.85
TESTFunction · 0.85
InterpreterMethod · 0.85

Calls 7

DefaultErrorReporterFunction · 0.85
AddAllMethod · 0.80
resetMethod · 0.45
getMethod · 0.45
GetModelMethod · 0.45
SetNumThreadsMethod · 0.45

Tested by 2

TESTFunction · 0.68
TESTFunction · 0.68