24 #ifndef __ARM_COMPUTE_TEST_VALIDATION_H__
25 #define __ARM_COMPUTE_TEST_VALIDATION_H__
72 constexpr
operator T()
const
78 T _value{ std::numeric_limits<T>::epsilon() };
111 value_type _value{ std::numeric_limits<T>::epsilon() };
115 template <
typename T>
116 inline ::std::ostream &operator<<(::std::ostream &os, const AbsoluteTolerance<T> &tolerance)
118 os << static_cast<typename AbsoluteTolerance<T>::value_type>(tolerance);
124 template <
typename T>
125 inline ::std::ostream &operator<<(::std::ostream &os, const RelativeTolerance<T> &tolerance)
127 os << static_cast<typename RelativeTolerance<T>::value_type>(tolerance);
132 template <
typename T>
142 if(dimensions1[i] != dimensions2[i])
175 template <
typename T,
typename U = AbsoluteTolerance<T>>
188 template <
typename T,
typename U = AbsoluteTolerance<T>>
209 void validate(std::vector<unsigned int> classified_labels, std::vector<unsigned int> expected_labels);
215 template <
typename T,
typename U = AbsoluteTolerance<T>>
216 bool validate(T target, T reference, U tolerance = AbsoluteTolerance<T>());
219 template <
typename T,
typename U,
typename V = AbsoluteTolerance<
float>>
220 void validate_keypoints(T target_first, T target_last, U reference_first, U reference_last, V tolerance = AbsoluteTolerance<float>());
222 template <
typename T>
225 compare_base(
typename T::value_type target,
typename T::value_type reference, T tolerance = T(0))
235 template <
typename T>
238 template <
typename U>
243 operator bool()
const
245 if(!std::isfinite(this->_target) || !std::isfinite(this->_reference))
249 else if(this->_target == this->_reference)
256 const comparison_type abs_difference(
std::abs(static_cast<comparison_type>(this->_target) - static_cast<comparison_type>(this->_reference)));
258 return abs_difference <= static_cast<comparison_type>(this->_tolerance);
262 template <
typename U>
267 operator bool()
const
269 if(!std::isfinite(this->_target) || !std::isfinite(this->_reference))
273 else if(this->_target == this->_reference)
280 if(
std::abs(static_cast<double>(this->_reference) -
static_cast<double>(this->_target)) <= epsilon)
286 if(static_cast<double>(this->_reference) == 0.0f)
291 const double relative_change =
std::abs(static_cast<double>(this->_target) - static_cast<double>(this->_reference)) / this->_reference;
293 return relative_change <= static_cast<U>(this->_tolerance);
298 template <
typename T,
typename U>
305 template <
typename T,
typename U>
308 int64_t num_mismatches = 0;
309 int64_t num_elements = 0;
326 for(
int element_idx = 0; element_idx < min_elements; ++element_idx)
333 for(
int c = 0; c < min_channels; ++c)
335 const T &target_value =
reinterpret_cast<const T *
>(tensor(
id))[c];
336 const T &reference_value =
reinterpret_cast<const T *
>(reference(
id))[c];
338 if(!
compare<U>(target_value, reference_value, tolerance_value))
357 const int64_t absolute_tolerance_number = tolerance_number * num_elements;
358 const float percent_mismatches =
static_cast<float>(num_mismatches) / num_elements * 100.f;
360 ARM_COMPUTE_TEST_INFO(num_mismatches <<
" values (" << std::fixed << std::setprecision(2) << percent_mismatches
361 <<
"%) mismatched (maximum tolerated " << std::setprecision(2) << tolerance_number <<
"%)");
367 template <
typename T,
typename U,
typename V>
368 std::pair<int64_t, int64_t>
compare_keypoints(T first1, T last1, U first2, U last2, V tolerance)
370 int64_t num_missing = 0;
371 int64_t num_mismatches = 0;
373 while(first1 != last1)
375 const auto point = std::find_if(first2, last2, [&](
KeyPoint point)
377 return point.
x == first1->x && point.
y == first1->y;
398 return std::make_pair(num_missing, num_mismatches);
401 template <
typename T,
typename U,
typename V>
402 void validate_keypoints(T target_first, T target_last, U reference_first, U reference_last, V tolerance)
404 const int64_t num_elements_target = std::distance(target_first, target_last);
405 const int64_t num_elements_reference = std::distance(reference_first, reference_last);
409 int64_t num_missing = 0;
410 int64_t num_mismatches = 0;
412 if(num_elements_reference > 0)
414 std::tie(num_missing, num_mismatches) =
compare_keypoints(reference_first, reference_last, target_first, target_last, tolerance);
416 const float percent_missing =
static_cast<float>(num_missing) / num_elements_reference * 100.f;
417 const float percent_mismatches =
static_cast<float>(num_mismatches) / num_elements_reference * 100.f;
419 ARM_COMPUTE_TEST_INFO(num_missing <<
" keypoints (" << std::fixed << std::setprecision(2) << percent_missing <<
"%) are missing in target");
422 ARM_COMPUTE_TEST_INFO(num_mismatches <<
" keypoints (" << std::fixed << std::setprecision(2) << percent_mismatches <<
"%) mismatched");
426 if(num_elements_target > 0)
428 std::tie(num_missing, num_mismatches) =
compare_keypoints(target_first, target_last, reference_first, reference_last, tolerance);
430 const float percent_missing =
static_cast<float>(num_missing) / num_elements_target * 100.f;
432 ARM_COMPUTE_TEST_INFO(num_missing <<
" keypoints (" << std::fixed << std::setprecision(2) << percent_missing <<
"%) are not part of target");
437 template <
typename T,
typename U>
444 const bool equal =
compare<U>(target, reference, tolerance);
451 template <
typename T,
typename U>
460 for(uint32_t i = 0; i < target.
min_loc.size(); ++i)
464 return coord.x == target.
min_loc.at(i).x && coord.y == target.
min_loc.at(i).y;
470 for(uint32_t i = 0; i < target.
max_loc.size(); ++i)
474 return coord.x == target.
max_loc.at(i).x && coord.y == target.
max_loc.at(i).y;
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.
ValidRegion shape_to_valid_region(TensorShape shape, bool border_undefined=false, BorderSize border_size=BorderSize(0))
Create a valid region based on tensor shape, border mode and border size.
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_FAIL(MSG, LEVEL)
#define ARM_COMPUTE_EXPECT_EQUAL(X, Y, LEVEL)
virtual TensorShape shape() const =0
Shape of the tensor.
#define ARM_COMPUTE_TEST_INFO(INFO)
U value_type
Underlying type.
float strength
Strength of the point.
void validate_keypoints(T target_first, T target_last, U reference_first, U reference_last, V tolerance=AbsoluteTolerance< float >())
Validate key points.
void validate_min_max_loc(const MinMaxLocationValues< T > &target, const MinMaxLocationValues< U > &reference)
RelativeTolerance()=default
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.
std::pair< int64_t, int64_t > compare_keypoints(T first1, T last1, U first2, U last2, V tolerance)
Check which keypoints from [first1, last1) are missing in [first2, last2)
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.
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(const arm_compute::ValidRegion ®ion, const arm_compute::ValidRegion &reference)
Validate valid regions.
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.
#define ARM_COMPUTE_EXPECT(X, LEVEL)
fixed_point< T > abs(fixed_point< T > x)
virtual int num_channels() const =0
Number of channels of the tensor.
std::vector< Coordinates2D > max_loc
AbsoluteTolerance()=default