24 #ifndef __ARM_COMPUTE_TEST_VALIDATION_H__ 25 #define __ARM_COMPUTE_TEST_VALIDATION_H__ 76 constexpr
operator T()
const 82 T _value{ std::numeric_limits<T>::epsilon() };
118 value_type _value{ std::numeric_limits<T>::epsilon() };
122 template <
typename T>
123 inline ::std::ostream &operator<<(::std::ostream &os, const AbsoluteTolerance<T> &tolerance)
125 os << static_cast<typename AbsoluteTolerance<T>::value_type>(tolerance);
131 template <
typename T>
132 inline ::std::ostream &operator<<(::std::ostream &os, const RelativeTolerance<T> &tolerance)
134 os << static_cast<typename RelativeTolerance<T>::value_type>(tolerance);
139 template <
typename T>
153 if(dimensions1[i] != dimensions2[i])
167 if((dimensions1[0] != dimensions2[2]) || (dimensions1[1] != dimensions2[0]) || (dimensions1[2] != dimensions2[1]))
174 if(dimensions1[i] != dimensions2[i])
214 template <
typename T,
typename U = AbsoluteTolerance<T>>
215 void validate(
const IAccessor &tensor,
const SimpleTensor<T> &reference,
U tolerance_value =
U(),
float tolerance_number = 0.f,
float absolute_tolerance_value = 0.f);
227 template <
typename T,
typename U = AbsoluteTolerance<T>>
240 template <
typename T,
typename U = AbsoluteTolerance<T>>
242 float absolute_tolerance_value = 0.f);
262 void validate(std::vector<unsigned int> classified_labels, std::vector<unsigned int> expected_labels);
268 template <
typename T,
typename U = AbsoluteTolerance<T>>
272 template <
typename T,
typename U,
typename V = AbsoluteTolerance<
float>>
274 float allowed_missing_percentage = 5.f,
float allowed_mismatch_percentage = 5.f);
277 template <
typename T,
typename U,
typename V = AbsoluteTolerance<
float>>
279 float allowed_missing_percentage = 5.f,
float allowed_mismatch_percentage = 5.f);
281 template <
typename T>
290 compare_base(
typename T::value_type target,
typename T::value_type reference, T tolerance = T(0))
291 : _target{ target }, _reference{ reference }, _tolerance{ tolerance }
295 typename T::value_type _target{};
296 typename T::value_type _reference{};
300 template <
typename T>
304 template <
typename U>
310 operator bool()
const 316 else if(this->_target == this->_reference)
321 using comparison_type =
typename std::conditional<std::is_integral<U>::value, int64_t,
U>::type;
323 const comparison_type abs_difference(
std::abs(static_cast<comparison_type>(this->_target) - static_cast<comparison_type>(this->_reference)));
325 return abs_difference <= static_cast<comparison_type>(this->_tolerance);
330 template <
typename U>
336 operator bool()
const 342 else if(this->_target == this->_reference)
347 const U epsilon = (std::is_same<half, typename std::remove_cv<U>::type>::value || (this->_reference == 0)) ?
static_cast<U>(0.01) :
static_cast<U>(1e-05);
349 if(
std::abs(static_cast<double>(this->_reference) -
static_cast<double>(this->_target)) <= epsilon)
355 if(static_cast<double>(this->_reference) == 0.0f)
360 const double relative_change =
std::abs((static_cast<double>(this->_target) - static_cast<double>(this->_reference)) / this->_reference);
362 return relative_change <= static_cast<U>(this->_tolerance);
367 template <
typename T,
typename U>
374 template <typename T, typename U, typename = typename std::enable_if<std::is_integral<T>::value>::type>
381 template <
typename T,
typename U>
384 int64_t num_mismatches = 0;
385 int64_t num_elements = 0;
402 for(
int element_idx = 0; element_idx < min_elements; ++element_idx)
415 for(
int c = 0;
c < min_channels; ++
c)
417 const T &target_value =
reinterpret_cast<const T *
>(tensor(target_id))[
c];
418 const T &reference_value =
reinterpret_cast<const T *
>(reference(
id))[
c];
420 if(!
compare<U>(target_value, reference_value, tolerance_value))
422 if(absolute_tolerance_value != 0.f)
447 const int64_t absolute_tolerance_number = tolerance_number * num_elements;
448 const float percent_mismatches =
static_cast<float>(num_mismatches) / num_elements * 100.f;
450 ARM_COMPUTE_TEST_INFO(num_mismatches <<
" values (" << std::fixed << std::setprecision(2) << percent_mismatches
451 <<
"%) mismatched (maximum tolerated " << std::setprecision(2) << tolerance_number <<
"%)");
456 template <typename T, typename U, typename = typename std::enable_if<std::is_integral<T>::value>::type>
459 int64_t num_mismatches = 0;
460 int64_t num_elements = 0;
477 for(
int element_idx = 0; element_idx < min_elements; ++element_idx)
490 for(
int c = 0;
c < min_channels; ++
c)
492 const T &target_value =
reinterpret_cast<const T *
>(tensor(target_id))[
c];
493 const T &reference_value =
reinterpret_cast<const T *
>(reference(
id))[
c];
495 bool equal =
compare<U>(target_value, reference_value, tolerance_value);
506 using limits_type =
typename std::make_unsigned<T>::type;
509 uint64_t abs_sum =
std::abs(static_cast<int64_t>(target_value)) +
std::abs(static_cast<int64_t>(reference_value));
510 uint64_t wrap_difference = max - abs_sum;
512 equal = wrap_difference < static_cast<uint64_t>(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>
547 int64_t num_mismatches = 0;
548 int64_t num_elements = 0;
565 for(
int element_idx = 0; element_idx < min_elements; ++element_idx)
575 if(valid_mask[element_idx] == 1)
578 for(
int c = 0;
c < min_channels; ++
c)
580 const T &target_value =
reinterpret_cast<const T *
>(tensor(target_id))[
c];
581 const T &reference_value =
reinterpret_cast<const T *
>(reference(
id))[
c];
583 if(!
compare<U>(target_value, reference_value, tolerance_value))
585 if(absolute_tolerance_value != 0.f)
614 const int64_t absolute_tolerance_number = tolerance_number * num_elements;
615 const float percent_mismatches =
static_cast<float>(num_mismatches) / num_elements * 100.f;
617 ARM_COMPUTE_TEST_INFO(num_mismatches <<
" values (" << std::fixed << std::setprecision(2) << percent_mismatches
618 <<
"%) mismatched (maximum tolerated " << std::setprecision(2) << tolerance_number <<
"%)");
623 template <
typename T,
typename U>
630 const bool equal =
compare<U>(target, reference, tolerance);
637 template <
typename T,
typename U>
646 for(uint32_t i = 0; i < target.
min_loc.size(); ++i)
650 return coord.x == target.
min_loc.at(i).x && coord.y == target.
min_loc.at(i).y;
656 for(uint32_t i = 0; i < target.
max_loc.size(); ++i)
660 return coord.x == target.
max_loc.at(i).x && coord.y == target.
max_loc.at(i).y;
668 template <
typename T,
typename U,
typename V>
669 std::pair<int64_t, int64_t>
compare_keypoints(T first1, T last1, U first2, U last2, V tolerance,
bool check_mismatches =
true)
672 const auto compare_props_eq = [&](
const KeyPoint & lhs,
const KeyPoint & rhs)
676 && lhs.
scale == rhs.scale
678 && lhs.
error == rhs.error;
682 const auto compare_coords_lt = [](
const KeyPoint & lhs,
const KeyPoint & rhs)
684 return std::tie(lhs.
x, lhs.
y) < std::tie(rhs.x, rhs.y);
687 std::sort(first1, last1, compare_coords_lt);
688 std::sort(first2, last2, compare_coords_lt);
692 ARM_COMPUTE_TEST_INFO(
"Checking for mismatches: ref count = " << std::distance(first1, last1) <<
" \ttarget count = " << std::distance(first2, last2));
695 int64_t num_missing = 0;
696 int64_t num_mismatches = 0;
697 bool rest_missing =
false;
699 while(first1 != last1)
707 if(compare_coords_lt(*first1, *first2))
715 if(!compare_coords_lt(*first2, *first1))
717 if(check_mismatches && !compare_props_eq(*first1, *first2))
732 while(first1 != last1)
740 return std::make_pair(num_missing, num_mismatches);
743 template <
typename T,
typename U,
typename V>
744 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)
746 const int64_t num_elements_target = std::distance(target_first, target_last);
747 const int64_t num_elements_reference = std::distance(reference_first, reference_last);
749 int64_t num_missing = 0;
750 int64_t num_mismatches = 0;
752 if(num_elements_reference > 0)
754 std::tie(num_missing, num_mismatches) =
compare_keypoints(reference_first, reference_last, target_first, target_last, tolerance);
756 const float percent_missing =
static_cast<float>(num_missing) / num_elements_reference * 100.f;
757 const float percent_mismatches =
static_cast<float>(num_mismatches) / num_elements_reference * 100.f;
759 ARM_COMPUTE_TEST_INFO(num_missing <<
" keypoints (" << std::fixed << std::setprecision(2) << percent_missing <<
"%) in ref are missing from target");
760 ARM_COMPUTE_TEST_INFO(
"Missing (not in tgt): " << num_missing <<
"/" << num_elements_reference <<
" = " << std::fixed << std::setprecision(2) << percent_missing
761 <<
"% \tMax allowed: " << allowed_missing_percentage <<
"%");
764 ARM_COMPUTE_TEST_INFO(num_mismatches <<
" keypoints (" << std::fixed << std::setprecision(2) << percent_mismatches <<
"%) mismatched");
765 ARM_COMPUTE_TEST_INFO(
"Mismatched keypoints: " << num_mismatches <<
"/" << num_elements_reference <<
" = " << std::fixed << std::setprecision(2) << percent_mismatches
766 <<
"% \tMax allowed: " << allowed_mismatch_percentage <<
"%");
770 if(num_elements_target > 0)
773 std::tie(num_missing, num_mismatches) =
compare_keypoints(target_first, target_last, reference_first, reference_last, tolerance,
false);
775 const float percent_missing =
static_cast<float>(num_missing) / num_elements_target * 100.f;
777 ARM_COMPUTE_TEST_INFO(num_missing <<
" keypoints (" << std::fixed << std::setprecision(2) << percent_missing <<
"%) in target are missing from ref");
778 ARM_COMPUTE_TEST_INFO(
"Missing (not in ref): " << num_missing <<
"/" << num_elements_target <<
" = " << std::fixed << std::setprecision(2) << percent_missing
779 <<
"% \tMax allowed: " << allowed_missing_percentage <<
"%");
785 template <
typename T,
typename U,
typename V>
788 int64_t num_missing = 0;
789 int64_t num_mismatches = 0;
791 while(first1 != last1)
793 const auto window = std::find_if(first2, last2, [&](
DetectionWindow window)
795 return window.
x == first1->x && window.
y == first1->y && window.
width == first1->width && window.
height == first1->height && window.
idx_class == first1->idx_class;
817 return std::make_pair(num_missing, num_mismatches);
820 template <
typename T,
typename U,
typename V>
822 float allowed_missing_percentage,
float allowed_mismatch_percentage)
824 const int64_t num_elements_target = std::distance(target_first, target_last);
825 const int64_t num_elements_reference = std::distance(reference_first, reference_last);
827 int64_t num_missing = 0;
828 int64_t num_mismatches = 0;
830 if(num_elements_reference > 0)
832 std::tie(num_missing, num_mismatches) =
compare_detection_windows(reference_first, reference_last, target_first, target_last, tolerance);
834 const float percent_missing =
static_cast<float>(num_missing) / num_elements_reference * 100.f;
835 const float percent_mismatches =
static_cast<float>(num_mismatches) / num_elements_reference * 100.f;
837 ARM_COMPUTE_TEST_INFO(num_missing <<
" detection windows (" << std::fixed << std::setprecision(2) << percent_missing <<
"%) are missing in target");
840 ARM_COMPUTE_TEST_INFO(num_mismatches <<
" detection windows (" << std::fixed << std::setprecision(2) << percent_mismatches <<
"%) mismatched");
844 if(num_elements_target > 0)
846 std::tie(num_missing, num_mismatches) =
compare_detection_windows(target_first, target_last, reference_first, reference_last, tolerance);
848 const float percent_missing =
static_cast<float>(num_missing) / num_elements_target * 100.f;
850 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.
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
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.
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.
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)
#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.
T x() const
Alias to access the size of the first dimension.
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) ...
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.
uint16_t width
Width of the detection window.
Dimensions with dimensionality.
Min and max values and locations.
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.
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.
Detection window used for the object detection.
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.
fixed_point< T > max(fixed_point< T > x, fixed_point< T > y)
fixed_point< T > abs(fixed_point< T > x)
Container for valid region of a window.
virtual int num_channels() const =0
Number of channels of the tensor.
DataLayout
Supported tensor data layouts.
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