Anthony Barbier | 2a07e18 | 2017-08-04 18:20:27 +0100 | [diff] [blame] | 1 | /* |
Isabella Gottardi | 0ae5de9 | 2019-03-14 10:32:11 +0000 | [diff] [blame] | 2 | * Copyright (c) 2017-2019 ARM Limited. |
Anthony Barbier | 2a07e18 | 2017-08-04 18:20:27 +0100 | [diff] [blame] | 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 | */ |
Georgios Pinitas | f52cd78 | 2019-03-25 14:06:14 +0000 | [diff] [blame] | 24 | #ifndef __ARM_COMPUTE_UTILS_GRAPH_UTILS_H__ |
| 25 | #define __ARM_COMPUTE_UTILS_GRAPH_UTILS_H__ |
Anthony Barbier | 2a07e18 | 2017-08-04 18:20:27 +0100 | [diff] [blame] | 26 | |
Michalis Spyrou | 53b405f | 2017-09-27 15:55:31 +0100 | [diff] [blame] | 27 | #include "arm_compute/core/PixelValue.h" |
Gian Marco Iodice | ad486e2 | 2018-08-07 17:17:06 +0100 | [diff] [blame] | 28 | #include "arm_compute/core/Utils.h" |
Isabella Gottardi | 88d5b22 | 2018-04-06 12:24:55 +0100 | [diff] [blame] | 29 | #include "arm_compute/core/utils/misc/Utility.h" |
Gian Marco | bfa3b52 | 2017-12-12 10:08:38 +0000 | [diff] [blame] | 30 | #include "arm_compute/graph/Graph.h" |
Anthony Barbier | 2a07e18 | 2017-08-04 18:20:27 +0100 | [diff] [blame] | 31 | #include "arm_compute/graph/ITensorAccessor.h" |
| 32 | #include "arm_compute/graph/Types.h" |
Isabella Gottardi | 88d5b22 | 2018-04-06 12:24:55 +0100 | [diff] [blame] | 33 | #include "arm_compute/runtime/Tensor.h" |
Anthony Barbier | 2a07e18 | 2017-08-04 18:20:27 +0100 | [diff] [blame] | 34 | |
Georgios Pinitas | 12be7ab | 2018-07-03 12:06:23 +0100 | [diff] [blame] | 35 | #include "utils/CommonGraphOptions.h" |
| 36 | |
Georgios Pinitas | 140fdc7 | 2018-02-16 11:42:38 +0000 | [diff] [blame] | 37 | #include <array> |
Michalis Spyrou | 53b405f | 2017-09-27 15:55:31 +0100 | [diff] [blame] | 38 | #include <random> |
Gian Marco | 44ec2e7 | 2017-10-19 14:13:38 +0100 | [diff] [blame] | 39 | #include <string> |
| 40 | #include <vector> |
Michalis Spyrou | 53b405f | 2017-09-27 15:55:31 +0100 | [diff] [blame] | 41 | |
Anthony Barbier | 2a07e18 | 2017-08-04 18:20:27 +0100 | [diff] [blame] | 42 | namespace arm_compute |
| 43 | { |
| 44 | namespace graph_utils |
| 45 | { |
Georgios Pinitas | 140fdc7 | 2018-02-16 11:42:38 +0000 | [diff] [blame] | 46 | /** Preprocessor interface **/ |
| 47 | class IPreprocessor |
| 48 | { |
| 49 | public: |
Alex Gilday | c357c47 | 2018-03-21 13:54:09 +0000 | [diff] [blame] | 50 | /** Default destructor. */ |
| 51 | virtual ~IPreprocessor() = default; |
| 52 | /** Preprocess the given tensor. |
| 53 | * |
| 54 | * @param[in] tensor Tensor to preprocess. |
| 55 | */ |
Georgios Pinitas | 140fdc7 | 2018-02-16 11:42:38 +0000 | [diff] [blame] | 56 | virtual void preprocess(ITensor &tensor) = 0; |
| 57 | }; |
| 58 | |
| 59 | /** Caffe preproccessor */ |
| 60 | class CaffePreproccessor : public IPreprocessor |
| 61 | { |
| 62 | public: |
| 63 | /** Default Constructor |
| 64 | * |
Georgios Pinitas | b54c644 | 2019-04-03 13:18:14 +0100 | [diff] [blame] | 65 | * @param[in] mean Mean array in RGB ordering |
| 66 | * @param[in] bgr Boolean specifying if the preprocessing should assume BGR format |
| 67 | * @param[in] scale Scale value |
Georgios Pinitas | 140fdc7 | 2018-02-16 11:42:38 +0000 | [diff] [blame] | 68 | */ |
Georgios Pinitas | b54c644 | 2019-04-03 13:18:14 +0100 | [diff] [blame] | 69 | CaffePreproccessor(std::array<float, 3> mean = std::array<float, 3> { { 0, 0, 0 } }, bool bgr = true, float scale = 1.f); |
Georgios Pinitas | 140fdc7 | 2018-02-16 11:42:38 +0000 | [diff] [blame] | 70 | void preprocess(ITensor &tensor) override; |
| 71 | |
| 72 | private: |
giuros01 | 351bd13 | 2019-08-23 14:27:30 +0100 | [diff] [blame] | 73 | template <typename T> |
| 74 | void preprocess_typed(ITensor &tensor); |
| 75 | |
Georgios Pinitas | 140fdc7 | 2018-02-16 11:42:38 +0000 | [diff] [blame] | 76 | std::array<float, 3> _mean; |
Pablo Tello | 3252143 | 2018-11-15 14:43:10 +0000 | [diff] [blame] | 77 | bool _bgr; |
Georgios Pinitas | b54c644 | 2019-04-03 13:18:14 +0100 | [diff] [blame] | 78 | float _scale; |
Georgios Pinitas | 140fdc7 | 2018-02-16 11:42:38 +0000 | [diff] [blame] | 79 | }; |
| 80 | |
| 81 | /** TF preproccessor */ |
| 82 | class TFPreproccessor : public IPreprocessor |
| 83 | { |
| 84 | public: |
Georgios Pinitas | be2772a | 2018-08-17 15:33:39 +0100 | [diff] [blame] | 85 | /** Constructor |
| 86 | * |
| 87 | * @param[in] min_range Min normalization range. (Defaults to -1.f) |
| 88 | * @param[in] max_range Max normalization range. (Defaults to 1.f) |
| 89 | */ |
| 90 | TFPreproccessor(float min_range = -1.f, float max_range = 1.f); |
| 91 | |
| 92 | // Inherited overriden methods |
Georgios Pinitas | 140fdc7 | 2018-02-16 11:42:38 +0000 | [diff] [blame] | 93 | void preprocess(ITensor &tensor) override; |
Georgios Pinitas | be2772a | 2018-08-17 15:33:39 +0100 | [diff] [blame] | 94 | |
| 95 | private: |
giuros01 | 351bd13 | 2019-08-23 14:27:30 +0100 | [diff] [blame] | 96 | template <typename T> |
| 97 | void preprocess_typed(ITensor &tensor); |
| 98 | |
Georgios Pinitas | be2772a | 2018-08-17 15:33:39 +0100 | [diff] [blame] | 99 | float _min_range; |
| 100 | float _max_range; |
Georgios Pinitas | 140fdc7 | 2018-02-16 11:42:38 +0000 | [diff] [blame] | 101 | }; |
| 102 | |
Anthony Barbier | 2a07e18 | 2017-08-04 18:20:27 +0100 | [diff] [blame] | 103 | /** PPM writer class */ |
| 104 | class PPMWriter : public graph::ITensorAccessor |
| 105 | { |
| 106 | public: |
| 107 | /** Constructor |
| 108 | * |
| 109 | * @param[in] name PPM file name |
| 110 | * @param[in] maximum Maximum elements to access |
| 111 | */ |
| 112 | PPMWriter(std::string name, unsigned int maximum = 1); |
| 113 | /** Allows instances to move constructed */ |
| 114 | PPMWriter(PPMWriter &&) = default; |
| 115 | |
| 116 | // Inherited methods overriden: |
| 117 | bool access_tensor(ITensor &tensor) override; |
| 118 | |
| 119 | private: |
| 120 | const std::string _name; |
| 121 | unsigned int _iterator; |
| 122 | unsigned int _maximum; |
| 123 | }; |
| 124 | |
| 125 | /** Dummy accessor class */ |
Michalis Spyrou | 53b405f | 2017-09-27 15:55:31 +0100 | [diff] [blame] | 126 | class DummyAccessor final : public graph::ITensorAccessor |
Anthony Barbier | 2a07e18 | 2017-08-04 18:20:27 +0100 | [diff] [blame] | 127 | { |
| 128 | public: |
| 129 | /** Constructor |
| 130 | * |
| 131 | * @param[in] maximum Maximum elements to write |
| 132 | */ |
| 133 | DummyAccessor(unsigned int maximum = 1); |
| 134 | /** Allows instances to move constructed */ |
| 135 | DummyAccessor(DummyAccessor &&) = default; |
| 136 | |
| 137 | // Inherited methods overriden: |
| 138 | bool access_tensor(ITensor &tensor) override; |
| 139 | |
| 140 | private: |
| 141 | unsigned int _iterator; |
| 142 | unsigned int _maximum; |
| 143 | }; |
| 144 | |
Isabella Gottardi | 88d5b22 | 2018-04-06 12:24:55 +0100 | [diff] [blame] | 145 | /** NumPy accessor class */ |
| 146 | class NumPyAccessor final : public graph::ITensorAccessor |
| 147 | { |
| 148 | public: |
| 149 | /** Constructor |
| 150 | * |
| 151 | * @param[in] npy_path Path to npy file. |
| 152 | * @param[in] shape Shape of the numpy tensor data. |
| 153 | * @param[in] data_type DataType of the numpy tensor data. |
Isabella Gottardi | a7acb3c | 2019-01-08 13:48:44 +0000 | [diff] [blame] | 154 | * @param[in] data_layout (Optional) DataLayout of the numpy tensor data. |
Isabella Gottardi | 88d5b22 | 2018-04-06 12:24:55 +0100 | [diff] [blame] | 155 | * @param[out] output_stream (Optional) Output stream |
| 156 | */ |
Isabella Gottardi | a7acb3c | 2019-01-08 13:48:44 +0000 | [diff] [blame] | 157 | NumPyAccessor(std::string npy_path, TensorShape shape, DataType data_type, DataLayout data_layout = DataLayout::NCHW, std::ostream &output_stream = std::cout); |
Isabella Gottardi | 88d5b22 | 2018-04-06 12:24:55 +0100 | [diff] [blame] | 158 | /** Allow instances of this class to be move constructed */ |
| 159 | NumPyAccessor(NumPyAccessor &&) = default; |
| 160 | /** Prevent instances of this class from being copied (As this class contains pointers) */ |
| 161 | NumPyAccessor(const NumPyAccessor &) = delete; |
| 162 | /** Prevent instances of this class from being copied (As this class contains pointers) */ |
| 163 | NumPyAccessor &operator=(const NumPyAccessor &) = delete; |
| 164 | |
| 165 | // Inherited methods overriden: |
| 166 | bool access_tensor(ITensor &tensor) override; |
| 167 | |
| 168 | private: |
| 169 | template <typename T> |
Isabella Gottardi | 0ae5de9 | 2019-03-14 10:32:11 +0000 | [diff] [blame] | 170 | void access_numpy_tensor(ITensor &tensor, T tolerance); |
Isabella Gottardi | 88d5b22 | 2018-04-06 12:24:55 +0100 | [diff] [blame] | 171 | |
| 172 | Tensor _npy_tensor; |
| 173 | const std::string _filename; |
| 174 | std::ostream &_output_stream; |
| 175 | }; |
| 176 | |
Isabella Gottardi | 2ea3761 | 2019-07-16 11:48:51 +0100 | [diff] [blame] | 177 | /** SaveNumPy accessor class */ |
| 178 | class SaveNumPyAccessor final : public graph::ITensorAccessor |
| 179 | { |
| 180 | public: |
| 181 | /** Constructor |
| 182 | * |
| 183 | * @param[in] npy_name Npy file name. |
| 184 | * @param[in] is_fortran (Optional) If true, save tensor in fortran order. |
| 185 | */ |
| 186 | SaveNumPyAccessor(const std::string npy_name, const bool is_fortran = false); |
| 187 | /** Allow instances of this class to be move constructed */ |
| 188 | SaveNumPyAccessor(SaveNumPyAccessor &&) = default; |
| 189 | /** Prevent instances of this class from being copied (As this class contains pointers) */ |
| 190 | SaveNumPyAccessor(const SaveNumPyAccessor &) = delete; |
| 191 | /** Prevent instances of this class from being copied (As this class contains pointers) */ |
| 192 | SaveNumPyAccessor &operator=(const SaveNumPyAccessor &) = delete; |
| 193 | |
| 194 | // Inherited methods overriden: |
| 195 | bool access_tensor(ITensor &tensor) override; |
| 196 | |
| 197 | private: |
| 198 | const std::string _npy_name; |
| 199 | const bool _is_fortran; |
| 200 | }; |
| 201 | |
Isabella Gottardi | cd4e9ab | 2019-11-05 17:50:27 +0000 | [diff] [blame] | 202 | /** Print accessor class |
| 203 | * @note The print accessor will print only when asserts are enabled. |
| 204 | * */ |
| 205 | class PrintAccessor final : public graph::ITensorAccessor |
| 206 | { |
| 207 | public: |
| 208 | /** Constructor |
| 209 | * |
| 210 | * @param[out] output_stream (Optional) Output stream |
| 211 | * @param[in] io_fmt (Optional) Format information |
| 212 | */ |
| 213 | PrintAccessor(std::ostream &output_stream = std::cout, IOFormatInfo io_fmt = IOFormatInfo()); |
| 214 | /** Allow instances of this class to be move constructed */ |
| 215 | PrintAccessor(PrintAccessor &&) = default; |
| 216 | /** Prevent instances of this class from being copied (As this class contains pointers) */ |
| 217 | PrintAccessor(const PrintAccessor &) = delete; |
| 218 | /** Prevent instances of this class from being copied (As this class contains pointers) */ |
| 219 | PrintAccessor &operator=(const PrintAccessor &) = delete; |
| 220 | |
| 221 | // Inherited methods overriden: |
| 222 | bool access_tensor(ITensor &tensor) override; |
| 223 | |
| 224 | private: |
| 225 | std::ostream &_output_stream; |
| 226 | IOFormatInfo _io_fmt; |
| 227 | }; |
| 228 | |
Georgios Pinitas | 12be7ab | 2018-07-03 12:06:23 +0100 | [diff] [blame] | 229 | /** Image accessor class */ |
| 230 | class ImageAccessor final : public graph::ITensorAccessor |
Gian Marco | 44ec2e7 | 2017-10-19 14:13:38 +0100 | [diff] [blame] | 231 | { |
| 232 | public: |
| 233 | /** Constructor |
| 234 | * |
Georgios Pinitas | 12be7ab | 2018-07-03 12:06:23 +0100 | [diff] [blame] | 235 | * @param[in] filename Image file |
Georgios Pinitas | 7c3b924 | 2018-06-21 19:01:25 +0100 | [diff] [blame] | 236 | * @param[in] bgr (Optional) Fill the first plane with blue channel (default = false - RGB format) |
Georgios Pinitas | 12be7ab | 2018-07-03 12:06:23 +0100 | [diff] [blame] | 237 | * @param[in] preprocessor (Optional) Image pre-processing object |
Gian Marco | 44ec2e7 | 2017-10-19 14:13:38 +0100 | [diff] [blame] | 238 | */ |
Georgios Pinitas | 12be7ab | 2018-07-03 12:06:23 +0100 | [diff] [blame] | 239 | ImageAccessor(std::string filename, bool bgr = true, std::unique_ptr<IPreprocessor> preprocessor = nullptr); |
Gian Marco | 44ec2e7 | 2017-10-19 14:13:38 +0100 | [diff] [blame] | 240 | /** Allow instances of this class to be move constructed */ |
Georgios Pinitas | 12be7ab | 2018-07-03 12:06:23 +0100 | [diff] [blame] | 241 | ImageAccessor(ImageAccessor &&) = default; |
Gian Marco | 44ec2e7 | 2017-10-19 14:13:38 +0100 | [diff] [blame] | 242 | |
| 243 | // Inherited methods overriden: |
| 244 | bool access_tensor(ITensor &tensor) override; |
| 245 | |
| 246 | private: |
Anthony Barbier | 8a04211 | 2018-08-21 18:16:53 +0100 | [diff] [blame] | 247 | bool _already_loaded; |
Georgios Pinitas | 12be7ab | 2018-07-03 12:06:23 +0100 | [diff] [blame] | 248 | const std::string _filename; |
Georgios Pinitas | 140fdc7 | 2018-02-16 11:42:38 +0000 | [diff] [blame] | 249 | const bool _bgr; |
| 250 | std::unique_ptr<IPreprocessor> _preprocessor; |
Gian Marco | 44ec2e7 | 2017-10-19 14:13:38 +0100 | [diff] [blame] | 251 | }; |
| 252 | |
Georgios Pinitas | 7c3b924 | 2018-06-21 19:01:25 +0100 | [diff] [blame] | 253 | /** Input Accessor used for network validation */ |
| 254 | class ValidationInputAccessor final : public graph::ITensorAccessor |
| 255 | { |
| 256 | public: |
| 257 | /** Constructor |
| 258 | * |
Anthony Barbier | 40606df | 2018-07-23 14:41:59 +0100 | [diff] [blame] | 259 | * @param[in] image_list File containing all the images to validate |
| 260 | * @param[in] images_path Path to images. |
| 261 | * @param[in] bgr (Optional) Fill the first plane with blue channel (default = false - RGB format) |
| 262 | * @param[in] preprocessor (Optional) Image pre-processing object (default = nullptr) |
| 263 | * @param[in] start (Optional) Start range |
| 264 | * @param[in] end (Optional) End range |
| 265 | * @param[out] output_stream (Optional) Output stream |
Georgios Pinitas | 7c3b924 | 2018-06-21 19:01:25 +0100 | [diff] [blame] | 266 | * |
Georgios Pinitas | 7908de7 | 2018-06-27 12:34:20 +0100 | [diff] [blame] | 267 | * @note Range is defined as [start, end] |
Georgios Pinitas | 7c3b924 | 2018-06-21 19:01:25 +0100 | [diff] [blame] | 268 | */ |
Georgios Pinitas | 12be7ab | 2018-07-03 12:06:23 +0100 | [diff] [blame] | 269 | ValidationInputAccessor(const std::string &image_list, |
| 270 | std::string images_path, |
Anthony Barbier | 40606df | 2018-07-23 14:41:59 +0100 | [diff] [blame] | 271 | std::unique_ptr<IPreprocessor> preprocessor = nullptr, |
| 272 | bool bgr = true, |
| 273 | unsigned int start = 0, |
| 274 | unsigned int end = 0, |
| 275 | std::ostream &output_stream = std::cout); |
Georgios Pinitas | 7c3b924 | 2018-06-21 19:01:25 +0100 | [diff] [blame] | 276 | |
| 277 | // Inherited methods overriden: |
| 278 | bool access_tensor(ITensor &tensor) override; |
| 279 | |
| 280 | private: |
Georgios Pinitas | 12be7ab | 2018-07-03 12:06:23 +0100 | [diff] [blame] | 281 | std::string _path; |
| 282 | std::vector<std::string> _images; |
| 283 | std::unique_ptr<IPreprocessor> _preprocessor; |
| 284 | bool _bgr; |
| 285 | size_t _offset; |
Anthony Barbier | 40606df | 2018-07-23 14:41:59 +0100 | [diff] [blame] | 286 | std::ostream &_output_stream; |
Georgios Pinitas | 7c3b924 | 2018-06-21 19:01:25 +0100 | [diff] [blame] | 287 | }; |
| 288 | |
Georgios Pinitas | 7908de7 | 2018-06-27 12:34:20 +0100 | [diff] [blame] | 289 | /** Output Accessor used for network validation */ |
| 290 | class ValidationOutputAccessor final : public graph::ITensorAccessor |
| 291 | { |
| 292 | public: |
| 293 | /** Default Constructor |
| 294 | * |
| 295 | * @param[in] image_list File containing all the images and labels results |
Georgios Pinitas | 7908de7 | 2018-06-27 12:34:20 +0100 | [diff] [blame] | 296 | * @param[out] output_stream (Optional) Output stream (Defaults to the standard output stream) |
| 297 | * @param[in] start (Optional) Start range |
| 298 | * @param[in] end (Optional) End range |
| 299 | * |
| 300 | * @note Range is defined as [start, end] |
| 301 | */ |
| 302 | ValidationOutputAccessor(const std::string &image_list, |
Georgios Pinitas | 7908de7 | 2018-06-27 12:34:20 +0100 | [diff] [blame] | 303 | std::ostream &output_stream = std::cout, |
| 304 | unsigned int start = 0, |
| 305 | unsigned int end = 0); |
| 306 | /** Reset accessor state */ |
| 307 | void reset(); |
| 308 | |
| 309 | // Inherited methods overriden: |
| 310 | bool access_tensor(ITensor &tensor) override; |
| 311 | |
| 312 | private: |
| 313 | /** Access predictions of the tensor |
| 314 | * |
| 315 | * @tparam T Tensor elements type |
| 316 | * |
| 317 | * @param[in] tensor Tensor to read the predictions from |
| 318 | */ |
| 319 | template <typename T> |
| 320 | std::vector<size_t> access_predictions_tensor(ITensor &tensor); |
Georgios Pinitas | 12be7ab | 2018-07-03 12:06:23 +0100 | [diff] [blame] | 321 | /** Aggregates the results of a sample |
| 322 | * |
| 323 | * @param[in] res Vector containing the results of a graph |
| 324 | * @param[in,out] positive_samples Positive samples to be updated |
| 325 | * @param[in] top_n Top n accuracy to measure |
| 326 | * @param[in] correct_label Correct label of the current sample |
| 327 | */ |
| 328 | void aggregate_sample(const std::vector<size_t> &res, size_t &positive_samples, size_t top_n, size_t correct_label); |
| 329 | /** Reports top N accuracy |
| 330 | * |
| 331 | * @param[in] top_n Top N accuracy that is being reported |
| 332 | * @param[in] total_samples Total number of samples |
| 333 | * @param[in] positive_samples Positive samples |
| 334 | */ |
| 335 | void report_top_n(size_t top_n, size_t total_samples, size_t positive_samples); |
Georgios Pinitas | 7908de7 | 2018-06-27 12:34:20 +0100 | [diff] [blame] | 336 | |
| 337 | private: |
| 338 | std::vector<int> _results; |
| 339 | std::ostream &_output_stream; |
Georgios Pinitas | 7908de7 | 2018-06-27 12:34:20 +0100 | [diff] [blame] | 340 | size_t _offset; |
Georgios Pinitas | 12be7ab | 2018-07-03 12:06:23 +0100 | [diff] [blame] | 341 | size_t _positive_samples_top1; |
| 342 | size_t _positive_samples_top5; |
Georgios Pinitas | 7908de7 | 2018-06-27 12:34:20 +0100 | [diff] [blame] | 343 | }; |
| 344 | |
Isabella Gottardi | 7234ed8 | 2018-11-27 08:51:10 +0000 | [diff] [blame] | 345 | /** Detection output accessor class */ |
| 346 | class DetectionOutputAccessor final : public graph::ITensorAccessor |
| 347 | { |
| 348 | public: |
| 349 | /** Constructor |
| 350 | * |
| 351 | * @param[in] labels_path Path to labels text file. |
| 352 | * @param[in] imgs_tensor_shapes Network input images tensor shapes. |
| 353 | * @param[out] output_stream (Optional) Output stream |
| 354 | */ |
| 355 | DetectionOutputAccessor(const std::string &labels_path, std::vector<TensorShape> &imgs_tensor_shapes, std::ostream &output_stream = std::cout); |
| 356 | /** Allow instances of this class to be move constructed */ |
| 357 | DetectionOutputAccessor(DetectionOutputAccessor &&) = default; |
| 358 | /** Prevent instances of this class from being copied (As this class contains pointers) */ |
| 359 | DetectionOutputAccessor(const DetectionOutputAccessor &) = delete; |
| 360 | /** Prevent instances of this class from being copied (As this class contains pointers) */ |
| 361 | DetectionOutputAccessor &operator=(const DetectionOutputAccessor &) = delete; |
| 362 | |
| 363 | // Inherited methods overriden: |
| 364 | bool access_tensor(ITensor &tensor) override; |
| 365 | |
| 366 | private: |
| 367 | template <typename T> |
| 368 | void access_predictions_tensor(ITensor &tensor); |
| 369 | |
| 370 | std::vector<std::string> _labels; |
| 371 | std::vector<TensorShape> _tensor_shapes; |
| 372 | std::ostream &_output_stream; |
| 373 | }; |
| 374 | |
Gian Marco | 44ec2e7 | 2017-10-19 14:13:38 +0100 | [diff] [blame] | 375 | /** Result accessor class */ |
| 376 | class TopNPredictionsAccessor final : public graph::ITensorAccessor |
| 377 | { |
| 378 | public: |
| 379 | /** Constructor |
| 380 | * |
| 381 | * @param[in] labels_path Path to labels text file. |
| 382 | * @param[in] top_n (Optional) Number of output classes to print |
| 383 | * @param[out] output_stream (Optional) Output stream |
| 384 | */ |
| 385 | TopNPredictionsAccessor(const std::string &labels_path, size_t top_n = 5, std::ostream &output_stream = std::cout); |
| 386 | /** Allow instances of this class to be move constructed */ |
| 387 | TopNPredictionsAccessor(TopNPredictionsAccessor &&) = default; |
| 388 | /** Prevent instances of this class from being copied (As this class contains pointers) */ |
| 389 | TopNPredictionsAccessor(const TopNPredictionsAccessor &) = delete; |
| 390 | /** Prevent instances of this class from being copied (As this class contains pointers) */ |
| 391 | TopNPredictionsAccessor &operator=(const TopNPredictionsAccessor &) = delete; |
| 392 | |
| 393 | // Inherited methods overriden: |
| 394 | bool access_tensor(ITensor &tensor) override; |
| 395 | |
| 396 | private: |
Giorgio Arena | a66eaa2 | 2017-12-21 19:50:06 +0000 | [diff] [blame] | 397 | template <typename T> |
| 398 | void access_predictions_tensor(ITensor &tensor); |
| 399 | |
Gian Marco | 44ec2e7 | 2017-10-19 14:13:38 +0100 | [diff] [blame] | 400 | std::vector<std::string> _labels; |
| 401 | std::ostream &_output_stream; |
| 402 | size_t _top_n; |
| 403 | }; |
| 404 | |
Michalis Spyrou | 53b405f | 2017-09-27 15:55:31 +0100 | [diff] [blame] | 405 | /** Random accessor class */ |
| 406 | class RandomAccessor final : public graph::ITensorAccessor |
| 407 | { |
| 408 | public: |
| 409 | /** Constructor |
| 410 | * |
| 411 | * @param[in] lower Lower bound value. |
| 412 | * @param[in] upper Upper bound value. |
| 413 | * @param[in] seed (Optional) Seed used to initialise the random number generator. |
| 414 | */ |
| 415 | RandomAccessor(PixelValue lower, PixelValue upper, const std::random_device::result_type seed = 0); |
| 416 | /** Allows instances to move constructed */ |
| 417 | RandomAccessor(RandomAccessor &&) = default; |
| 418 | |
| 419 | // Inherited methods overriden: |
| 420 | bool access_tensor(ITensor &tensor) override; |
| 421 | |
| 422 | private: |
| 423 | template <typename T, typename D> |
| 424 | void fill(ITensor &tensor, D &&distribution); |
| 425 | PixelValue _lower; |
| 426 | PixelValue _upper; |
| 427 | std::random_device::result_type _seed; |
| 428 | }; |
| 429 | |
Anthony Barbier | 2a07e18 | 2017-08-04 18:20:27 +0100 | [diff] [blame] | 430 | /** Numpy Binary loader class*/ |
Michalis Spyrou | 53b405f | 2017-09-27 15:55:31 +0100 | [diff] [blame] | 431 | class NumPyBinLoader final : public graph::ITensorAccessor |
Anthony Barbier | 2a07e18 | 2017-08-04 18:20:27 +0100 | [diff] [blame] | 432 | { |
| 433 | public: |
| 434 | /** Default Constructor |
| 435 | * |
Georgios Pinitas | cac13b1 | 2018-04-27 19:07:19 +0100 | [diff] [blame] | 436 | * @param[in] filename Binary file name |
| 437 | * @param[in] file_layout (Optional) Layout of the numpy tensor data. Defaults to NCHW |
Anthony Barbier | 2a07e18 | 2017-08-04 18:20:27 +0100 | [diff] [blame] | 438 | */ |
Georgios Pinitas | cac13b1 | 2018-04-27 19:07:19 +0100 | [diff] [blame] | 439 | NumPyBinLoader(std::string filename, DataLayout file_layout = DataLayout::NCHW); |
Anthony Barbier | 2a07e18 | 2017-08-04 18:20:27 +0100 | [diff] [blame] | 440 | /** Allows instances to move constructed */ |
| 441 | NumPyBinLoader(NumPyBinLoader &&) = default; |
| 442 | |
| 443 | // Inherited methods overriden: |
| 444 | bool access_tensor(ITensor &tensor) override; |
| 445 | |
| 446 | private: |
Anthony Barbier | 8a04211 | 2018-08-21 18:16:53 +0100 | [diff] [blame] | 447 | bool _already_loaded; |
Anthony Barbier | 2a07e18 | 2017-08-04 18:20:27 +0100 | [diff] [blame] | 448 | const std::string _filename; |
Georgios Pinitas | cac13b1 | 2018-04-27 19:07:19 +0100 | [diff] [blame] | 449 | const DataLayout _file_layout; |
Anthony Barbier | 2a07e18 | 2017-08-04 18:20:27 +0100 | [diff] [blame] | 450 | }; |
Isabella Gottardi | a4c6188 | 2017-11-03 12:11:55 +0000 | [diff] [blame] | 451 | |
Georgios Pinitas | 652bde5 | 2018-01-10 15:33:28 +0000 | [diff] [blame] | 452 | /** Generates appropriate random accessor |
| 453 | * |
| 454 | * @param[in] lower Lower random values bound |
| 455 | * @param[in] upper Upper random values bound |
| 456 | * @param[in] seed Random generator seed |
| 457 | * |
| 458 | * @return A ramdom accessor |
| 459 | */ |
| 460 | inline std::unique_ptr<graph::ITensorAccessor> get_random_accessor(PixelValue lower, PixelValue upper, const std::random_device::result_type seed = 0) |
| 461 | { |
| 462 | return arm_compute::support::cpp14::make_unique<RandomAccessor>(lower, upper, seed); |
| 463 | } |
| 464 | |
Isabella Gottardi | a4c6188 | 2017-11-03 12:11:55 +0000 | [diff] [blame] | 465 | /** Generates appropriate weights accessor according to the specified path |
| 466 | * |
| 467 | * @note If path is empty will generate a DummyAccessor else will generate a NumPyBinLoader |
| 468 | * |
Georgios Pinitas | cac13b1 | 2018-04-27 19:07:19 +0100 | [diff] [blame] | 469 | * @param[in] path Path to the data files |
| 470 | * @param[in] data_file Relative path to the data files from path |
| 471 | * @param[in] file_layout (Optional) Layout of file. Defaults to NCHW |
Isabella Gottardi | a4c6188 | 2017-11-03 12:11:55 +0000 | [diff] [blame] | 472 | * |
| 473 | * @return An appropriate tensor accessor |
| 474 | */ |
Georgios Pinitas | cac13b1 | 2018-04-27 19:07:19 +0100 | [diff] [blame] | 475 | inline std::unique_ptr<graph::ITensorAccessor> get_weights_accessor(const std::string &path, |
| 476 | const std::string &data_file, |
| 477 | DataLayout file_layout = DataLayout::NCHW) |
Isabella Gottardi | a4c6188 | 2017-11-03 12:11:55 +0000 | [diff] [blame] | 478 | { |
| 479 | if(path.empty()) |
| 480 | { |
| 481 | return arm_compute::support::cpp14::make_unique<DummyAccessor>(); |
| 482 | } |
| 483 | else |
| 484 | { |
Georgios Pinitas | cac13b1 | 2018-04-27 19:07:19 +0100 | [diff] [blame] | 485 | return arm_compute::support::cpp14::make_unique<NumPyBinLoader>(path + data_file, file_layout); |
Isabella Gottardi | a4c6188 | 2017-11-03 12:11:55 +0000 | [diff] [blame] | 486 | } |
| 487 | } |
| 488 | |
Georgios Pinitas | 12be7ab | 2018-07-03 12:06:23 +0100 | [diff] [blame] | 489 | /** Generates appropriate input accessor according to the specified graph parameters |
Isabella Gottardi | a4c6188 | 2017-11-03 12:11:55 +0000 | [diff] [blame] | 490 | * |
Georgios Pinitas | 12be7ab | 2018-07-03 12:06:23 +0100 | [diff] [blame] | 491 | * @param[in] graph_parameters Graph parameters |
| 492 | * @param[in] preprocessor (Optional) Preproccessor object |
| 493 | * @param[in] bgr (Optional) Fill the first plane with blue channel (default = true) |
Isabella Gottardi | a4c6188 | 2017-11-03 12:11:55 +0000 | [diff] [blame] | 494 | * |
| 495 | * @return An appropriate tensor accessor |
| 496 | */ |
Georgios Pinitas | 12be7ab | 2018-07-03 12:06:23 +0100 | [diff] [blame] | 497 | inline std::unique_ptr<graph::ITensorAccessor> get_input_accessor(const arm_compute::utils::CommonGraphParams &graph_parameters, |
| 498 | std::unique_ptr<IPreprocessor> preprocessor = nullptr, |
| 499 | bool bgr = true) |
Isabella Gottardi | a4c6188 | 2017-11-03 12:11:55 +0000 | [diff] [blame] | 500 | { |
Georgios Pinitas | 12be7ab | 2018-07-03 12:06:23 +0100 | [diff] [blame] | 501 | if(!graph_parameters.validation_file.empty()) |
Isabella Gottardi | a4c6188 | 2017-11-03 12:11:55 +0000 | [diff] [blame] | 502 | { |
Georgios Pinitas | 12be7ab | 2018-07-03 12:06:23 +0100 | [diff] [blame] | 503 | return arm_compute::support::cpp14::make_unique<ValidationInputAccessor>(graph_parameters.validation_file, |
| 504 | graph_parameters.validation_path, |
| 505 | std::move(preprocessor), |
| 506 | bgr, |
| 507 | graph_parameters.validation_range_start, |
| 508 | graph_parameters.validation_range_end); |
Isabella Gottardi | a4c6188 | 2017-11-03 12:11:55 +0000 | [diff] [blame] | 509 | } |
| 510 | else |
| 511 | { |
Gian Marco Iodice | ad486e2 | 2018-08-07 17:17:06 +0100 | [diff] [blame] | 512 | const std::string &image_file = graph_parameters.image; |
| 513 | const std::string &image_file_lower = lower_string(image_file); |
| 514 | if(arm_compute::utility::endswith(image_file_lower, ".npy")) |
Isabella Gottardi | 88d5b22 | 2018-04-06 12:24:55 +0100 | [diff] [blame] | 515 | { |
Manuel Bottini | 3252795 | 2019-11-05 16:55:57 +0000 | [diff] [blame] | 516 | return arm_compute::support::cpp14::make_unique<NumPyBinLoader>(image_file, graph_parameters.data_layout); |
Georgios Pinitas | 12be7ab | 2018-07-03 12:06:23 +0100 | [diff] [blame] | 517 | } |
Gian Marco Iodice | ad486e2 | 2018-08-07 17:17:06 +0100 | [diff] [blame] | 518 | else if(arm_compute::utility::endswith(image_file_lower, ".jpeg") |
| 519 | || arm_compute::utility::endswith(image_file_lower, ".jpg") |
| 520 | || arm_compute::utility::endswith(image_file_lower, ".ppm")) |
Georgios Pinitas | 12be7ab | 2018-07-03 12:06:23 +0100 | [diff] [blame] | 521 | { |
| 522 | return arm_compute::support::cpp14::make_unique<ImageAccessor>(image_file, bgr, std::move(preprocessor)); |
Isabella Gottardi | 88d5b22 | 2018-04-06 12:24:55 +0100 | [diff] [blame] | 523 | } |
| 524 | else |
| 525 | { |
Georgios Pinitas | 12be7ab | 2018-07-03 12:06:23 +0100 | [diff] [blame] | 526 | return arm_compute::support::cpp14::make_unique<DummyAccessor>(); |
Isabella Gottardi | 88d5b22 | 2018-04-06 12:24:55 +0100 | [diff] [blame] | 527 | } |
Isabella Gottardi | a4c6188 | 2017-11-03 12:11:55 +0000 | [diff] [blame] | 528 | } |
| 529 | } |
| 530 | |
Georgios Pinitas | 12be7ab | 2018-07-03 12:06:23 +0100 | [diff] [blame] | 531 | /** Generates appropriate output accessor according to the specified graph parameters |
Isabella Gottardi | a4c6188 | 2017-11-03 12:11:55 +0000 | [diff] [blame] | 532 | * |
Georgios Pinitas | 12be7ab | 2018-07-03 12:06:23 +0100 | [diff] [blame] | 533 | * @note If the output accessor is requested to validate the graph then ValidationOutputAccessor is generated |
| 534 | * else if output_accessor_file is empty will generate a DummyAccessor else will generate a TopNPredictionsAccessor |
Isabella Gottardi | a4c6188 | 2017-11-03 12:11:55 +0000 | [diff] [blame] | 535 | * |
Georgios Pinitas | 12be7ab | 2018-07-03 12:06:23 +0100 | [diff] [blame] | 536 | * @param[in] graph_parameters Graph parameters |
| 537 | * @param[in] top_n (Optional) Number of output classes to print (default = 5) |
| 538 | * @param[in] is_validation (Optional) Validation flag (default = false) |
| 539 | * @param[out] output_stream (Optional) Output stream (default = std::cout) |
Isabella Gottardi | a4c6188 | 2017-11-03 12:11:55 +0000 | [diff] [blame] | 540 | * |
| 541 | * @return An appropriate tensor accessor |
| 542 | */ |
Georgios Pinitas | 12be7ab | 2018-07-03 12:06:23 +0100 | [diff] [blame] | 543 | inline std::unique_ptr<graph::ITensorAccessor> get_output_accessor(const arm_compute::utils::CommonGraphParams &graph_parameters, |
| 544 | size_t top_n = 5, |
| 545 | bool is_validation = false, |
| 546 | std::ostream &output_stream = std::cout) |
Isabella Gottardi | a4c6188 | 2017-11-03 12:11:55 +0000 | [diff] [blame] | 547 | { |
Michalis Spyrou | 6bff195 | 2019-10-02 17:22:11 +0100 | [diff] [blame] | 548 | ARM_COMPUTE_UNUSED(is_validation); |
Georgios Pinitas | 12be7ab | 2018-07-03 12:06:23 +0100 | [diff] [blame] | 549 | if(!graph_parameters.validation_file.empty()) |
| 550 | { |
| 551 | return arm_compute::support::cpp14::make_unique<ValidationOutputAccessor>(graph_parameters.validation_file, |
| 552 | output_stream, |
| 553 | graph_parameters.validation_range_start, |
| 554 | graph_parameters.validation_range_end); |
| 555 | } |
| 556 | else if(graph_parameters.labels.empty()) |
Isabella Gottardi | a4c6188 | 2017-11-03 12:11:55 +0000 | [diff] [blame] | 557 | { |
Anthony Barbier | e1a905a | 2017-12-22 13:53:46 +0000 | [diff] [blame] | 558 | return arm_compute::support::cpp14::make_unique<DummyAccessor>(0); |
Isabella Gottardi | a4c6188 | 2017-11-03 12:11:55 +0000 | [diff] [blame] | 559 | } |
| 560 | else |
| 561 | { |
Georgios Pinitas | 12be7ab | 2018-07-03 12:06:23 +0100 | [diff] [blame] | 562 | return arm_compute::support::cpp14::make_unique<TopNPredictionsAccessor>(graph_parameters.labels, top_n, output_stream); |
Isabella Gottardi | a4c6188 | 2017-11-03 12:11:55 +0000 | [diff] [blame] | 563 | } |
| 564 | } |
Isabella Gottardi | 7234ed8 | 2018-11-27 08:51:10 +0000 | [diff] [blame] | 565 | /** Generates appropriate output accessor according to the specified graph parameters |
| 566 | * |
| 567 | * @note If the output accessor is requested to validate the graph then ValidationOutputAccessor is generated |
| 568 | * else if output_accessor_file is empty will generate a DummyAccessor else will generate a TopNPredictionsAccessor |
| 569 | * |
| 570 | * @param[in] graph_parameters Graph parameters |
| 571 | * @param[in] tensor_shapes Network input images tensor shapes. |
| 572 | * @param[in] is_validation (Optional) Validation flag (default = false) |
| 573 | * @param[out] output_stream (Optional) Output stream (default = std::cout) |
| 574 | * |
| 575 | * @return An appropriate tensor accessor |
| 576 | */ |
| 577 | inline std::unique_ptr<graph::ITensorAccessor> get_detection_output_accessor(const arm_compute::utils::CommonGraphParams &graph_parameters, |
| 578 | std::vector<TensorShape> tensor_shapes, |
| 579 | bool is_validation = false, |
| 580 | std::ostream &output_stream = std::cout) |
| 581 | { |
Michalis Spyrou | 6bff195 | 2019-10-02 17:22:11 +0100 | [diff] [blame] | 582 | ARM_COMPUTE_UNUSED(is_validation); |
Isabella Gottardi | 7234ed8 | 2018-11-27 08:51:10 +0000 | [diff] [blame] | 583 | if(!graph_parameters.validation_file.empty()) |
| 584 | { |
| 585 | return arm_compute::support::cpp14::make_unique<ValidationOutputAccessor>(graph_parameters.validation_file, |
| 586 | output_stream, |
| 587 | graph_parameters.validation_range_start, |
| 588 | graph_parameters.validation_range_end); |
| 589 | } |
| 590 | else if(graph_parameters.labels.empty()) |
| 591 | { |
| 592 | return arm_compute::support::cpp14::make_unique<DummyAccessor>(0); |
| 593 | } |
| 594 | else |
| 595 | { |
| 596 | return arm_compute::support::cpp14::make_unique<DetectionOutputAccessor>(graph_parameters.labels, tensor_shapes, output_stream); |
| 597 | } |
| 598 | } |
Isabella Gottardi | 88d5b22 | 2018-04-06 12:24:55 +0100 | [diff] [blame] | 599 | /** Generates appropriate npy output accessor according to the specified npy_path |
| 600 | * |
| 601 | * @note If npy_path is empty will generate a DummyAccessor else will generate a NpyAccessor |
| 602 | * |
| 603 | * @param[in] npy_path Path to npy file. |
| 604 | * @param[in] shape Shape of the numpy tensor data. |
| 605 | * @param[in] data_type DataType of the numpy tensor data. |
Isabella Gottardi | a7acb3c | 2019-01-08 13:48:44 +0000 | [diff] [blame] | 606 | * @param[in] data_layout DataLayout of the numpy tensor data. |
Isabella Gottardi | 88d5b22 | 2018-04-06 12:24:55 +0100 | [diff] [blame] | 607 | * @param[out] output_stream (Optional) Output stream |
| 608 | * |
| 609 | * @return An appropriate tensor accessor |
| 610 | */ |
Isabella Gottardi | a7acb3c | 2019-01-08 13:48:44 +0000 | [diff] [blame] | 611 | inline std::unique_ptr<graph::ITensorAccessor> get_npy_output_accessor(const std::string &npy_path, TensorShape shape, DataType data_type, DataLayout data_layout = DataLayout::NCHW, |
| 612 | std::ostream &output_stream = std::cout) |
Isabella Gottardi | 88d5b22 | 2018-04-06 12:24:55 +0100 | [diff] [blame] | 613 | { |
| 614 | if(npy_path.empty()) |
| 615 | { |
| 616 | return arm_compute::support::cpp14::make_unique<DummyAccessor>(0); |
| 617 | } |
| 618 | else |
| 619 | { |
Isabella Gottardi | a7acb3c | 2019-01-08 13:48:44 +0000 | [diff] [blame] | 620 | return arm_compute::support::cpp14::make_unique<NumPyAccessor>(npy_path, shape, data_type, data_layout, output_stream); |
Isabella Gottardi | 88d5b22 | 2018-04-06 12:24:55 +0100 | [diff] [blame] | 621 | } |
| 622 | } |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 623 | |
Isabella Gottardi | 2ea3761 | 2019-07-16 11:48:51 +0100 | [diff] [blame] | 624 | /** Generates appropriate npy output accessor according to the specified npy_path |
| 625 | * |
| 626 | * @note If npy_path is empty will generate a DummyAccessor else will generate a SaveNpyAccessor |
| 627 | * |
| 628 | * @param[in] npy_name Npy filename. |
| 629 | * @param[in] is_fortran (Optional) If true, save tensor in fortran order. |
| 630 | * |
| 631 | * @return An appropriate tensor accessor |
| 632 | */ |
| 633 | inline std::unique_ptr<graph::ITensorAccessor> get_save_npy_output_accessor(const std::string &npy_name, const bool is_fortran = false) |
| 634 | { |
| 635 | if(npy_name.empty()) |
| 636 | { |
| 637 | return arm_compute::support::cpp14::make_unique<DummyAccessor>(0); |
| 638 | } |
| 639 | else |
| 640 | { |
| 641 | return arm_compute::support::cpp14::make_unique<SaveNumPyAccessor>(npy_name, is_fortran); |
| 642 | } |
| 643 | } |
| 644 | |
Isabella Gottardi | cd4e9ab | 2019-11-05 17:50:27 +0000 | [diff] [blame] | 645 | /** Generates print tensor accessor |
| 646 | * |
| 647 | * @param[out] output_stream (Optional) Output stream |
| 648 | * |
| 649 | * @return A print tensor accessor |
| 650 | */ |
| 651 | inline std::unique_ptr<graph::ITensorAccessor> get_print_output_accessor(std::ostream &output_stream = std::cout) |
| 652 | { |
| 653 | return arm_compute::support::cpp14::make_unique<PrintAccessor>(output_stream); |
| 654 | } |
| 655 | |
Georgios Pinitas | 7d66a8e | 2018-07-17 12:28:42 +0100 | [diff] [blame] | 656 | /** Permutes a given tensor shape given the input and output data layout |
| 657 | * |
| 658 | * @param[in] tensor_shape Tensor shape to permute |
| 659 | * @param[in] in_data_layout Input tensor shape data layout |
| 660 | * @param[in] out_data_layout Output tensor shape data layout |
| 661 | * |
| 662 | * @return Permuted tensor shape |
| 663 | */ |
| 664 | inline TensorShape permute_shape(TensorShape tensor_shape, DataLayout in_data_layout, DataLayout out_data_layout) |
| 665 | { |
| 666 | if(in_data_layout != out_data_layout) |
| 667 | { |
| 668 | arm_compute::PermutationVector perm_vec = (in_data_layout == DataLayout::NCHW) ? arm_compute::PermutationVector(2U, 0U, 1U) : arm_compute::PermutationVector(1U, 2U, 0U); |
| 669 | arm_compute::permute(tensor_shape, perm_vec); |
| 670 | } |
| 671 | return tensor_shape; |
| 672 | } |
| 673 | |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 674 | /** Utility function to return the TargetHint |
| 675 | * |
| 676 | * @param[in] target Integer value which expresses the selected target. Must be 0 for NEON or 1 for OpenCL or 2 (OpenCL with Tuner) |
| 677 | * |
| 678 | * @return the TargetHint |
| 679 | */ |
Georgios Pinitas | d9eb275 | 2018-04-03 13:44:29 +0100 | [diff] [blame] | 680 | inline graph::Target set_target_hint(int target) |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 681 | { |
Georgios Pinitas | fbb8054 | 2018-03-27 17:15:49 +0100 | [diff] [blame] | 682 | ARM_COMPUTE_ERROR_ON_MSG(target > 3, "Invalid target. Target must be 0 (NEON), 1 (OpenCL), 2 (OpenCL + Tuner), 3 (GLES)"); |
Georgios Pinitas | d9eb275 | 2018-04-03 13:44:29 +0100 | [diff] [blame] | 683 | if((target == 1 || target == 2)) |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 684 | { |
Georgios Pinitas | d9eb275 | 2018-04-03 13:44:29 +0100 | [diff] [blame] | 685 | return graph::Target::CL; |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 686 | } |
Georgios Pinitas | fbb8054 | 2018-03-27 17:15:49 +0100 | [diff] [blame] | 687 | else if(target == 3) |
| 688 | { |
Georgios Pinitas | d9eb275 | 2018-04-03 13:44:29 +0100 | [diff] [blame] | 689 | return graph::Target::GC; |
Georgios Pinitas | fbb8054 | 2018-03-27 17:15:49 +0100 | [diff] [blame] | 690 | } |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 691 | else |
| 692 | { |
Georgios Pinitas | d9eb275 | 2018-04-03 13:44:29 +0100 | [diff] [blame] | 693 | return graph::Target::NEON; |
Georgios Pinitas | d8734b5 | 2017-12-22 15:27:52 +0000 | [diff] [blame] | 694 | } |
| 695 | } |
Michalis Spyrou | e472082 | 2017-10-02 17:44:52 +0100 | [diff] [blame] | 696 | } // namespace graph_utils |
Anthony Barbier | 2a07e18 | 2017-08-04 18:20:27 +0100 | [diff] [blame] | 697 | } // namespace arm_compute |
| 698 | |
Georgios Pinitas | f52cd78 | 2019-03-25 14:06:14 +0000 | [diff] [blame] | 699 | #endif /* __ARM_COMPUTE_UTILS_GRAPH_UTILS_H__ */ |