MCPcopy Create free account
hub / github.com/ARM-software/armnn / Execute

Method Execute

tests/ExecuteNetwork/TfliteExecutor.cpp:227–409  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

225}
226
227std::vector<const void *> TfLiteExecutor::Execute()
228{
229 TfLiteStatus status;
230 std::vector<const void*> results;
231 for (unsigned int x = 0; x < m_Params.m_Iterations; x++)
232 {
233 // Start timer to record inference time in milliseconds.
234 const auto start_time = armnn::GetTimeNow();
235 // Run the inference
236 status = m_TfLiteInterpreter->Invoke();
237 if (status != kTfLiteOk)
238 {
239 LogAndThrow("Failed to execute the inference on the TfLite runtime.. The result was: " +
240 TfLiteStatusToString(status) + ".");
241 }
242 const auto duration = armnn::GetTimeDuration(start_time);
243
244 // Handle the results.
245 for (unsigned int outputIndex = 0; outputIndex < m_TfLiteInterpreter->outputs().size(); ++outputIndex)
246 {
247 auto tfLiteDelegateOutputId = m_TfLiteInterpreter->outputs()[outputIndex];
248 TfLiteIntArray* outputDims = m_TfLiteInterpreter->tensor(tfLiteDelegateOutputId)->dims;
249 // If we've been asked to write to a file then set a file output stream. Otherwise, use stdout.
250 FILE* outputTensorFile = stdout;
251 bool isNumpyOutput = false;
252 if (!m_Params.m_OutputTensorFiles.empty())
253 {
254 isNumpyOutput = m_Params.m_OutputTensorFiles[outputIndex].find(".npy") != std::string::npos;
255 outputTensorFile = fopen(m_Params.m_OutputTensorFiles[outputIndex].c_str(), "w");
256 if (outputTensorFile == NULL)
257 {
258 LogAndThrow("Specified output tensor file, \"" + m_Params.m_OutputTensorFiles[outputIndex] +
259 "\", cannot be created. Defaulting to stdout. Error was: " + std::strerror(errno));
260 }
261 else
262 {
263 ARMNN_LOG(info) << "Writing output " << outputIndex << " of iteration: " << x + 1
264 << " to file: '" << m_Params.m_OutputTensorFiles[outputIndex] << "'";
265 }
266 }
267
268 long outputSize = 1;
269 for (unsigned int dim = 0; dim < static_cast<unsigned int>(outputDims->size); ++dim)
270 {
271 outputSize *= outputDims->data[dim];
272 }
273
274 // outputDims->data can be a Flexible Array Member (int data[];) in a C extern code in TF common.h
275 // TensorShape constructor argument is an unsigned int *
276 // so reinterpret_cast is used here to ensure the correct type of data is passed
277 armnn::TensorShape shape(static_cast<unsigned int>(outputDims->size),
278 reinterpret_cast<unsigned int *>(outputDims->data));
279 armnn::DataType dataType(GetDataType(*m_TfLiteInterpreter->tensor(tfLiteDelegateOutputId)));
280
281 std::cout << m_TfLiteInterpreter->tensor(tfLiteDelegateOutputId)->name << ": ";
282 switch (m_TfLiteInterpreter->tensor(tfLiteDelegateOutputId)->type)
283 {
284 case kTfLiteFloat32:

Callers

nothing calls this directly

Calls 12

GetTimeNowFunction · 0.85
LogAndThrowFunction · 0.85
TfLiteStatusToStringFunction · 0.85
GetTimeDurationFunction · 0.85
WriteToNumpyFileFunction · 0.85
emptyMethod · 0.80
push_backMethod · 0.80
GetDataTypeFunction · 0.50
InvokeMethod · 0.45
sizeMethod · 0.45
c_strMethod · 0.45

Tested by

no test coverage detected