From 7a1966cb95baa9de08d7cecc189f5f85bf9ca9dc Mon Sep 17 00:00:00 2001 From: James Ward Date: Mon, 5 Oct 2020 17:11:23 +0100 Subject: IVGCVSW-5287 Switch tests/MultipleNetworksCifar10 over to cxxopts Signed-off-by: James Ward Change-Id: Ia4ff69f2c8dd538ad7845053dc7a690f434c381c --- .../MultipleNetworksCifar10.cpp | 106 ++++++++++----------- 1 file changed, 53 insertions(+), 53 deletions(-) (limited to 'tests') diff --git a/tests/MultipleNetworksCifar10/MultipleNetworksCifar10.cpp b/tests/MultipleNetworksCifar10/MultipleNetworksCifar10.cpp index 6f9a9c8c54..456ff68e7c 100644 --- a/tests/MultipleNetworksCifar10/MultipleNetworksCifar10.cpp +++ b/tests/MultipleNetworksCifar10/MultipleNetworksCifar10.cpp @@ -2,10 +2,6 @@ // Copyright © 2017 Arm Ltd. All rights reserved. // SPDX-License-Identifier: MIT // -#include -#include -#include -#include #include "armnn/ArmNN.hpp" #include "armnn/Utils.hpp" @@ -15,6 +11,14 @@ #include "../InferenceTest.hpp" #include "../InferenceModel.hpp" +#include + +#include +#include +#include +#include + + using namespace std; using namespace std::chrono; using namespace armnn::test; @@ -31,65 +35,61 @@ int main(int argc, char* argv[]) { // Configures logging for both the ARMNN library and this test program. armnn::ConfigureLogging(true, true, level); - namespace po = boost::program_options; std::vector computeDevice; - std::vector defaultBackends = {armnn::Compute::CpuAcc, armnn::Compute::CpuRef}; std::string modelDir; std::string dataDir; const std::string backendsMessage = "Which device to run layers on by default. Possible choices: " + armnn::BackendRegistryInstance().GetBackendIdsAsString(); - po::options_description desc("Options"); - try - { - // Adds generic options needed for all inference tests. - desc.add_options() - ("help", "Display help messages") - ("model-dir,m", po::value(&modelDir)->required(), - "Path to directory containing the Cifar10 model file") - ("compute,c", po::value>(&computeDevice)->default_value(defaultBackends), - backendsMessage.c_str()) - ("data-dir,d", po::value(&dataDir)->required(), - "Path to directory containing the Cifar10 test data"); - } - catch (const std::exception& e) - { - // Coverity points out that default_value(...) can throw a bad_lexical_cast, - // and that desc.add_options() can throw boost::io::too_few_args. - // They really won't in any of these cases. - ARMNN_ASSERT_MSG(false, "Caught unexpected exception"); - std::cerr << "Fatal internal error: " << e.what() << std::endl; - return 1; - } - - po::variables_map vm; + cxxopts::Options in_options("MultipleNetworksCifar10", + "Run multiple networks inference tests using Cifar-10 data."); try { - po::store(po::parse_command_line(argc, argv, desc), vm); - - if (vm.count("help")) + // Adds generic options needed for all inference tests. + in_options.add_options() + ("h,help", "Display help messages") + ("m,model-dir", "Path to directory containing the Cifar10 model file", + cxxopts::value(modelDir)) + ("c,compute", backendsMessage.c_str(), + cxxopts::value>(computeDevice)->default_value("CpuAcc,CpuRef")) + ("d,data-dir", "Path to directory containing the Cifar10 test data", + cxxopts::value(dataDir)); + + auto result = in_options.parse(argc, argv); + + if(result.count("help") > 0) { - std::cout << desc << std::endl; - return 1; + std::cout << in_options.help() << std::endl; + return EXIT_FAILURE; } - po::notify(vm); + //ensure mandatory parameters given + std::string mandatorySingleParameters[] = {"model-dir", "data-dir"}; + for (auto param : mandatorySingleParameters) + { + if(result.count(param) > 0) + { + std::string dir = result[param].as(); + + if(!ValidateDirectory(dir)) { + return EXIT_FAILURE; + } + } else { + std::cerr << "Parameter \'--" << param << "\' is required but missing." << std::endl; + return EXIT_FAILURE; + } + } } - catch (po::error& e) + catch (const cxxopts::OptionException& e) { - std::cerr << e.what() << std::endl << std::endl; - std::cerr << desc << std::endl; - return 1; + std::cerr << e.what() << std::endl << in_options.help() << std::endl; + return EXIT_FAILURE; } - if (!ValidateDirectory(modelDir)) - { - return 1; - } - string modelPath = modelDir + "cifar10_full_iter_60000.caffemodel"; + fs::path modelPath = fs::path(modelDir + "/cifar10_full_iter_60000.caffemodel"); // Create runtime // This will also load dynamic backend in case that the dynamic backend path is specified @@ -142,7 +142,7 @@ int main(int argc, char* argv[]) std::stringstream message; message << "armnn::Exception ("<