ArmNN
 24.08
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>
Include dependency graph for ArmnnConverter.cpp:

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 329 of file ArmnnConverter.cpp.

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

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

armnn::ConfigureLogging
void ConfigureLogging(bool printToStandardOutput, bool printToDebugOutput, LogSeverity severity)
Configures the logging behaviour of the ARMNN library.
Definition: Utils.cpp:20
armnn::LogSeverity::Info
@ Info
armnn::Exception::what
virtual const char * what() const noexcept override
Definition: Exceptions.cpp:32
ARMNN_LOG
#define ARMNN_LOG(severity)
Definition: Logging.hpp:212
armnn::TensorShape
Definition: Tensor.hpp:20
armnn::InvalidArgumentException
Definition: Exceptions.hpp:80
armnn::Exception
Base class for all ArmNN exceptions so that users can filter to just those.
Definition: Exceptions.hpp:46
armnnOnnxParser::IOnnxParser
Definition: IOnnxParser.hpp:23
armnn::LogSeverity::Debug
@ Debug
armnn::LogSeverity
LogSeverity
Definition: Utils.hpp:13
armnnTfLiteParser::ITfLiteParser
Definition: ITfLiteParser.hpp:26