24 #ifndef ARM_COMPUTE_TEST_VALIDATION_H 25 #define ARM_COMPUTE_TEST_VALIDATION_H 75 constexpr
operator T()
const 121 template <
typename T>
122 inline ::std::ostream &operator<<(::std::ostream &os, const AbsoluteTolerance<T> &tolerance)
124 os << static_cast<typename AbsoluteTolerance<T>::value_type>(tolerance);
130 template <
typename T>
131 inline ::std::ostream &operator<<(::std::ostream &os, const RelativeTolerance<T> &tolerance)
133 os << static_cast<typename RelativeTolerance<T>::value_type>(tolerance);
138 template <
typename T>
152 if(dimensions1[i] != dimensions2[i])
166 if((dimensions1[0] != dimensions2[2]) || (dimensions1[1] != dimensions2[0]) || (dimensions1[2] != dimensions2[1]))
173 if(dimensions1[i] != dimensions2[i])
213 template <
typename T,
typename U = AbsoluteTolerance<T>>
214 void validate(
const IAccessor &tensor,
const SimpleTensor<T> &reference,
U tolerance_value =
U(),
float tolerance_number = 0.f,
float absolute_tolerance_value = 0.f);
226 template <
typename T,
typename U = AbsoluteTolerance<T>>
239 template <
typename T,
typename U = AbsoluteTolerance<T>>
241 float absolute_tolerance_value = 0.f);
261 void validate(std::vector<unsigned int> classified_labels, std::vector<unsigned int> expected_labels);
267 template <
typename T,
typename U = AbsoluteTolerance<T>>
271 template <
typename T,
typename U,
typename V = AbsoluteTolerance<
float>>
273 float allowed_missing_percentage = 5.f,
float allowed_mismatch_percentage = 5.f);
276 template <
typename T,
typename U,
typename V = AbsoluteTolerance<
float>>
278 float allowed_missing_percentage = 5.f,
float allowed_mismatch_percentage = 5.f);
280 template <
typename T>
289 compare_base(
typename T::value_type target,
typename T::value_type reference, T tolerance = T(0))
290 : _target{ target }, _reference{ reference }, _tolerance{ tolerance }
294 typename T::value_type _target{};
295 typename T::value_type _reference{};
299 template <
typename T>
303 template <
typename U>
309 operator bool()
const 315 else if(this->_target == this->_reference)
320 using comparison_type =
typename std::conditional<std::is_integral<U>::value, int64_t,
U>
::type;
322 const comparison_type abs_difference(std::abs(static_cast<comparison_type>(this->_target) - static_cast<comparison_type>(this->_reference)));
324 return abs_difference <= static_cast<comparison_type>(this->_tolerance);
329 template <
typename U>
335 operator bool()
const 341 else if(this->_target == this->_reference)
348 if(std::abs(static_cast<double>(this->_reference) -
static_cast<double>(this->_target)) <=
epsilon)
354 if(static_cast<double>(this->_reference) == 0.0f)
359 const double relative_change = std::abs((static_cast<double>(this->_target) - static_cast<double>(this->_reference)) / this->_reference);
361 return relative_change <= static_cast<U>(this->_tolerance);
366 template <
typename T,
typename U>
373 template <typename T, typename U, typename = typename std::enable_if<std::is_integral<T>::value>
::type>
380 template <
typename T,
typename U>
383 uint64_t num_mismatches = 0;
384 uint64_t num_elements = 0;
401 for(
int element_idx = 0; element_idx < min_elements; ++element_idx)
414 for(
int c = 0; c < min_channels; ++c)
416 const T &target_value =
reinterpret_cast<const T *
>(tensor(target_id))[c];
417 const T &reference_value =
reinterpret_cast<const T *
>(reference(
id))[c];
419 if(!
compare<U>(target_value, reference_value, tolerance_value))
421 if(absolute_tolerance_value != 0.f)
444 if(num_elements != 0)
446 const uint64_t absolute_tolerance_number = tolerance_number * num_elements;
447 const float percent_mismatches =
static_cast<float>(num_mismatches) / num_elements * 100.f;
449 ARM_COMPUTE_TEST_INFO(num_mismatches <<
" values (" << std::fixed << std::setprecision(2) << percent_mismatches
450 <<
"%) mismatched (maximum tolerated " << std::setprecision(2) << tolerance_number * 100 <<
"%)");
455 template <typename T, typename U, typename = typename std::enable_if<std::is_integral<T>::value>
::type>
458 uint64_t num_mismatches = 0;
459 uint64_t num_elements = 0;
476 for(
int element_idx = 0; element_idx < min_elements; ++element_idx)
489 for(
int c = 0; c < min_channels; ++c)
491 const T &target_value =
reinterpret_cast<const T *
>(tensor(target_id))[c];
492 const T &reference_value =
reinterpret_cast<const T *
>(reference(
id))[c];
494 bool equal =
compare<U>(target_value, reference_value, tolerance_value);
507 uint64_t max = std::numeric_limits<limits_type>::max();
508 uint64_t abs_sum = std::abs(static_cast<int64_t>(target_value)) + std::abs(static_cast<int64_t>(reference_value));
509 uint64_t wrap_difference = max - abs_sum;
511 equal = wrap_difference < static_cast<uint64_t>(tolerance_value);
532 if(num_elements != 0)
534 const uint64_t absolute_tolerance_number = tolerance_number * num_elements;
535 const float percent_mismatches =
static_cast<float>(num_mismatches) / num_elements * 100.f;
537 ARM_COMPUTE_TEST_INFO(num_mismatches <<
" values (" << std::fixed << std::setprecision(2) << percent_mismatches
538 <<
"%) mismatched (maximum tolerated " << std::setprecision(2) << tolerance_number * 100 <<
"%)");
543 template <
typename T,
typename U>
546 uint64_t num_mismatches = 0;
547 uint64_t num_elements = 0;
564 for(
int element_idx = 0; element_idx < min_elements; ++element_idx)
574 if(valid_mask[element_idx] == 1)
577 for(
int c = 0; c < min_channels; ++c)
579 const T &target_value =
reinterpret_cast<const T *
>(tensor(target_id))[c];
580 const T &reference_value =
reinterpret_cast<const T *
>(reference(
id))[c];
582 if(!
compare<U>(target_value, reference_value, tolerance_value))
584 if(absolute_tolerance_value != 0.f)
611 if(num_elements != 0)
613 const uint64_t absolute_tolerance_number = tolerance_number * num_elements;
614 const float percent_mismatches =
static_cast<float>(num_mismatches) / num_elements * 100.f;
616 ARM_COMPUTE_TEST_INFO(num_mismatches <<
" values (" << std::fixed << std::setprecision(2) << percent_mismatches
617 <<
"%) mismatched (maximum tolerated " << std::setprecision(2) << tolerance_number * 100 <<
"%)");
622 template <
typename T,
typename U>
629 const bool equal =
compare<U>(target, reference, tolerance);
636 template <
typename T,
typename U>
645 for(uint32_t i = 0; i < target.
min_loc.size(); ++i)
649 return coord.x == target.
min_loc.at(i).x && coord.y == target.
min_loc.at(i).y;
655 for(uint32_t i = 0; i < target.
max_loc.size(); ++i)
659 return coord.x == target.
max_loc.at(i).x && coord.y == target.
max_loc.at(i).y;
667 template <
typename T,
typename U,
typename V>
668 std::pair<int64_t, int64_t>
compare_keypoints(T first1, T last1, U first2, U last2, V tolerance,
bool check_mismatches =
true)
671 const auto compare_props_eq = [&](
const KeyPoint & lhs,
const KeyPoint & rhs)
675 && lhs.
scale == rhs.scale
677 && lhs.
error == rhs.error;
681 const auto compare_coords_lt = [](
const KeyPoint & lhs,
const KeyPoint & rhs)
683 return std::tie(lhs.
x, lhs.
y) < std::tie(rhs.x, rhs.y);
686 std::sort(first1, last1, compare_coords_lt);
687 std::sort(first2, last2, compare_coords_lt);
691 ARM_COMPUTE_TEST_INFO(
"Checking for mismatches: ref count = " << std::distance(first1, last1) <<
" target count = " << std::distance(first2, last2));
694 int64_t num_missing = 0;
695 int64_t num_mismatches = 0;
696 bool rest_missing =
false;
698 while(first1 != last1)
706 if(compare_coords_lt(*first1, *first2))
715 if(!compare_coords_lt(*first2, *first1))
717 if(check_mismatches && !compare_props_eq(*first1, *first2))
733 while(first1 != last1)
742 return std::make_pair(num_missing, num_mismatches);
745 template <
typename T,
typename U,
typename V>
746 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)
748 const int64_t num_elements_target = std::distance(target_first, target_last);
749 const int64_t num_elements_reference = std::distance(reference_first, reference_last);
751 int64_t num_missing = 0;
752 int64_t num_mismatches = 0;
754 if(num_elements_reference > 0)
756 std::tie(num_missing, num_mismatches) =
compare_keypoints(reference_first, reference_last, target_first, target_last, tolerance);
758 const float percent_missing =
static_cast<float>(num_missing) / num_elements_reference * 100.f;
759 const float percent_mismatches =
static_cast<float>(num_mismatches) / num_elements_reference * 100.f;
761 ARM_COMPUTE_TEST_INFO(num_missing <<
" keypoints (" << std::fixed << std::setprecision(2) << percent_missing <<
"%) in ref are missing from target");
762 ARM_COMPUTE_TEST_INFO(
"Missing (not in tgt): " << num_missing <<
"/" << num_elements_reference <<
" = " << std::fixed << std::setprecision(2) << percent_missing
763 <<
"% \tMax allowed: " << allowed_missing_percentage <<
"%");
766 ARM_COMPUTE_TEST_INFO(num_mismatches <<
" keypoints (" << std::fixed << std::setprecision(2) << percent_mismatches <<
"%) mismatched");
767 ARM_COMPUTE_TEST_INFO(
"Mismatched keypoints: " << num_mismatches <<
"/" << num_elements_reference <<
" = " << std::fixed << std::setprecision(2) << percent_mismatches
768 <<
"% \tMax allowed: " << allowed_mismatch_percentage <<
"%");
772 if(num_elements_target > 0)
775 std::tie(num_missing, num_mismatches) =
compare_keypoints(target_first, target_last, reference_first, reference_last, tolerance,
false);
777 const float percent_missing =
static_cast<float>(num_missing) / num_elements_target * 100.f;
779 ARM_COMPUTE_TEST_INFO(num_missing <<
" keypoints (" << std::fixed << std::setprecision(2) << percent_missing <<
"%) in target are missing from ref");
780 ARM_COMPUTE_TEST_INFO(
"Missing (not in ref): " << num_missing <<
"/" << num_elements_target <<
" = " << std::fixed << std::setprecision(2) << percent_missing
781 <<
"% \tMax allowed: " << allowed_missing_percentage <<
"%");
787 template <
typename T,
typename U,
typename V>
790 int64_t num_missing = 0;
791 int64_t num_mismatches = 0;
793 while(first1 != last1)
795 const auto window = std::find_if(first2, last2, [&](
DetectionWindow window)
797 return window.
x == first1->x && window.
y == first1->y && window.
width == first1->width && window.
height == first1->height && window.
idx_class == first1->idx_class;
821 return std::make_pair(num_missing, num_mismatches);
824 template <
typename T,
typename U,
typename V>
826 float allowed_missing_percentage,
float allowed_mismatch_percentage)
828 const int64_t num_elements_target = std::distance(target_first, target_last);
829 const int64_t num_elements_reference = std::distance(reference_first, reference_last);
831 int64_t num_missing = 0;
832 int64_t num_mismatches = 0;
834 if(num_elements_reference > 0)
836 std::tie(num_missing, num_mismatches) =
compare_detection_windows(reference_first, reference_last, target_first, target_last, tolerance);
838 const float percent_missing =
static_cast<float>(num_missing) / num_elements_reference * 100.f;
839 const float percent_mismatches =
static_cast<float>(num_mismatches) / num_elements_reference * 100.f;
841 ARM_COMPUTE_TEST_INFO(num_missing <<
" detection windows (" << std::fixed << std::setprecision(2) << percent_missing <<
"%) are missing in target");
844 ARM_COMPUTE_TEST_INFO(num_mismatches <<
" detection windows (" << std::fixed << std::setprecision(2) << percent_mismatches <<
"%) mismatched");
848 if(num_elements_target > 0)
850 std::tie(num_missing, num_mismatches) =
compare_detection_windows(target_first, target_last, reference_first, reference_last, tolerance);
852 const float percent_missing =
static_cast<float>(num_missing) / num_elements_target * 100.f;
854 ARM_COMPUTE_TEST_INFO(num_missing <<
" detection windows (" << std::fixed << std::setprecision(2) << percent_missing <<
"%) are not part of target");
constexpr AbsoluteTolerance(T value)
Constructor.
BorderMode
Methods available to handle borders.
U value_type
Underlying type.
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
Min value location.
uint16_t x
Top-left x coordinate.
float score
Confidence value for the detection window.
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.
ARM_COMPUTE_EXPECT(has_error==expected, framework::LogLevel::ERRORS)
Strides PermutationVector
Permutation vector.
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
const DataLayout data_layout
compare_base(typename T::value_type target, typename T::value_type reference, T tolerance=T(0))
Construct a comparison object.
TensorShape shape() const override
Shape of the tensor.
bool compare_dimensions(const Dimensions< T > &dimensions1, const Dimensions< T > &dimensions2, const DataLayout &data_layout=DataLayout::NCHW)
const ValidRegion valid_region
decltype(strategy::transforms) typedef type
#define ARM_COMPUTE_EXPECT_EQUAL(X, Y, LEVEL)
virtual TensorShape shape() const =0
Shape of the tensor.
#define ARM_COMPUTE_TEST_INFO(INFO)
Copyright (c) 2017-2021 Arm Limited.
U value_type
Underlying type.
float strength
Strength of the point.
void permute(Dimensions< T > &dimensions, const PermutationVector &perm)
Permutes given Dimensions according to a permutation vector.
void validate_detection_windows(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 detection windows.
std::pair< int64_t, int64_t > compare_detection_windows(T first1, T last1, U first2, U last2, V tolerance)
Check which detection windows from [first1, last1) are missing in [first2, last2) ...
T x() const
Alias to access the size of the first dimension.
void validate_min_max_loc(const MinMaxLocationValues< T > &target, const MinMaxLocationValues< U > &reference)
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.
uint16_t width
Width of the detection window.
Dimensions with dimensionality.
Min and max values and locations.
validate(CLAccessor(output_state), expected_output)
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.
virtual DataLayout data_layout() const =0
Data layout of the tensor.
uint16_t idx_class
Index of the class.
Num samples, channels, height, width.
void ARM_COMPUTE_PRINT_INFO()
uint16_t height
Height of the detection window.
Simple tensor object that stores elements in a consecutive chunk of memory.
int num_channels() const override
Number of channels of the tensor.
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.
Detection window used for the object detection.
unsigned int num_dimensions() const
Returns the effective dimensionality of the tensor.
Num samples, height, width, channels.
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.
uint16_t y
Top-left y coordinate.
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.
Container for valid region of a window.
virtual int num_channels() const =0
Number of channels of the tensor.
DataLayout
[DataLayout enum definition]
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
Max value location.
AbsoluteTolerance()=default