24 #ifndef __ARM_COMPUTE_TEST_VALIDATION_H__ 25 #define __ARM_COMPUTE_TEST_VALIDATION_H__ 73 constexpr
operator T()
const 79 T _value{ std::numeric_limits<T>::epsilon() };
112 value_type _value{ std::numeric_limits<T>::epsilon() };
116 template <
typename T>
117 inline ::std::ostream &operator<<(::std::ostream &os, const AbsoluteTolerance<T> &tolerance)
119 os << static_cast<typename AbsoluteTolerance<T>::value_type>(tolerance);
125 template <
typename T>
126 inline ::std::ostream &operator<<(::std::ostream &os, const RelativeTolerance<T> &tolerance)
128 os << static_cast<typename RelativeTolerance<T>::value_type>(tolerance);
133 template <
typename T>
143 if(dimensions1[i] != dimensions2[i])
182 template <
typename T,
typename U = AbsoluteTolerance<T>>
195 template <
typename T,
typename U = AbsoluteTolerance<T>>
208 template <
typename T,
typename U = AbsoluteTolerance<T>>
229 void validate(std::vector<unsigned int> classified_labels, std::vector<unsigned int> expected_labels);
235 template <
typename T,
typename U = AbsoluteTolerance<T>>
239 template <
typename T,
typename U,
typename V = AbsoluteTolerance<
float>>
241 float allowed_missing_percentage = 5.f,
float allowed_mismatch_percentage = 5.f);
243 template <
typename T>
246 compare_base(
typename T::value_type target,
typename T::value_type reference, T tolerance = T(0))
247 : _target{ target }, _reference{ reference }, _tolerance{ tolerance }
251 typename T::value_type _target{};
252 typename T::value_type _reference{};
256 template <
typename T>
259 template <
typename U>
264 operator bool()
const 270 else if(this->_target == this->_reference)
277 const comparison_type abs_difference(
std::abs(static_cast<comparison_type>(this->_target) - static_cast<comparison_type>(this->_reference)));
279 return abs_difference <= static_cast<comparison_type>(this->_tolerance);
283 template <
typename U>
288 operator bool()
const 294 else if(this->_target == this->_reference)
301 if(
std::abs(static_cast<double>(this->_reference) -
static_cast<double>(this->_target)) <= epsilon)
307 if(static_cast<double>(this->_reference) == 0.0f)
312 const double relative_change =
std::abs(static_cast<double>(this->_target) - static_cast<double>(this->_reference)) / this->_reference;
314 return relative_change <= static_cast<U>(this->_tolerance);
319 template <
typename T,
typename U>
333 template <
typename T,
typename U>
336 int64_t num_mismatches = 0;
337 int64_t num_elements = 0;
354 for(
int element_idx = 0; element_idx < min_elements; ++element_idx)
361 for(
int c = 0;
c < min_channels; ++
c)
363 const T &target_value =
reinterpret_cast<const T *
>(tensor(
id))[
c];
364 const T &reference_value =
reinterpret_cast<const T *
>(reference(
id))[
c];
367 const T target_truncated_value =
static_cast<T
>(
static_cast<int>(target_value * 10000) / 10000);
368 const T reference_truncated_value =
static_cast<T
>(
static_cast<int>(target_value * 10000) / 10000);
369 if(!
compare<U>(target_truncated_value, reference_truncated_value, tolerance_value))
388 const int64_t absolute_tolerance_number = tolerance_number * num_elements;
389 const float percent_mismatches =
static_cast<float>(num_mismatches) / num_elements * 100.f;
391 ARM_COMPUTE_TEST_INFO(num_mismatches <<
" values (" << std::fixed << std::setprecision(2) << percent_mismatches
392 <<
"%) mismatched (maximum tolerated " << std::setprecision(2) << tolerance_number <<
"%)");
400 int64_t num_mismatches = 0;
401 int64_t num_elements = 0;
418 for(
int element_idx = 0; element_idx < min_elements; ++element_idx)
425 for(
int c = 0;
c < min_channels; ++
c)
427 const T &target_value =
reinterpret_cast<const T *
>(tensor(
id))[
c];
428 const T &reference_value =
reinterpret_cast<const T *
>(reference(
id))[
c];
430 bool equal =
compare<U>(target_value, reference_value, tolerance_value);
444 uint64_t abs_sum =
std::abs(static_cast<int64_t>(target_value)) +
std::abs(static_cast<int64_t>(reference_value));
445 uint64_t wrap_difference = max - abs_sum;
447 equal = wrap_difference < static_cast<uint64_t>(tolerance_value);
470 const int64_t absolute_tolerance_number = tolerance_number * num_elements;
471 const float percent_mismatches =
static_cast<float>(num_mismatches) / num_elements * 100.f;
473 ARM_COMPUTE_TEST_INFO(num_mismatches <<
" values (" << std::fixed << std::setprecision(2) << percent_mismatches
474 <<
"%) mismatched (maximum tolerated " << std::setprecision(2) << tolerance_number <<
"%)");
479 template <
typename T,
typename U>
482 int64_t num_mismatches = 0;
483 int64_t num_elements = 0;
500 for(
int element_idx = 0; element_idx < min_elements; ++element_idx)
504 if(valid_mask[element_idx] == 1)
507 for(
int c = 0;
c < min_channels; ++
c)
509 const T &target_value =
reinterpret_cast<const T *
>(tensor(
id))[
c];
510 const T &reference_value =
reinterpret_cast<const T *
>(reference(
id))[
c];
512 if(!
compare<U>(target_value, reference_value, tolerance_value))
535 const int64_t absolute_tolerance_number = tolerance_number * num_elements;
536 const float percent_mismatches =
static_cast<float>(num_mismatches) / num_elements * 100.f;
538 ARM_COMPUTE_TEST_INFO(num_mismatches <<
" values (" << std::fixed << std::setprecision(2) << percent_mismatches
539 <<
"%) mismatched (maximum tolerated " << std::setprecision(2) << tolerance_number <<
"%)");
544 template <
typename T,
typename U>
551 const bool equal =
compare<U>(target, reference, tolerance);
558 template <
typename T,
typename U>
567 for(uint32_t i = 0; i < target.
min_loc.size(); ++i)
571 return coord.x == target.
min_loc.at(i).x && coord.y == target.
min_loc.at(i).y;
577 for(uint32_t i = 0; i < target.
max_loc.size(); ++i)
581 return coord.x == target.
max_loc.at(i).x && coord.y == target.
max_loc.at(i).y;
589 template <
typename T,
typename U,
typename V>
590 std::pair<int64_t, int64_t>
compare_keypoints(T first1, T last1, U first2, U last2, V tolerance,
bool check_mismatches =
true)
593 const auto compare_props_eq = [&](
const KeyPoint & lhs,
const KeyPoint & rhs)
597 && lhs.
scale == rhs.scale
599 && lhs.
error == rhs.error;
603 const auto compare_coords_lt = [](
const KeyPoint & lhs,
const KeyPoint & rhs)
605 return std::tie(lhs.
x, lhs.
y) < std::tie(rhs.x, rhs.y);
608 std::sort(first1, last1, compare_coords_lt);
609 std::sort(first2, last2, compare_coords_lt);
613 ARM_COMPUTE_TEST_INFO(
"Checking for mismatches: ref count = " << std::distance(first1, last1) <<
" \ttarget count = " << std::distance(first2, last2));
616 int64_t num_missing = 0;
617 int64_t num_mismatches = 0;
618 bool rest_missing =
false;
620 while(first1 != last1)
628 if(compare_coords_lt(*first1, *first2))
636 if(!compare_coords_lt(*first2, *first1))
638 if(check_mismatches && !compare_props_eq(*first1, *first2))
653 while(first1 != last1)
661 return std::make_pair(num_missing, num_mismatches);
664 template <
typename T,
typename U,
typename V>
665 void validate_keypoints(T target_first, T target_last, U reference_first, U reference_last, V tolerance,
float allowed_missing_percentage,
float allowed_mismatch_percentage)
667 const int64_t num_elements_target = std::distance(target_first, target_last);
668 const int64_t num_elements_reference = std::distance(reference_first, reference_last);
670 int64_t num_missing = 0;
671 int64_t num_mismatches = 0;
673 if(num_elements_reference > 0)
675 std::tie(num_missing, num_mismatches) =
compare_keypoints(reference_first, reference_last, target_first, target_last, tolerance);
677 const float percent_missing =
static_cast<float>(num_missing) / num_elements_reference * 100.f;
678 const float percent_mismatches =
static_cast<float>(num_mismatches) / num_elements_reference * 100.f;
680 ARM_COMPUTE_TEST_INFO(num_missing <<
" keypoints (" << std::fixed << std::setprecision(2) << percent_missing <<
"%) in ref are missing from target");
681 ARM_COMPUTE_TEST_INFO(
"Missing (not in tgt): " << num_missing <<
"/" << num_elements_reference <<
" = " << std::fixed << std::setprecision(2) << percent_missing
682 <<
"% \tMax allowed: " << allowed_missing_percentage <<
"%");
685 ARM_COMPUTE_TEST_INFO(num_mismatches <<
" keypoints (" << std::fixed << std::setprecision(2) << percent_mismatches <<
"%) mismatched");
686 ARM_COMPUTE_TEST_INFO(
"Mismatched keypoints: " << num_mismatches <<
"/" << num_elements_reference <<
" = " << std::fixed << std::setprecision(2) << percent_mismatches
687 <<
"% \tMax allowed: " << allowed_mismatch_percentage <<
"%");
691 if(num_elements_target > 0)
694 std::tie(num_missing, num_mismatches) =
compare_keypoints(target_first, target_last, reference_first, reference_last, tolerance,
false);
696 const float percent_missing =
static_cast<float>(num_missing) / num_elements_target * 100.f;
698 ARM_COMPUTE_TEST_INFO(num_missing <<
" keypoints (" << std::fixed << std::setprecision(2) << percent_missing <<
"%) in target are missing from ref");
699 ARM_COMPUTE_TEST_INFO(
"Missing (not in ref): " << num_missing <<
"/" << num_elements_target <<
" = " << std::fixed << std::setprecision(2) << percent_missing
700 <<
"% \tMax allowed: " << allowed_missing_percentage <<
"%");
constexpr AbsoluteTolerance(T value)
Constructor.
BorderMode
Methods available to handle borders.
U value_type
Underlying type.
bool compare_dimensions(const Dimensions< T > &dimensions1, const Dimensions< T > &dimensions2)
fixed_point< T > min(fixed_point< T > x, fixed_point< T > y)
size_t element_size() const override
Size of each element in the tensor in bytes.
float scale
Scale initialized to 0 by the corner detector.
Class reprensenting an absolute tolerance value.
std::vector< Coordinates2D > min_loc
virtual Format format() const =0
Image format of the tensor.
Container for 2D border size.
float orientation
Orientation initialized to 0 by the corner detector.
int make_printable(int8_t value)
int32_t tracking_status
Status initialized to 1 by the corner detector, set to 0 when the point is lost.
Format format() const override
Image format of the tensor.
DataType data_type() const override
Data type of the tensor.
compare_base(typename T::value_type target, typename T::value_type reference, T tolerance=T(0))
TensorShape shape() const override
Shape of the tensor.
#define ARM_COMPUTE_EXPECT_EQUAL(X, Y, LEVEL)
virtual TensorShape shape() const =0
Shape of the tensor.
#define ARM_COMPUTE_TEST_INFO(INFO)
This file contains all available output stages for GEMMLowp on OpenCL.
U value_type
Underlying type.
float strength
Strength of the point.
void validate_min_max_loc(const MinMaxLocationValues< T > &target, const MinMaxLocationValues< U > &reference)
validate(dst.info() ->valid_region(), dst_valid_region)
float error
Tracking error initialized to 0 by the corner detector.
bool is_in_valid_region(const ValidRegion &valid_region, Coordinates coord)
Check if a coordinate is within a valid region.
Dimensions with dimensionality.
virtual int num_elements() const =0
Number of elements of the tensor.
Coordinates index2coord(const TensorShape &shape, int index)
Convert a linear index into n-dimensional coordinates.
void ARM_COMPUTE_PRINT_INFO()
Simple tensor object that stores elements in a consecutive chunk of memory.
int num_channels() const override
Number of channels of the tensor.
unsigned int num_dimensions() const
Returns the effective dimensionality of the tensor.
ARM_COMPUTE_EXPECT(src.info() ->is_resizable(), framework::LogLevel::ERRORS)
Class reprensenting a relative tolerance value.
virtual DataType data_type() const =0
Data type of the tensor.
Common interface to provide information and access to tensor like structures.
void validate_keypoints(T target_first, T target_last, U reference_first, U reference_last, V tolerance=AbsoluteTolerance< float >(), float allowed_missing_percentage=5.f, float allowed_mismatch_percentage=5.f)
Validate key points.
int num_elements() const override
Number of elements of the tensor.
virtual size_t element_size() const =0
Size of each element in the tensor in bytes.
constexpr RelativeTolerance(value_type value)
Constructor.
fixed_point< T > max(fixed_point< T > x, fixed_point< T > y)
fixed_point< T > abs(fixed_point< T > x)
virtual int num_channels() const =0
Number of channels of the tensor.
ValidRegion shape_to_valid_region(const TensorShape &a_shape, bool border_undefined=false, BorderSize border_size=BorderSize(0))
Create a valid region based on tensor shape, border mode and border size.
std::pair< int64_t, int64_t > compare_keypoints(T first1, T last1, U first2, U last2, V tolerance, bool check_mismatches=true)
Check which keypoints from [first1, last1) are missing in [first2, last2)
void validate_wrap(const IAccessor &tensor, const SimpleTensor< T > &reference, U tolerance_value, float tolerance_number)
std::vector< Coordinates2D > max_loc
AbsoluteTolerance()=default