Compute Library
 22.08
VerifyAccessor< D > Class Template Referenceabstract

Graph example validation accessor class. More...

#include <graph_validate_utils.h>

Collaboration diagram for VerifyAccessor< D >:
[legend]

Public Types

using TBias = typename std::conditional< std::is_same< typename std::decay< D >::type, uint8_t >::value, int32_t, D >::type
 

Public Member Functions

 VerifyAccessor (ExampleParams &params)
 Constructor. More...
 
bool access_tensor (ITensor &tensor) override
 Interface to be implemented to access a given tensor. More...
 
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. More...
 
virtual TensorShape output_shape (ITensor &tensor)
 Calculate reference output tensor shape. More...
 
virtual arm_compute::test::SimpleTensor< D > reference (arm_compute::test::SimpleTensor< D > &src, arm_compute::test::SimpleTensor< D > &weights, arm_compute::test::SimpleTensor< TBias > &bias, const arm_compute::TensorShape &output_shape)=0
 Calculate reference tensor. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
virtual float relative_tolerance ()=0
 Select relative tolerance. More...
 
virtual float absolute_tolerance ()=0
 Select absolute tolerance. More...
 
virtual float tolerance_number ()=0
 Select tolerance number. More...
 
void validate (ITensor &tensor, arm_compute::test::SimpleTensor< D > output)
 Validate the output versus the reference. More...
 
- Public Member Functions inherited from ITensorAccessor
virtual ~ITensorAccessor ()=default
 Default virtual destructor. More...
 
virtual bool access_tensor_data ()
 Returns true if the tensor data is being accessed. More...
 

Data Fields

ExampleParams _params
 

Detailed Description

template<typename D>
class arm_compute::utils::VerifyAccessor< D >

Graph example validation accessor class.

Definition at line 349 of file graph_validate_utils.h.

Member Typedef Documentation

◆ TBias

using TBias = typename std::conditional<std::is_same<typename std::decay<D>::type, uint8_t>::value, int32_t, D>::type

Definition at line 352 of file graph_validate_utils.h.

Constructor & Destructor Documentation

◆ VerifyAccessor()

VerifyAccessor ( ExampleParams params)
inlineexplicit

Constructor.

Parameters
[in]paramsConvolution parameters

Definition at line 357 of file graph_validate_utils.h.

358  : _params(std::move(params))
359  {
360  }

Member Function Documentation

◆ absolute_tolerance()

virtual float absolute_tolerance ( )
pure virtual

Select absolute tolerance.

Select absolute tolerance if not supplied by user.

Returns
Appropriate absolute tolerance.

◆ access_tensor()

bool access_tensor ( ITensor tensor)
inlineoverridevirtual

Interface to be implemented to access a given tensor.

Parameters
[in]tensorTensor to be accessed
Returns
True if access is successful else false

Implements ITensorAccessor.

Definition at line 362 of file graph_validate_utils.h.

References bias, ITensorInfo::data_type(), arm_compute::test::validation::fill_tensor(), ITensor::info(), arm_compute::test::validation::output_shape, arm_compute::test::validation::src, ITensorInfo::tensor_shape(), and arm_compute::validate().

363  {
364  if(_params.output.npy.empty())
365  {
369 
370  //Create Input tensors
371  create_tensors(src, weights, bias, tensor);
372 
373  //Fill the tensors with random values
374  fill_tensor(src, 0, static_cast<D>(_params.input.range_low), static_cast<D>(_params.input.range_high));
375  fill_tensor(weights, 1, static_cast<D>(_params.weights.range_low), static_cast<D>(_params.weights.range_high));
376  fill_tensor(bias, 2, static_cast<TBias>(_params.input.range_low), static_cast<TBias>(_params.input.range_high));
377 
378  arm_compute::test::SimpleTensor<D> output = reference(src, weights, bias, output_shape(tensor));
379 
380  validate(tensor, output);
381  }
382  else
383  {
384  //The user provided a reference file use an npy accessor to validate
385  arm_compute::graph_utils::NumPyAccessor(_params.output.npy, tensor.info()->tensor_shape(), tensor.info()->data_type()).access_tensor(tensor);
386  }
387  return false;
388  }
bool access_tensor(ITensor &tensor) override
Interface to be implemented to access a given tensor.
void validate(ITensor &tensor, arm_compute::test::SimpleTensor< D > output)
Validate the output versus the reference.
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.
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.
SimpleTensor< float > src
Definition: DFT.cpp:155
virtual TensorShape output_shape(ITensor &tensor)
Calculate reference output tensor shape.
Simple tensor object that stores elements in a consecutive chunk of memory.
Definition: SimpleTensor.h:58
virtual arm_compute::test::SimpleTensor< D > reference(arm_compute::test::SimpleTensor< D > &src, arm_compute::test::SimpleTensor< D > &weights, arm_compute::test::SimpleTensor< TBias > &bias, const arm_compute::TensorShape &output_shape)=0
Calculate reference tensor.
const int32_t * bias

◆ create_tensors()

virtual void create_tensors ( arm_compute::test::SimpleTensor< D > &  src,
arm_compute::test::SimpleTensor< D > &  weights,
arm_compute::test::SimpleTensor< TBias > &  bias,
ITensor tensor 
)
inlinevirtual

Create reference tensors.

Validate the given tensor against the reference result.

Parameters
[out]srcThe tensor with the source data.
[out]weightsThe tensor with the weigths data.
[out]biasThe tensor with the bias data.
[in]tensorTensor result of the actual operation passed into the Accessor.
Returns
None.

Definition at line 401 of file graph_validate_utils.h.

References ARM_COMPUTE_UNUSED.

405  {
406  ARM_COMPUTE_UNUSED(tensor);
407  //Create Input tensors
411  }
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
Definition: Error.h:152
Simple tensor object that stores elements in a consecutive chunk of memory.
Definition: SimpleTensor.h:58

◆ fill_tensor() [1/4]

void fill_tensor ( arm_compute::test::SimpleTensor< uint8_t > &  tensor,
std::random_device::result_type  seed,
uint8_t  low,
uint8_t  high 
)
inline

Fill QASYMM tensor with Random values.

Validate the given tensor against the reference result.

Parameters
[out]tensorThe tensor we want to file
[in]seedseed for the randomization function
[in]lowlower bound for random values
[in]highupper bound for random values
Returns
None.

Definition at line 451 of file graph_validate_utils.h.

References ARM_COMPUTE_ERROR_ON, SimpleTensor< T >::data_type(), arm_compute::test::validation::distribution(), SimpleTensor< T >::num_elements(), arm_compute::QASYMM8, arm_compute::test::validation::qinfo, SimpleTensor< T >::quantization_info(), arm_compute::quantize_qasymm8(), and QuantizationInfo::uniform().

452  {
454 
455  const UniformQuantizationInfo qinfo = tensor.quantization_info().uniform();
456 
457  uint8_t qasymm8_low = quantize_qasymm8(low, qinfo);
458  uint8_t qasymm8_high = quantize_qasymm8(high, qinfo);
459 
460  std::mt19937 gen(seed);
461  std::uniform_int_distribution<uint8_t> distribution(qasymm8_low, qasymm8_high);
462 
463  for(int i = 0; i < tensor.num_elements(); ++i)
464  {
465  tensor[i] = quantize_qasymm8(distribution(gen), qinfo);
466  }
467  }
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.
DataType data_type() const override
Data type of the tensor.
Definition: SimpleTensor.h:357
#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
quantized, asymmetric fixed-point 8-bit number unsigned
UniformQuantizationInfo uniform() const
Return per layer quantization info.
std::uniform_real_distribution< float > distribution(-5.f, 5.f)
const QuantizationInfo qinfo
Definition: Im2Col.cpp:155
int num_elements() const override
Number of elements of the tensor.
Definition: SimpleTensor.h:406
QuantizationInfo quantization_info() const override
Quantization info in case of asymmetric quantized type.
Definition: SimpleTensor.h:332

◆ fill_tensor() [2/4]

void fill_tensor ( arm_compute::test::SimpleTensor< int32_t > &  tensor,
std::random_device::result_type  seed,
int32_t  low,
int32_t  high 
)
inline

Fill S32 tensor with Random values.

Validate the given tensor against the reference result.

Parameters
[out]tensorThe tensor we want to file
[in]seedseed for the randomization function
[in]lowlower bound for random values
[in]highupper bound for random values
Returns
None.

Definition at line 479 of file graph_validate_utils.h.

References arm_compute::test::validation::distribution(), and SimpleTensor< T >::num_elements().

480  {
481  std::mt19937 gen(seed);
482  std::uniform_int_distribution<int32_t> distribution(static_cast<int32_t>(low), static_cast<uint32_t>(high));
483 
484  for(int i = 0; i < tensor.num_elements(); ++i)
485  {
486  tensor[i] = distribution(gen);
487  }
488  }
std::uniform_real_distribution< float > distribution(-5.f, 5.f)
int num_elements() const override
Number of elements of the tensor.
Definition: SimpleTensor.h:406

◆ fill_tensor() [3/4]

void fill_tensor ( arm_compute::test::SimpleTensor< float > &  tensor,
std::random_device::result_type  seed,
float  low,
float  high 
)
inline

Fill F32 tensor with Random values.

Validate the given tensor against the reference result.

Parameters
[out]tensorThe tensor we want to file
[in]seedseed for the randomization function
[in]lowlower bound for random values
[in]highupper bound for random values
Returns
None.

Definition at line 500 of file graph_validate_utils.h.

References ARM_COMPUTE_ERROR_ON, SimpleTensor< T >::data_type(), arm_compute::test::validation::distribution(), arm_compute::F32, and SimpleTensor< T >::num_elements().

501  {
503  std::mt19937 gen(seed);
504  std::uniform_real_distribution<float> distribution(low, high);
505 
506  for(int i = 0; i < tensor.num_elements(); ++i)
507  {
508  tensor[i] = distribution(gen);
509  }
510  }
1 channel, 1 F32 per channel
DataType data_type() const override
Data type of the tensor.
Definition: SimpleTensor.h:357
#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
std::uniform_real_distribution< float > distribution(-5.f, 5.f)
int num_elements() const override
Number of elements of the tensor.
Definition: SimpleTensor.h:406

◆ fill_tensor() [4/4]

void fill_tensor ( arm_compute::test::SimpleTensor< half > &  tensor,
std::random_device::result_type  seed,
half  low,
half  high 
)
inline

Fill F16 tensor with Random values.

Validate the given tensor against the reference result.

Parameters
[out]tensorThe tensor we want to file
[in]seedseed for the randomization function
[in]lowlower bound for random values
[in]highupper bound for random values
Returns
None.

Definition at line 522 of file graph_validate_utils.h.

References ARM_COMPUTE_ERROR_ON, SimpleTensor< T >::data_type(), arm_compute::test::validation::distribution(), arm_compute::F16, and SimpleTensor< T >::num_elements().

523  {
525  std::mt19937 gen(seed);
526  std::uniform_real_distribution<float> distribution(static_cast<half>(low), static_cast<half>(high));
527 
528  for(int i = 0; i < tensor.num_elements(); ++i)
529  {
530  tensor[i] = static_cast<half>(distribution(gen));
531  }
532  }
half_float::half half
16-bit floating point type
Definition: Types.h:48
DataType data_type() const override
Data type of the tensor.
Definition: SimpleTensor.h:357
#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
1 channel, 1 F16 per channel
std::uniform_real_distribution< float > distribution(-5.f, 5.f)
int num_elements() const override
Number of elements of the tensor.
Definition: SimpleTensor.h:406

◆ output_shape()

virtual TensorShape output_shape ( ITensor tensor)
inlinevirtual

Calculate reference output tensor shape.

Parameters
[in]tensorTensor result of the actual operation passed into the Accessor.
Returns
output tensor shape.

Definition at line 419 of file graph_validate_utils.h.

References bias, ITensor::info(), arm_compute::NCHW, arm_compute::test::validation::output_shape, arm_compute::graph_utils::permute_shape(), arm_compute::test::validation::src, and ITensorInfo::tensor_shape().

420  {
421  return arm_compute::graph_utils::permute_shape(tensor.info()->tensor_shape(), _params.data_layout, DataLayout::NCHW);
422  }
Num samples, channels, height, width.
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

◆ reference()

virtual arm_compute::test::SimpleTensor<D> reference ( arm_compute::test::SimpleTensor< D > &  src,
arm_compute::test::SimpleTensor< D > &  weights,
arm_compute::test::SimpleTensor< TBias > &  bias,
const arm_compute::TensorShape output_shape 
)
pure virtual

Calculate reference tensor.

Validate the given tensor against the reference result.

Parameters
[in]srcThe tensor with the source data.
[in]weightsThe tensor with the weigths data.
[in]biasThe tensor with the bias data.
[in]output_shapeShape of the output tensor.
Returns
Tensor with the reference output.

◆ relative_tolerance()

virtual float relative_tolerance ( )
pure virtual

Select relative tolerance.

Select relative tolerance if not supplied by user.

Returns
Appropriate relative tolerance.

◆ tolerance_number()

virtual float tolerance_number ( )
pure virtual

Select tolerance number.

Select tolerance number if not supplied by user.

Returns
Appropriate tolerance number.

◆ validate()

void validate ( ITensor tensor,
arm_compute::test::SimpleTensor< D >  output 
)
inline

Validate the output versus the reference.

Parameters
[in]tensorTensor result of the actual operation passed into the Accessor.
[in]outputTensor result of the reference implementation.
Returns
None.

< Relative tolerance

< Absolute tolerance

< Tolerance number

Definition at line 565 of file graph_validate_utils.h.

References arm_compute::test::validation::validate().

566  {
567  float user_relative_tolerance = _params.verification.relative_tolerance;
568  float user_absolute_tolerance = _params.verification.absolute_tolerance;
569  float user_tolerance_num = _params.verification.tolerance_number;
570  /* If no user input was provided override with defaults. */
571  if(user_relative_tolerance == -1)
572  {
573  user_relative_tolerance = relative_tolerance();
574  }
575 
576  if(user_absolute_tolerance == -1)
577  {
578  user_absolute_tolerance = absolute_tolerance();
579  }
580 
581  if(user_tolerance_num == -1)
582  {
583  user_tolerance_num = tolerance_number();
584  }
585 
586  const arm_compute::test::validation::RelativeTolerance<float> rel_tolerance(user_relative_tolerance); /**< Relative tolerance */
587  const arm_compute::test::validation::AbsoluteTolerance<float> abs_tolerance(user_absolute_tolerance); /**< Absolute tolerance */
588  const float tolerance_num(user_tolerance_num); /**< Tolerance number */
589 
590  arm_compute::test::validation::validate(arm_compute::test::Accessor(tensor), output, rel_tolerance, tolerance_num, abs_tolerance);
591  }
Class reprensenting an absolute tolerance value.
Definition: Validation.h:61
Accessor implementation for Tensor objects.
Definition: Accessor.h:35
virtual float relative_tolerance()=0
Select relative tolerance.
validate(CLAccessor(output_state), expected_output)
Class reprensenting a relative tolerance value.
Definition: Validation.h:97
virtual float tolerance_number()=0
Select tolerance number.
virtual float absolute_tolerance()=0
Select absolute tolerance.

Field Documentation

◆ _params

ExampleParams _params

Definition at line 593 of file graph_validate_utils.h.


The documentation for this class was generated from the following file: