ArmNN
 20.08
CommandLineProcessor Class Reference

#include <CommandLineProcessor.hpp>

Public Member Functions

bool ProcessCommandLine (int argc, char *argv[])
 
std::string GetInputFileName ()
 
std::string GetCsvFileName ()
 
std::string GetCsvFileDirectory ()
 
std::string GetOutputDirectoryName ()
 
std::string GetOutputFileName ()
 
std::string GetQuantizationScheme ()
 
QuantizationDataSet GetQuantizationDataSet ()
 
bool HasPreservedDataType ()
 
bool HasQuantizationData ()
 

Protected Attributes

std::string m_InputFileName
 
std::string m_CsvFileName
 
std::string m_CsvFileDirectory
 
std::string m_OutputDirectory
 
std::string m_OutputFileName
 
std::string m_QuantizationScheme
 
QuantizationDataSet m_QuantizationDataSet
 
bool m_PreserveDataType
 

Detailed Description

Definition at line 25 of file CommandLineProcessor.hpp.

Member Function Documentation

◆ GetCsvFileDirectory()

std::string GetCsvFileDirectory ( )
inline

◆ GetCsvFileName()

std::string GetCsvFileName ( )
inline

◆ GetInputFileName()

std::string GetInputFileName ( )
inline

Definition at line 30 of file CommandLineProcessor.hpp.

References CommandLineProcessor::m_InputFileName.

Referenced by main().

◆ GetOutputDirectoryName()

std::string GetOutputDirectoryName ( )
inline

Definition at line 33 of file CommandLineProcessor.hpp.

References CommandLineProcessor::m_OutputDirectory.

Referenced by main().

◆ GetOutputFileName()

std::string GetOutputFileName ( )
inline

Definition at line 34 of file CommandLineProcessor.hpp.

References CommandLineProcessor::m_OutputFileName.

Referenced by main().

◆ GetQuantizationDataSet()

QuantizationDataSet GetQuantizationDataSet ( )
inline

Definition at line 36 of file CommandLineProcessor.hpp.

References CommandLineProcessor::m_QuantizationDataSet.

Referenced by main().

◆ GetQuantizationScheme()

std::string GetQuantizationScheme ( )
inline

◆ HasPreservedDataType()

bool HasPreservedDataType ( )
inline

◆ HasQuantizationData()

bool HasQuantizationData ( )
inline

◆ ProcessCommandLine()

bool ProcessCommandLine ( int  argc,
char *  argv[] 
)

Definition at line 84 of file CommandLineProcessor.cpp.

References CommandLineProcessor::m_CsvFileDirectory, CommandLineProcessor::m_CsvFileName, CommandLineProcessor::m_InputFileName, CommandLineProcessor::m_OutputDirectory, CommandLineProcessor::m_OutputFileName, CommandLineProcessor::m_PreserveDataType, CommandLineProcessor::m_QuantizationDataSet, CommandLineProcessor::m_QuantizationScheme, armnnQuantizer::ValidateOutputDirectory(), armnnQuantizer::ValidateProvidedFile(), and armnnQuantizer::ValidateQuantizationScheme().

Referenced by main().

85 {
86  namespace po = boost::program_options;
87 
88  po::options_description desc("Options");
89  try
90  {
91  desc.add_options()
92  ("help,h", "Display help messages")
93  ("infile,f", po::value<std::string>(&m_InputFileName)->required(),
94  "Input file containing float 32 ArmNN Input Graph")
95  ("scheme,s", po::value<std::string>(&m_QuantizationScheme)->default_value("QAsymmU8"),
96  "Quantization scheme,"
97  " \"QAsymmU8\" or \"QAsymmS8\" or \"QSymm16\","
98  " default value QAsymmU8")
99  ("csvfile,c", po::value<std::string>(&m_CsvFileName)->default_value(""),
100  "CSV file containing paths for RAW input tensors")
101  ("preserve-data-type,p", po::bool_switch(&m_PreserveDataType)->default_value(false),
102  "Preserve the input and output data types")
103  ("outdir,d", po::value<std::string>(&m_OutputDirectory)->required(),
104  "Directory that output file will be written to")
105  ("outfile,o", po::value<std::string>(&m_OutputFileName)->required(), "ArmNN output file name");
106  }
107  catch (const std::exception& e)
108  {
109  std::cerr << "Fatal internal error: [" << e.what() << "]" << std::endl;
110  return false;
111  }
112 
113  po::variables_map vm;
114 
115  try
116  {
117  po::store(po::parse_command_line(argc, argv, desc), vm);
118 
119  if (vm.count("help") || argc <= 1)
120  {
121  std::cout << "Convert a Fp32 ArmNN model to a quantized ArmNN model." << std::endl;
122  std::cout << std::endl;
123  std::cout << desc << std::endl;
124  return false;
125  }
126 
127  po::notify(vm);
128  }
129  catch (const po::error& e)
130  {
131  std::cerr << e.what() << std::endl << std::endl;
132  std::cerr << desc << std::endl;
133  return false;
134  }
135 
137  {
138  return false;
139  }
140 
142  {
143  return false;
144  }
145 
146  if (m_CsvFileName != "")
147  {
149  {
150  return false;
151  }
152  else
153  {
154  fs::path csvFilePath(m_CsvFileName);
155  m_CsvFileDirectory = csvFilePath.parent_path().c_str();
156  }
157 
158  // If CSV file is defined, create a QuantizationDataSet for specified CSV file.
159  m_QuantizationDataSet = QuantizationDataSet(m_CsvFileName);
160  }
161 
163  {
164  return false;
165  }
166 
167  std::string output(m_OutputDirectory);
168  output.append(m_OutputFileName);
169 
170  if (fs::exists(output))
171  {
172  std::cerr << "Output file [" << output << "] already exists" << std::endl;
173  return false;
174  }
175 
176  return true;
177 }
bool ValidateQuantizationScheme(const std::string &scheme)
bool ValidateOutputDirectory(std::string &dir)
bool ValidateProvidedFile(const std::string &inputFileName)

Member Data Documentation

◆ m_CsvFileDirectory

std::string m_CsvFileDirectory
protected

◆ m_CsvFileName

std::string m_CsvFileName
protected

◆ m_InputFileName

std::string m_InputFileName
protected

◆ m_OutputDirectory

std::string m_OutputDirectory
protected

◆ m_OutputFileName

std::string m_OutputFileName
protected

◆ m_PreserveDataType

bool m_PreserveDataType
protected

◆ m_QuantizationDataSet

◆ m_QuantizationScheme

std::string m_QuantizationScheme
protected

The documentation for this class was generated from the following files: