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