Compute Library
 21.02
graph_validate_utils.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2019-2020 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 
25 #ifndef GRAPH_VALIDATE_UTILS_H
26 #define GRAPH_VALIDATE_UTILS_H
27 
28 #include "arm_compute/graph.h"
29 
30 #include "ValidateExample.h"
32 
33 namespace arm_compute
34 {
35 namespace utils
36 {
37 /*Available Padding modes */
39 {
40  Valid,
41  Same,
42  Manual
43 };
44 
45 /** Stream Input operator for the ConvolutionPaddingMode type
46  *
47  * @param[in] stream Input stream.
48  * @param[out] Mode Convolution parameters to output
49  *
50  * @return input stream.
51  */
52 inline ::std::istream &operator>>(::std::istream &stream, ConvolutionPaddingMode &Mode)
53 {
54  static const std::map<std::string, ConvolutionPaddingMode> modes =
55  {
56  { "valid", ConvolutionPaddingMode::Valid },
57  { "same", ConvolutionPaddingMode::Same },
58  { "manual", ConvolutionPaddingMode::Manual }
59  };
60  std::string value;
61  stream >> value;
62 #ifndef ARM_COMPUTE_EXCEPTIONS_DISABLED
63  try
64  {
65 #endif /* ARM_COMPUTE_EXCEPTIONS_DISABLED */
66  Mode = modes.at(arm_compute::utility::tolower(value));
67 #ifndef ARM_COMPUTE_EXCEPTIONS_DISABLED
68  }
69  catch(const std::out_of_range &)
70  {
71  throw std::invalid_argument(value);
72  }
73 #endif /* ARM_COMPUTE_EXCEPTIONS_DISABLED */
74 
75  return stream;
76 }
77 
78 /** Formatted output of the ConvolutionPaddingMode type
79  *
80  * @param[out] os Output stream.
81  * @param[in] Mode ConvolutionPaddingMode to output
82  *
83  * @return Modified output stream.
84  */
85 inline ::std::ostream &operator<<(::std::ostream &os, ConvolutionPaddingMode Mode)
86 {
87  switch(Mode)
88  {
90  os << "Valid";
91  break;
93  os << "Same";
94  break;
96  os << "Manual";
97  break;
98  default:
99  throw std::invalid_argument("Unsupported padding mode format");
100  }
101 
102  return os;
103 }
104 
105 /** Structure holding all the input tensor graph parameters */
107 {
108  int width{ 1 };
109  int height{ 1 };
110  int fm{ 1 };
111  int batch{ 1 };
112  QuantizationInfo quant_info{ 1.0f, 0 };
113  std::string npy{};
114  uint64_t range_low{ 0 };
115  uint64_t range_high{ 16 };
116 };
117 
118 /** Structure holding all the verification graph parameters */
120 {
121  float absolute_tolerance{ -1.f };
122  float relative_tolerance{ -1.f };
123  float tolerance_number{ -1.f };
124 };
125 
126 /** Structure holding all the common graph parameters */
128 {
129  bool help{ false };
130  int threads{ 0 };
132 };
133 
134 /** Structure holding all the graph Example parameters */
136 {
137  FrameworkParams common_params{};
139  TensorParams weights{};
140  TensorParams bias{};
141  TensorParams output{};
142  VerificationParams verification{};
144 };
145 
146 /** Structure holding all the Convolution layer graph parameters */
148 {
149  int depth_multiplier{ 1 };
150  /** Padding graph parameters */
151  int padding_top{ 0 };
152  int padding_bottom{ 0 };
153  int padding_left{ 0 };
154  int padding_right{ 0 };
155  int padding_stride_x{ 0 };
156  int padding_stride_y{ 0 };
158  struct
159  {
160  struct
161  {
162  int X{ 0 };
163  int Y{ 0 };
164  } stride{};
166  } padding{};
167 };
168 
169 /** Structure holding all the fully_connected layer graph parameters */
171 {
173  int num_outputs{ 1 };
174 };
175 
176 /** Structure holding all the graph Example parameters */
178 {
179  FullyConnectedParams fully_connected{};
184 };
185 
186 /** Calculate stride information.
187  *
188  * Depending on the selected padding mode create the desired PadStrideInfo
189  *
190  * @param[in] params Convolution parameters supplied by the user.
191  *
192  * @return PadStrideInfo with the correct padding mode.
193  */
195 {
196  switch(params.convolution.padding_mode)
197  {
199  {
202  }
204  {
205  return PadStrideInfo();
206  }
208  {
211  params.convolution.padding_stride_y));
212  }
213  default:
214  ARM_COMPUTE_ERROR("NOT SUPPORTED!");
215  }
216 }
217 /** CommonGraphValidateOptions command line options used to configure the graph examples
218  *
219  * (Similar to common options)
220  * The options in this object get populated when "parse()" is called on the parser used to construct it.
221  * The expected workflow is:
222  *
223  * CommandLineParser parser;
224  * CommonOptions options( parser );
225  * parser.parse(argc, argv);
226  */
228 {
229 public:
231  : help(parser.add_option<ToggleOption>("help")),
232  threads(parser.add_option<SimpleOption<int>>("threads")),
233  target(),
234  data_type(),
235  absolute_tolerance(parser.add_option<SimpleOption<float>>("abs_tolerance", -1.0f)),
236  relative_tolerance(parser.add_option<SimpleOption<float>>("rel_tolerance", -1.0f)),
237  tolerance_number(parser.add_option<SimpleOption<float>>("tolerance_num", -1.0f))
238  {
239  const std::set<arm_compute::graph::Target> supported_targets
240  {
244  };
245 
246  const std::set<arm_compute::DataType> supported_data_types
247  {
251  };
252 
253  target = parser.add_option<EnumOption<arm_compute::graph::Target>>("target", supported_targets, arm_compute::graph::Target::NEON);
254  data_type = parser.add_option<EnumOption<DataType>>("type", supported_data_types, DataType::F32);
255 
256  target->set_help("Target to execute on");
257  data_type->set_help("Data type to use");
258  help->set_help("Show this help message");
259  absolute_tolerance->set_help("Absolute tolerance used for verification");
260  relative_tolerance->set_help("Absolute tolerance used for verification");
261  tolerance_number->set_help("Absolute tolerance used for verification");
262  }
263 
264  /** Prevent instances of this class from being copied (As this class contains pointers) */
266  /** Prevent instances of this class from being copied (As this class contains pointers) */
267  CommonGraphValidateOptions &operator=(const CommonGraphValidateOptions &) = delete;
268  /** Allow instances of this class to be moved */
269  CommonGraphValidateOptions(CommonGraphValidateOptions &&) noexcept(true) = default;
270  /** Allow instances of this class to be moved */
271  CommonGraphValidateOptions &operator=(CommonGraphValidateOptions &&) noexcept(true) = default;
272  /** Default destructor */
273  virtual ~CommonGraphValidateOptions() = default;
274 
276  {
277  common_params.common_params.help = help->is_set() ? help->value() : false;
278  common_params.common_params.threads = threads->value();
279  common_params.common_params.target = target->value();
280 
281  common_params.verification.absolute_tolerance = absolute_tolerance->value();
282  common_params.verification.relative_tolerance = relative_tolerance->value();
283  common_params.verification.tolerance_number = tolerance_number->value();
284  }
285 
286  /** Formatted output of the ExampleParams type
287  *
288  * @param[out] os Output stream.
289  * @param[in] common_params Example parameters to output
290  *
291  * @return None.
292  */
293  virtual void print_parameters(::std::ostream &os, const ExampleParams &common_params)
294  {
295  os << "Threads : " << common_params.common_params.threads << std::endl;
296  os << "Target : " << common_params.common_params.target << std::endl;
297  os << "Data type : " << common_params.data_type << std::endl;
298  }
299 
300  ToggleOption *help; /**< show help message */
301  SimpleOption<int> *threads; /**< Number of threads option */
302  EnumOption<arm_compute::graph::Target> *target; /**< Graph execution target */
304  SimpleOption<float> *absolute_tolerance; /**< Absolute tolerance used in verification */
305  SimpleOption<float> *relative_tolerance; /**< Relative tolerance used in verification */
306  SimpleOption<float> *tolerance_number; /**< Tolerance number used in verification */
307 };
308 
309 /** Consumes the consume_common_graph_parameters graph options and creates a structure containing any information
310  *
311  * @param[in] options Options to consume
312  * @param[out] common_params params structure to consume.
313  *
314  * @return consume_common_graph_parameters structure containing the common graph parameters
315  */
317 {
318  common_params.common_params.help = options.help->is_set() ? options.help->value() : false;
319  common_params.common_params.threads = options.threads->value();
320  common_params.common_params.target = options.target->value();
321 
322  common_params.verification.absolute_tolerance = options.absolute_tolerance->value();
323  common_params.verification.relative_tolerance = options.relative_tolerance->value();
324  common_params.verification.tolerance_number = options.tolerance_number->value();
325 }
326 
327 /** Generates appropriate accessor according to the specified graph parameters
328  *
329  * @param[in] tensor Tensor parameters
330  * @param[in] lower Lower random values bound
331  * @param[in] upper Upper random values bound
332  * @param[in] seed Random generator seed
333  *
334  * @return An appropriate tensor accessor
335  */
336 inline std::unique_ptr<graph::ITensorAccessor> get_accessor(const TensorParams &tensor, PixelValue lower, PixelValue upper, const std::random_device::result_type seed = 0)
337 {
338  if(!tensor.npy.empty())
339  {
340  return std::make_unique<arm_compute::graph_utils::NumPyBinLoader>(tensor.npy);
341  }
342  else
343  {
344  return std::make_unique<arm_compute::graph_utils::RandomAccessor>(lower, upper, seed);
345  }
346 }
347 
348 /** Graph example validation accessor class */
349 template <typename D>
351 {
352 public:
353  using TBias = typename std::conditional<std::is_same<typename std::decay<D>::type, uint8_t>::value, int32_t, D>::type;
354  /** Constructor
355  *
356  * @param[in] params Convolution parameters
357  */
358  explicit VerifyAccessor(ExampleParams &params)
359  : _params(std::move(params))
360  {
361  }
362  // Inherited methods overriden:
363  bool access_tensor(ITensor &tensor) override
364  {
365  if(_params.output.npy.empty())
366  {
370 
371  //Create Input tensors
372  create_tensors(src, weights, bias, tensor);
373 
374  //Fill the tensors with random values
375  fill_tensor(src, 0, static_cast<D>(_params.input.range_low), static_cast<D>(_params.input.range_high));
376  fill_tensor(weights, 1, static_cast<D>(_params.weights.range_low), static_cast<D>(_params.weights.range_high));
377  fill_tensor(bias, 2, static_cast<TBias>(_params.input.range_low), static_cast<TBias>(_params.input.range_high));
378 
379  arm_compute::test::SimpleTensor<D> output = reference(src, weights, bias, output_shape(tensor));
380 
381  validate(tensor, output);
382  }
383  else
384  {
385  //The user provided a reference file use an npy accessor to validate
386  arm_compute::graph_utils::NumPyAccessor(_params.output.npy, tensor.info()->tensor_shape(), tensor.info()->data_type()).access_tensor(tensor);
387  }
388  return false;
389  }
390 
391  /** Create reference tensors.
392  *
393  * Validate the given tensor against the reference result.
394  *
395  * @param[out] src The tensor with the source data.
396  * @param[out] weights The tensor with the weigths data.
397  * @param[out] bias The tensor with the bias data.
398  * @param[in] tensor Tensor result of the actual operation passed into the Accessor.
399  *
400  * @return None.
401  */
405  ITensor &tensor)
406  {
407  ARM_COMPUTE_UNUSED(tensor);
408  //Create Input tensors
409  src = arm_compute::test::SimpleTensor<D> { TensorShape(_params.input.width, _params.input.height, _params.input.fm, _params.input.batch), _params.data_type, 1, _params.input.quant_info };
410  weights = arm_compute::test::SimpleTensor<D> { TensorShape(_params.weights.width, _params.weights.height, _params.weights.fm), _params.data_type, 1, _params.weights.quant_info };
411  bias = arm_compute::test::SimpleTensor<TBias> { TensorShape(_params.input.height), _params.data_type, 1, _params.input.quant_info };
412  }
413 
414  /** Calculate reference output tensor shape.
415  *
416  * @param[in] tensor Tensor result of the actual operation passed into the Accessor.
417  *
418  * @return output tensor shape.
419  */
421  {
422  return arm_compute::graph_utils::permute_shape(tensor.info()->tensor_shape(), _params.data_layout, DataLayout::NCHW);
423  }
424 
425  /** Calculate reference tensor.
426  *
427  * Validate the given tensor against the reference result.
428  *
429  * @param[in] src The tensor with the source data.
430  * @param[in] weights The tensor with the weigths data.
431  * @param[in] bias The tensor with the bias data.
432  * @param[in] output_shape Shape of the output tensor.
433  *
434  * @return Tensor with the reference output.
435  */
440 
441  /** Fill QASYMM tensor with Random values.
442  *
443  * Validate the given tensor against the reference result.
444  *
445  * @param[out] tensor The tensor we want to file
446  * @param[in] seed seed for the randomization function
447  * @param[in] low lower bound for random values
448  * @param[in] high upper bound for random values
449  *
450  * @return None.
451  */
452  void fill_tensor(arm_compute::test::SimpleTensor<uint8_t> &tensor, std::random_device::result_type seed, uint8_t low, uint8_t high)
453  {
455 
457 
458  uint8_t qasymm8_low = quantize_qasymm8(low, qinfo);
459  uint8_t qasymm8_high = quantize_qasymm8(high, qinfo);
460 
461  std::mt19937 gen(seed);
462  std::uniform_int_distribution<uint8_t> distribution(qasymm8_low, qasymm8_high);
463 
464  for(int i = 0; i < tensor.num_elements(); ++i)
465  {
466  tensor[i] = quantize_qasymm8(distribution(gen), qinfo);
467  }
468  }
469  /** Fill S32 tensor with Random values.
470  *
471  * Validate the given tensor against the reference result.
472  *
473  * @param[out] tensor The tensor we want to file
474  * @param[in] seed seed for the randomization function
475  * @param[in] low lower bound for random values
476  * @param[in] high upper bound for random values
477  *
478  * @return None.
479  */
480  void fill_tensor(arm_compute::test::SimpleTensor<int32_t> &tensor, std::random_device::result_type seed, int32_t low, int32_t high)
481  {
482  std::mt19937 gen(seed);
483  std::uniform_int_distribution<int32_t> distribution(static_cast<int32_t>(low), static_cast<uint32_t>(high));
484 
485  for(int i = 0; i < tensor.num_elements(); ++i)
486  {
487  tensor[i] = distribution(gen);
488  }
489  }
490  /** Fill F32 tensor with Random values.
491  *
492  * Validate the given tensor against the reference result.
493  *
494  * @param[out] tensor The tensor we want to file
495  * @param[in] seed seed for the randomization function
496  * @param[in] low lower bound for random values
497  * @param[in] high upper bound for random values
498  *
499  * @return None.
500  */
501  void fill_tensor(arm_compute::test::SimpleTensor<float> &tensor, std::random_device::result_type seed, float low, float high)
502  {
504  std::mt19937 gen(seed);
505  std::uniform_real_distribution<float> distribution(low, high);
506 
507  for(int i = 0; i < tensor.num_elements(); ++i)
508  {
509  tensor[i] = distribution(gen);
510  }
511  }
512  /** Fill F16 tensor with Random values.
513  *
514  * Validate the given tensor against the reference result.
515  *
516  * @param[out] tensor The tensor we want to file
517  * @param[in] seed seed for the randomization function
518  * @param[in] low lower bound for random values
519  * @param[in] high upper bound for random values
520  *
521  * @return None.
522  */
523  void fill_tensor(arm_compute::test::SimpleTensor<half> &tensor, std::random_device::result_type seed, half low, half high)
524  {
526  std::mt19937 gen(seed);
527  std::uniform_real_distribution<float> distribution(static_cast<half>(low), static_cast<half>(high));
528 
529  for(int i = 0; i < tensor.num_elements(); ++i)
530  {
531  tensor[i] = static_cast<half>(distribution(gen));
532  }
533  }
534 
535  /** Select relative tolerance.
536  *
537  * Select relative tolerance if not supplied by user.
538  *
539  * @return Appropriate relative tolerance.
540  */
541  virtual float relative_tolerance() = 0;
542 
543  /** Select absolute tolerance.
544  *
545  * Select absolute tolerance if not supplied by user.
546  *
547  * @return Appropriate absolute tolerance.
548  */
549  virtual float absolute_tolerance() = 0;
550 
551  /** Select tolerance number.
552  *
553  * Select tolerance number if not supplied by user.
554  *
555  * @return Appropriate tolerance number.
556  */
557  virtual float tolerance_number() = 0;
558 
559  /** Validate the output versus the reference.
560  *
561  * @param[in] tensor Tensor result of the actual operation passed into the Accessor.
562  * @param[in] output Tensor result of the reference implementation.
563  *
564  * @return None.
565  */
567  {
568  float user_relative_tolerance = _params.verification.relative_tolerance;
569  float user_absolute_tolerance = _params.verification.absolute_tolerance;
570  float user_tolerance_num = _params.verification.tolerance_number;
571  /* If no user input was provided override with defaults. */
572  if(user_relative_tolerance == -1)
573  {
574  user_relative_tolerance = relative_tolerance();
575  }
576 
577  if(user_absolute_tolerance == -1)
578  {
579  user_absolute_tolerance = absolute_tolerance();
580  }
581 
582  if(user_tolerance_num == -1)
583  {
584  user_tolerance_num = tolerance_number();
585  }
586 
587  const arm_compute::test::validation::RelativeTolerance<float> rel_tolerance(user_relative_tolerance); /**< Relative tolerance */
588  const arm_compute::test::validation::AbsoluteTolerance<float> abs_tolerance(user_absolute_tolerance); /**< Absolute tolerance */
589  const float tolerance_num(user_tolerance_num); /**< Tolerance number */
590 
591  arm_compute::test::validation::validate(arm_compute::test::Accessor(tensor), output, rel_tolerance, tolerance_num, abs_tolerance);
592  }
593 
595 };
596 
597 /** Generates appropriate convolution verify accessor
598  *
599  * @param[in] params User supplied parameters for convolution.
600  *
601  * @return A convolution verify accessor for the requested datatype.
602  */
603 template <template <typename D> class VerifyAccessorT>
604 inline std::unique_ptr<graph::ITensorAccessor> get_verify_accessor(ExampleParams params)
605 {
606  switch(params.data_type)
607  {
608  case DataType::QASYMM8:
609  {
610  return std::make_unique<VerifyAccessorT<uint8_t>>(
611  params);
612  }
613  case DataType::F16:
614  {
615  return std::make_unique<VerifyAccessorT<half>>(
616  params);
617  }
618  case DataType::F32:
619  {
620  return std::make_unique<VerifyAccessorT<float>>(
621  params);
622  }
623  default:
624  ARM_COMPUTE_ERROR("NOT SUPPORTED!");
625  }
626 }
627 
628 template <typename LayerT, typename OptionsT, template <typename D> class VerifyAccessorT>
630 {
631 public:
633  : graph(0, name)
634  {
635  }
636 
637  virtual LayerT GraphFunctionLayer(ExampleParams &params) = 0;
638 
639  bool do_setup(int argc, char **argv) override
640  {
642 
643  OptionsT Options(parser);
644 
645  parser.parse(argc, argv);
646 
647  ExampleParams params;
648 
649  Options.consume_common_parameters(params);
650  Options.consume_parameters(params);
651 
652  if(params.common_params.help)
653  {
654  parser.print_help(argv[0]);
655  return false;
656  }
657 
658  Options.print_parameters(std::cout, params);
659  // Create input descriptor
661  DataLayout::NCHW, params.data_layout);
663 
664  const PixelValue lower = PixelValue(params.input.range_low, params.data_type, params.input.quant_info);
665  const PixelValue upper = PixelValue(params.input.range_high, params.data_type, params.input.quant_info);
666 
667  graph << params.common_params.target
668  << params.convolution_method
669  << params.depth_convolution_method
670  << arm_compute::graph::frontend::InputLayer(input_descriptor, get_accessor(params.input, lower, upper, 0))
671  << GraphFunctionLayer(params)
672  << arm_compute::graph::frontend::OutputLayer(get_verify_accessor<VerifyAccessorT>(params));
673 
675  config.num_threads = params.common_params.threads;
676 
677  graph.finalize(params.common_params.target, config);
678 
679  return true;
680  }
681 
682  void do_run() override
683  {
684  graph.run();
685  }
686 
687  void do_teardown() override
688  {
689  }
690 
692 };
693 
694 } // graph_validate_utils
695 } // arm_compute
696 #endif //GRAPH_VALIDATE_UTILS_H
int padding_top
Padding graph parameters.
bool access_tensor(ITensor &tensor) override
Interface to be implemented to access a given tensor.
PadStrideInfo calculate_convolution_padding(ExampleParams params)
Calculate stride information.
Neon capable target device.
Class describing the value of a pixel for any image format.
Definition: PixelValue.h:34
Graph configuration structure Device target types.
Definition: Types.h:80
Shape of a tensor.
Definition: TensorShape.h:39
Class reprensenting an absolute tolerance value.
Definition: Validation.h:50
arm_compute::graph::ConvolutionMethod convolution_method
uint8_t quantize_qasymm8(float value, const INFO_TYPE &qinfo, RoundingPolicy rounding_policy=RoundingPolicy::TO_NEAREST_UP)
Quantize a value given an unsigned 8-bit asymmetric quantization scheme.
#define ARM_COMPUTE_ERROR(msg)
Print the given message then throw an std::runtime_error.
Definition: Error.h:352
Structure holding all the common graph parameters.
void validate(ITensor &tensor, arm_compute::test::SimpleTensor< D > output)
Validate the output versus the reference.
virtual DataType data_type() const =0
Data type used for each element of the tensor.
Implementation of an option that can be either true or false.
Definition: ToggleOption.h:36
half_float::half half
16-bit floating point type
Definition: Types.h:46
1 channel, 1 F32 per channel
DataType data_type() const override
Data type of the tensor.
Definition: SimpleTensor.h:357
CommonGraphValidateOptions command line options used to configure the graph examples.
inline ::std::ostream & operator<<(::std::ostream &os, ConvolutionPaddingMode Mode)
Formatted output of the ConvolutionPaddingMode type.
Structure holding all the graph Example parameters.
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:466
const DataLayout data_layout
Definition: Im2Col.cpp:151
Fully connected layer info.
Definition: Types.h:1613
void consume_common_graph_parameters(CommonGraphValidateOptions &options, CommonParams &common_params)
Consumes the consume_common_graph_parameters graph options and creates a structure containing any inf...
Abstract ValidateExample class.
Includes all the Graph headers at once.
Quantization info when assuming per layer quantization.
Class to parse command line arguments.
decltype(strategy::transforms) typedef type
Interface for Neon tensor.
Definition: ITensor.h:36
void fill_tensor(arm_compute::test::SimpleTensor< uint8_t > &tensor, std::random_device::result_type seed, uint8_t low, uint8_t high)
Fill QASYMM tensor with Random values.
Structure holding all the input tensor graph parameters.
virtual void create_tensors(arm_compute::test::SimpleTensor< D > &src, arm_compute::test::SimpleTensor< D > &weights, arm_compute::test::SimpleTensor< TBias > &bias, ITensor &tensor)
Create reference tensors.
std::unique_ptr< graph::ITensorAccessor > get_accessor(const TensorParams &tensor, PixelValue lower, PixelValue upper, const std::random_device::result_type seed=0)
Generates appropriate accessor according to the specified graph parameters.
SimpleTensor< float > src
Definition: DFT.cpp:155
Copyright (c) 2017-2021 Arm Limited.
1 channel, 1 F16 per channel
virtual TensorShape output_shape(ITensor &tensor)
Calculate reference output tensor shape.
const DataType data_type
Definition: Im2Col.cpp:150
GLES compute capable target device.
std::string tolower(std::string string)
Convert string to lower case.
Definition: Utility.h:203
Quantization information.
TensorShape input_shape
Validate test suite is to test ARM_COMPUTE_RETURN_ON_* macros we use to check the validity of given a...
Accessor implementation for Tensor objects.
Definition: Accessor.h:35
Structure holding all the verification graph parameters.
void parse(int argc, char **argv)
Parses the command line arguments and updates the options accordingly.
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
Definition: Error.h:152
Structure holding all the fully_connected layer graph parameters.
fill_tensor(input_to_input_weights, std::vector< uint8_t >{ 122, 130, 124, 134, 120, 122, 134, 134 })
void fill_tensor(arm_compute::test::SimpleTensor< float > &tensor, std::random_device::result_type seed, float low, float high)
Fill F32 tensor with Random values.
virtual const TensorShape & tensor_shape() const =0
Size for each dimension of the tensor.
CommonGraphValidateOptions(CommandLineParser &parser) noexcept
quantized, asymmetric fixed-point 8-bit number unsigned
DepthwiseConvolutionMethod
Supported Depthwise Convolution layer methods.
Definition: Types.h:127
UniformQuantizationInfo uniform() const
Return per layer quantization info.
Structure holding all the graph Example parameters.
virtual ITensorInfo * info() const =0
Interface to be implemented by the child class to return the tensor&#39;s metadata.
void fill_tensor(arm_compute::test::SimpleTensor< half > &tensor, std::random_device::result_type seed, half low, half high)
Fill F16 tensor with Random values.
virtual void print_parameters(::std::ostream &os, const ExampleParams &common_params)
Formatted output of the ExampleParams type.
Padding and stride information class.
Definition: Types.h:722
validate(CLAccessor(output_state), expected_output)
void consume_common_parameters(CommonParams &common_params)
std::uniform_real_distribution< float > distribution(-5.f, 5.f)
const T & value() const
Get the option value.
Definition: SimpleOption.h:112
std::unique_ptr< graph::ITensorAccessor > get_verify_accessor(ExampleParams params)
Generates appropriate convolution verify accessor.
Num samples, channels, height, width.
const char * name
Tensor accessor interface.
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:664
SimpleTensor< T > convolution(const SimpleTensor< uint8_t > &src, DataType output_data_type, const int16_t *conv, uint32_t scale, BorderMode border_mode, uint8_t constant_border_value, const unsigned int width, const unsigned int height)
Definition: Convolution.cpp:38
Simple tensor object that stores elements in a consecutive chunk of memory.
Definition: SimpleTensor.h:58
void fill_tensor(arm_compute::test::SimpleTensor< int32_t > &tensor, std::random_device::result_type seed, int32_t low, int32_t high)
Fill S32 tensor with Random values.
arm_compute::graph::DepthwiseConvolutionMethod depth_convolution_method
SimpleOption< float > * absolute_tolerance
Absolute tolerance used in verification.
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)
bool do_setup(int argc, char **argv) override
Setup the example.
void do_teardown() override
Teardown the example.
VerifyAccessor(ExampleParams &params)
Constructor.
Graph example validation accessor class.
Class reprensenting a relative tolerance value.
Definition: Validation.h:86
const QuantizationInfo qinfo
Definition: Im2Col.cpp:155
EnumOption< arm_compute::graph::Target > * target
Graph execution target.
int num_elements() const override
Number of elements of the tensor.
Definition: SimpleTensor.h:406
ConvolutionMethod
Supported Convolution layer methods.
Definition: Types.h:118
int num_threads
Number of threads to use (thread capable backends), if 0 the backend will auto-initialize, if -1 the backend will stay as it is.
Definition: Types.h:88
SimpleOption< int > * threads
Number of threads option.
Default approach using internal heuristics.
Stream frontend class to construct simple graphs in a stream fashion.
Definition: Stream.h:45
void do_run() override
Run the example.
Default approach using internal heuristics.
bool is_set() const
Has a value been assigned to the option?
Definition: Option.h:135
void print_help(const std::string &program_name) const
Prints a help message for all configured options.
inline ::std::istream & operator>>(::std::istream &stream, ConvolutionPaddingMode &Mode)
Stream Input operator for the ConvolutionPaddingMode type.
QuantizationInfo quantization_info() const override
Quantization info in case of asymmetric quantized type.
Definition: SimpleTensor.h:332
EnumOption< arm_compute::DataType > * data_type
Graph data type.
const T & value() const
Get the selected value.
SimpleOption< float > * tolerance_number
Tolerance number used in verification.
DataType
Available data types.
Definition: Types.h:77
arm_compute::graph::frontend::Stream graph
OpenCL capable target device.
DataLayout
[DataLayout enum definition]
Definition: Types.h:120
Structure holding all the Convolution layer graph parameters.
typename std::conditional< std::is_same< typename std::decay< D >::type, uint8_t >::value, int32_t, D >::type TBias
void set_help(std::string help)
Set the help message for the option.
Definition: Option.h:125
Status validate(const ITensorInfo *scores_in, const ITensorInfo *boxes_in, const ITensorInfo *batch_splits_in, const ITensorInfo *scores_out, const ITensorInfo *boxes_out, const ITensorInfo *classes, const ITensorInfo *batch_splits_out, const ITensorInfo *keeps, const ITensorInfo *keeps_size, const BoxNMSLimitInfo info)
PadStrideInfo calculate_same_pad(TensorShape input_shape, TensorShape weights_shape, PadStrideInfo conv_info, DataLayout data_layout=DataLayout::NCHW, const Size2D &dilation=Size2D(1u, 1u), const DimensionRoundingType &rounding_type=DimensionRoundingType::FLOOR)
Calculate padding requirements in case of SAME padding.
Definition: Utils.cpp:357
SimpleOption< float > * relative_tolerance
Relative tolerance used in verification.