blob: ce4a2c9dd1b81844402b3d4e1dddfcb3a4b9a782 [file] [log] [blame]
Georgios Pinitas12be7ab2018-07-03 12:06:23 +01001/*
2 * Copyright (c) 2018 ARM Limited.
3 *
4 * SPDX-License-Identifier: MIT
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to
8 * deal in the Software without restriction, including without limitation the
9 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
24#ifndef ARM_COMPUTE_EXAMPLES_UTILS_COMMON_GRAPH_OPTIONS
25#define ARM_COMPUTE_EXAMPLES_UTILS_COMMON_GRAPH_OPTIONS
26
27#include "utils/command_line/CommandLineOptions.h"
28#include "utils/command_line/CommandLineParser.h"
29
30#include "arm_compute/graph/TypeLoader.h"
31#include "arm_compute/graph/TypePrinter.h"
32
33namespace arm_compute
34{
35namespace utils
36{
Georgios Pinitas9f28b392018-07-18 20:01:53 +010037/* ![Common graph examples parameters] */
38/* Common graph parameters
39 *
40 * --help : Print the example's help message.
41 * --threads : The number of threads to be used by the example during execution.
42 * --target : Execution target to be used by the examples. Supported target options: NEON, CL, GC.
43 * --type : Data type to be used by the examples. Supported data type options: QASYMM8, F16, F32.
44 * --layout : Data layout to be used by the examples. Supported data layout options : NCHW, NHWC.
45 * --enable-tuner : Toggle option to enable the OpenCL dynamic tuner.
46 * --fast-math : Toggle option to enable the fast math option.
47 * --data : Path that contains the trainable parameter files of graph layers.
48 * --image : Image to load and operate on. Image types supported: PPM, JPEG, NPY.
49 * --labels : File that contains the labels that classify upon.
50 * --validation-file : File that contains a list of image names with their corresponding label id (e.g. image0.jpg 5).
51 * This is used to run the graph over a number of images and report top-1 and top-5 metrics.
52 * --validation-path : The path where the validation images specified in the validation file reside.
53 * --validation-range : The range of the images to validate from the validation file (e.g 0,9).
54 * If not specified all the images will be validated.
55 * --tuner-file : The file to store the OpenCL dynamic tuner tuned parameters.
56 *
57 * Note that data, image and labels options should be provided to perform an inference run on an image.
58 * Note that validation-file and validation-path should be provided to perform a graph accuracy estimation.
59 * Note GLES target is not supported for most of the networks.
60 *
61 * Example execution commands:
62 *
63 * Execute a single inference given an image and a file containing the correspondence between label ids and human readable labels:
64 * ./graph_vgg16 --data=data/ --target=cl --layout=nhwc --image=kart.jpeg --labels=imagenet1000_clsid_to_human.txt
65 *
66 * Perform a graph validation on a list of images:
67 * ./graph_vgg16 --data=data/ --target=neon --threads=4 --layout=nchw --validation-file=val.txt --validation-path=ilsvrc_test_images/
68 *
69 * File formats:
70 *
71 * Validation file should be a plain file containing the names of the images followed by the correct label id.
72 * For example:
73 *
74 * image0.jpeg 882
75 * image1.jpeg 34
76 * image2.jpeg 354
77 *
78 * Labels file should be a plain file where each line is the respective human readable label (counting starts from 0).
79 * For example:
80 *
81 * 0: label0_name label0_name
82 * 1: label1_name or label1_name
83 * 2: label2_name label2_name
84 */
85/* ![Common graph examples parameters] */
86
Georgios Pinitas12be7ab2018-07-03 12:06:23 +010087/** Structure holding all the common graph parameters */
88struct CommonGraphParams
89{
90 bool help{ false };
91 int threads{ 0 };
92 arm_compute::graph::Target target{ arm_compute::graph::Target::NEON };
93 arm_compute::DataType data_type{ DataType::F32 };
94 arm_compute::DataLayout data_layout{ DataLayout::NCHW };
95 bool enable_tuner{ false };
96 arm_compute::graph::FastMathHint fast_math_hint{ arm_compute::graph::FastMathHint::DISABLED };
97 std::string data_path{};
98 std::string image{};
99 std::string labels{};
100 std::string validation_file{};
101 std::string validation_path{};
Anthony Barbier7b607dc2018-07-13 15:55:24 +0100102 std::string tuner_file{};
Georgios Pinitas12be7ab2018-07-03 12:06:23 +0100103 unsigned int validation_range_start{ 0 };
104 unsigned int validation_range_end{ std::numeric_limits<unsigned int>::max() };
105};
106
107/** Formatted output of the CommonGraphParams type
108 *
109 * @param[out] os Output stream.
110 * @param[in] common_params Common parameters to output
111 *
112 * @return Modified output stream.
113 */
114::std::ostream &operator<<(::std::ostream &os, const CommonGraphParams &common_params);
115
116/** Common command line options used to configure the graph examples
117 *
118 * The options in this object get populated when "parse()" is called on the parser used to construct it.
119 * The expected workflow is:
120 *
121 * CommandLineParser parser;
122 * CommonOptions options( parser );
123 * parser.parse(argc, argv);
124 */
125class CommonGraphOptions
126{
127public:
128 /** Constructor
129 *
130 * @param[in,out] parser A parser on which "parse()" hasn't been called yet.
131 */
132 CommonGraphOptions(CommandLineParser &parser);
Gian Marco Iodice11a7e322018-07-05 15:42:02 +0100133 /** Prevent instances of this class from being copied (As this class contains pointers) */
Georgios Pinitas12be7ab2018-07-03 12:06:23 +0100134 CommonGraphOptions(const CommonGraphOptions &) = delete;
Gian Marco Iodice11a7e322018-07-05 15:42:02 +0100135 /** Prevent instances of this class from being copied (As this class contains pointers) */
Georgios Pinitas12be7ab2018-07-03 12:06:23 +0100136 CommonGraphOptions &operator=(const CommonGraphOptions &) = delete;
Gian Marco Iodice11a7e322018-07-05 15:42:02 +0100137 /** Allow instances of this class to be moved */
138 CommonGraphOptions(CommonGraphOptions &&) = default;
139 /** Allow instances of this class to be moved */
140 CommonGraphOptions &operator=(CommonGraphOptions &&) = default;
141 /** Default destructor */
142 ~CommonGraphOptions() = default;
Georgios Pinitas12be7ab2018-07-03 12:06:23 +0100143
144 ToggleOption *help; /**< Show help option */
145 SimpleOption<int> *threads; /**< Number of threads option */
146 EnumOption<arm_compute::graph::Target> *target; /**< Graph execution target */
147 EnumOption<arm_compute::DataType> *data_type; /**< Graph data type */
148 EnumOption<arm_compute::DataLayout> *data_layout; /**< Graph data layout */
149 ToggleOption *enable_tuner; /**< Enable tuner */
150 ToggleOption *fast_math_hint; /**< Fast math hint */
151 SimpleOption<std::string> *data_path; /**< Trainable parameters path */
152 SimpleOption<std::string> *image; /**< Image */
153 SimpleOption<std::string> *labels; /**< Labels */
154 SimpleOption<std::string> *validation_file; /**< Validation file */
155 SimpleOption<std::string> *validation_path; /**< Validation data path */
156 SimpleOption<std::string> *validation_range; /**< Validation range */
Anthony Barbier7b607dc2018-07-13 15:55:24 +0100157 SimpleOption<std::string> *tuner_file; /**< File to load/store the tuner's values from */
Georgios Pinitas12be7ab2018-07-03 12:06:23 +0100158};
159
160/** Consumes the common graph options and creates a structure containing any information
161 *
162 * @param[in] options Options to consume
163 *
Georgios Pinitas9f28b392018-07-18 20:01:53 +0100164 * @return Structure containing the common graph parameters
Georgios Pinitas12be7ab2018-07-03 12:06:23 +0100165 */
166CommonGraphParams consume_common_graph_parameters(CommonGraphOptions &options);
167} // namespace utils
168} // namespace arm_compute
169#endif /* ARM_COMPUTE_EXAMPLES_UTILS_COMMON_GRAPH_OPTIONS */