From 41ff7f8da0ac12012d1eef7be6d160f9e17c2aec Mon Sep 17 00:00:00 2001 From: Matthew Sloyan Date: Thu, 8 Oct 2020 16:41:47 +0100 Subject: IVGCVSW-5279 Switch armnnQuantizer over to cxxopts Signed-off-by: Matthew Sloyan Change-Id: I79f12ba33b3ca58cdc4be531ffbf72fa20690792 --- src/armnnQuantizer/CommandLineProcessor.cpp | 85 ++++++++++++++++------------- 1 file changed, 46 insertions(+), 39 deletions(-) (limited to 'src/armnnQuantizer') diff --git a/src/armnnQuantizer/CommandLineProcessor.cpp b/src/armnnQuantizer/CommandLineProcessor.cpp index ace4a506fb..74ad5e7dbc 100644 --- a/src/armnnQuantizer/CommandLineProcessor.cpp +++ b/src/armnnQuantizer/CommandLineProcessor.cpp @@ -6,7 +6,7 @@ #include "CommandLineProcessor.hpp" #include -#include +#include namespace armnnQuantizer { @@ -83,53 +83,60 @@ bool ValidateQuantizationScheme(const std::string& scheme) bool CommandLineProcessor::ProcessCommandLine(int argc, char* argv[]) { - namespace po = boost::program_options; - - po::options_description desc("Options"); try { - desc.add_options() - ("help,h", "Display help messages") - ("infile,f", po::value(&m_InputFileName)->required(), - "Input file containing float 32 ArmNN Input Graph") - ("scheme,s", po::value(&m_QuantizationScheme)->default_value("QAsymmU8"), - "Quantization scheme," - " \"QAsymmU8\" or \"QAsymmS8\" or \"QSymm16\"," - " default value QAsymmU8") - ("csvfile,c", po::value(&m_CsvFileName)->default_value(""), - "CSV file containing paths for RAW input tensors") - ("preserve-data-type,p", po::bool_switch(&m_PreserveDataType)->default_value(false), - "Preserve the input and output data types") - ("outdir,d", po::value(&m_OutputDirectory)->required(), - "Directory that output file will be written to") - ("outfile,o", po::value(&m_OutputFileName)->required(), "ArmNN output file name"); - } - catch (const std::exception& e) - { - std::cerr << "Fatal internal error: [" << e.what() << "]" << std::endl; - return false; - } - - po::variables_map vm; - - try - { - po::store(po::parse_command_line(argc, argv, desc), vm); - - if (vm.count("help") || argc <= 1) + cxxopts::Options options("ArmnnQuantizer","Convert a Fp32 ArmNN model to a quantized ArmNN model."); + + options.add_options() + ("h,help", "Display help messages") + ("f,infile", + "Input file containing float 32 ArmNN Input Graph", + cxxopts::value(m_InputFileName)) + ("s,scheme", + "Quantization scheme," + " \"QAsymmU8\" or \"QAsymmS8\" or \"QSymm16\"," + " default value QAsymmU8", + cxxopts::value(m_QuantizationScheme)->default_value("QAsymmU8")) + ("c,csvfile", + "CSV file containing paths for RAW input tensors", + cxxopts::value(m_CsvFileName)->default_value("")) + ("p,preserve-data-type", + "Preserve the input and output data types", + cxxopts::value(m_PreserveDataType)->default_value("false")) + ("d,outdir", + "Directory that output file will be written to", + cxxopts::value(m_OutputDirectory)) + ("o,outfile", + "ArmNN output file name", + cxxopts::value(m_OutputFileName)); + + auto result = options.parse(argc, argv); + + if (result.count("help") > 0 || argc <= 1) { - std::cout << "Convert a Fp32 ArmNN model to a quantized ArmNN model." << std::endl; - std::cout << std::endl; - std::cout << desc << std::endl; + std::cout << options.help() << std::endl; return false; } - po::notify(vm); + // Check for mandatory single options. + std::string mandatorySingleParameters[] = { "infile", "outdir", "outfile" }; + for (auto param : mandatorySingleParameters) + { + if (result.count(param) != 1) + { + std::cerr << "Parameter \'--" << param << "\' is required but missing." << std::endl; + return false; + } + } } - catch (const po::error& e) + catch (const cxxopts::OptionException& e) { std::cerr << e.what() << std::endl << std::endl; - std::cerr << desc << std::endl; + return false; + } + catch (const std::exception& e) + { + std::cerr << "Fatal internal error: [" << e.what() << "]" << std::endl; return false; } -- cgit v1.2.1