ArmNN
 22.05.01
ArmnnConverter.cpp File Reference
#include <armnn/Logging.hpp>
#include <HeapProfiling.hpp>
#include <armnn/utility/NumericCast.hpp>
#include <armnn/utility/StringUtils.hpp>
#include <cxxopts/cxxopts.hpp>
#include <fmt/format.h>
#include <cstdlib>
#include <fstream>
#include <iostream>

Go to the source code of this file.

Macros

#define CXXOPTS_VECTOR_DELIMITER   '.'
 

Functions

int main (int argc, char *argv[])
 

Macro Definition Documentation

◆ CXXOPTS_VECTOR_DELIMITER

#define CXXOPTS_VECTOR_DELIMITER   '.'

Definition at line 27 of file ArmnnConverter.cpp.

Function Documentation

◆ main()

int main ( int  argc,
char *  argv[] 
)
Examples:
AsyncExecutionSample.cpp, CustomMemoryAllocatorSample.cpp, DynamicSample.cpp, and SimpleSample.cpp.

Definition at line 327 of file ArmnnConverter.cpp.

References ARMNN_LOG, armnn::ConfigureLogging(), armnn::Debug, armnn::Info, and Exception::what().

328 {
329 
330 #if (!defined(ARMNN_ONNX_PARSER) \
331  && !defined(ARMNN_TF_PARSER) \
332  && !defined(ARMNN_TF_LITE_PARSER))
333  ARMNN_LOG(fatal) << "Not built with any of the supported parsers Onnx, Tensorflow, or TfLite.";
334  return EXIT_FAILURE;
335 #endif
336 
337 #if !defined(ARMNN_SERIALIZER)
338  ARMNN_LOG(fatal) << "Not built with Serializer support.";
339  return EXIT_FAILURE;
340 #endif
341 
342 #ifdef NDEBUG
344 #else
346 #endif
347 
348  armnn::ConfigureLogging(true, true, level);
349 
350  std::string modelFormat;
351  std::string modelPath;
352 
353  std::vector<std::string> inputNames;
354  std::vector<std::string> inputTensorShapeStrs;
355  std::vector<armnn::TensorShape> inputTensorShapes;
356 
357  std::vector<std::string> outputNames;
358  std::string outputPath;
359 
360  bool isModelBinary = true;
361 
362  if (ParseCommandLineArgs(
363  argc, argv, modelFormat, modelPath, inputNames, inputTensorShapeStrs, outputNames, outputPath, isModelBinary)
364  != EXIT_SUCCESS)
365  {
366  return EXIT_FAILURE;
367  }
368 
369  for (const std::string& shapeStr : inputTensorShapeStrs)
370  {
371  if (!shapeStr.empty())
372  {
373  std::stringstream ss(shapeStr);
374 
375  try
376  {
377  armnn::TensorShape shape = ParseTensorShape(ss);
378  inputTensorShapes.push_back(shape);
379  }
380  catch (const armnn::InvalidArgumentException& e)
381  {
382  ARMNN_LOG(fatal) << "Cannot create tensor shape: " << e.what();
383  return EXIT_FAILURE;
384  }
385  }
386  }
387 
388  ArmnnConverter converter(modelPath, inputNames, inputTensorShapes, outputNames, outputPath, isModelBinary);
389 
390  try
391  {
392  if (modelFormat.find("onnx") != std::string::npos)
393  {
394 #if defined(ARMNN_ONNX_PARSER)
395  if (!converter.CreateNetwork<armnnOnnxParser::IOnnxParser>())
396  {
397  ARMNN_LOG(fatal) << "Failed to load model from file";
398  return EXIT_FAILURE;
399  }
400 #else
401  ARMNN_LOG(fatal) << "Not built with Onnx parser support.";
402  return EXIT_FAILURE;
403 #endif
404  }
405  else if (modelFormat.find("tflite") != std::string::npos)
406  {
407 #if defined(ARMNN_TF_LITE_PARSER)
408  if (!isModelBinary)
409  {
410  ARMNN_LOG(fatal) << "Unknown model format: '" << modelFormat << "'. Only 'binary' format supported \
411  for tflite files";
412  return EXIT_FAILURE;
413  }
414 
415  if (!converter.CreateNetwork<armnnTfLiteParser::ITfLiteParser>())
416  {
417  ARMNN_LOG(fatal) << "Failed to load model from file";
418  return EXIT_FAILURE;
419  }
420 #else
421  ARMNN_LOG(fatal) << "Not built with TfLite parser support.";
422  return EXIT_FAILURE;
423 #endif
424  }
425  else
426  {
427  ARMNN_LOG(fatal) << "Unknown model format: '" << modelFormat << "'";
428  return EXIT_FAILURE;
429  }
430  }
431  catch(armnn::Exception& e)
432  {
433  ARMNN_LOG(fatal) << "Failed to load model from file: " << e.what();
434  return EXIT_FAILURE;
435  }
436 
437  if (!converter.Serialize())
438  {
439  ARMNN_LOG(fatal) << "Failed to serialize model";
440  return EXIT_FAILURE;
441  }
442 
443  return EXIT_SUCCESS;
444 }
void ConfigureLogging(bool printToStandardOutput, bool printToDebugOutput, LogSeverity severity)
Configures the logging behaviour of the ARMNN library.
Definition: Utils.cpp:18
virtual const char * what() const noexcept override
Definition: Exceptions.cpp:32
#define ARMNN_LOG(severity)
Definition: Logging.hpp:205
Base class for all ArmNN exceptions so that users can filter to just those.
Definition: Exceptions.hpp:46
LogSeverity
Definition: Utils.hpp:14