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

Function RunInference

tensorflow/lite/examples/label_image/label_image.cc:139–319  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

137}
138
139void RunInference(Settings* s) {
140 if (!s->model_name.c_str()) {
141 LOG(ERROR) << "no model file name\n";
142 exit(-1);
143 }
144
145 std::unique_ptr<tflite::FlatBufferModel> model;
146 std::unique_ptr<tflite::Interpreter> interpreter;
147 model = tflite::FlatBufferModel::BuildFromFile(s->model_name.c_str());
148 if (!model) {
149 LOG(FATAL) << "\nFailed to mmap model " << s->model_name << "\n";
150 exit(-1);
151 }
152 s->model = model.get();
153 LOG(INFO) << "Loaded model " << s->model_name << "\n";
154 model->error_reporter();
155 LOG(INFO) << "resolved reporter\n";
156
157 tflite::ops::builtin::BuiltinOpResolver resolver;
158
159 tflite::InterpreterBuilder(*model, resolver)(&interpreter);
160 if (!interpreter) {
161 LOG(FATAL) << "Failed to construct interpreter\n";
162 exit(-1);
163 }
164
165 interpreter->UseNNAPI(s->old_accel);
166 interpreter->SetAllowFp16PrecisionForFp32(s->allow_fp16);
167
168 if (s->verbose) {
169 LOG(INFO) << "tensors size: " << interpreter->tensors_size() << "\n";
170 LOG(INFO) << "nodes size: " << interpreter->nodes_size() << "\n";
171 LOG(INFO) << "inputs: " << interpreter->inputs().size() << "\n";
172 LOG(INFO) << "input(0) name: " << interpreter->GetInputName(0) << "\n";
173
174 int t_size = interpreter->tensors_size();
175 for (int i = 0; i < t_size; i++) {
176 if (interpreter->tensor(i)->name)
177 LOG(INFO) << i << ": " << interpreter->tensor(i)->name << ", "
178 << interpreter->tensor(i)->bytes << ", "
179 << interpreter->tensor(i)->type << ", "
180 << interpreter->tensor(i)->params.scale << ", "
181 << interpreter->tensor(i)->params.zero_point << "\n";
182 }
183 }
184
185 if (s->number_of_threads != -1) {
186 interpreter->SetNumThreads(s->number_of_threads);
187 }
188
189 int image_width = 224;
190 int image_height = 224;
191 int image_channels = 3;
192 std::vector<uint8_t> in = read_bmp(s->input_bmp_name, &image_width,
193 &image_height, &image_channels, s);
194
195 int input = interpreter->inputs()[0];
196 if (s->verbose) LOG(INFO) << "input: " << input << "\n";

Callers 2

MainFunction · 0.85
TEST_FFunction · 0.85

Calls 15

exitFunction · 0.85
InterpreterBuilderClass · 0.85
read_bmpFunction · 0.85
GetDelegatesFunction · 0.85
PrintInterpreterStateFunction · 0.85
get_usFunction · 0.85
PrintProfilingInfoFunction · 0.85
c_strMethod · 0.80
ReadLabelsFileFunction · 0.70
getMethod · 0.45
error_reporterMethod · 0.45

Tested by 1

TEST_FFunction · 0.68