diff options
author | Pablo Tello <pablo.tello@arm.com> | 2018-12-21 16:47:23 +0000 |
---|---|---|
committer | Georgios Pinitas <georgios.pinitas@arm.com> | 2019-01-21 16:44:00 +0000 |
commit | a0a0e29f635de08092c2325f8f049ffb286aabaf (patch) | |
tree | 26e33498f278c0b54e7b47cd376e63be5ad526c5 /tests/AssetsLibrary.h | |
parent | 3ddb9ae7c0b9e351179387e530922252315900ad (diff) | |
download | ComputeLibrary-a0a0e29f635de08092c2325f8f049ffb286aabaf.tar.gz |
COMPMID-1766: Implemented CPP Non Max Suppression
Change-Id: I1dcd5fb3d9ad6c6c750415bf8074698b800dfbc1
Reviewed-on: https://review.mlplatform.org/494
Tested-by: Arm Jenkins <bsgcomp@arm.com>
Reviewed-by: Giuseppe Rossini <giuseppe.rossini@arm.com>
Reviewed-by: Georgios Pinitas <georgios.pinitas@arm.com>
Diffstat (limited to 'tests/AssetsLibrary.h')
-rw-r--r-- | tests/AssetsLibrary.h | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/tests/AssetsLibrary.h b/tests/AssetsLibrary.h index d09e22762d..366c1450ba 100644 --- a/tests/AssetsLibrary.h +++ b/tests/AssetsLibrary.h @@ -207,6 +207,9 @@ public: template <typename T, typename D> void fill(T &&tensor, D &&distribution, std::random_device::result_type seed_offset) const; + template <typename T, typename D> + void fill_boxes(T &&tensor, D &&distribution, std::random_device::result_type seed_offset) const; + /** Fills the specified @p raw tensor with random values drawn from @p * distribution. * @@ -482,6 +485,40 @@ void AssetsLibrary::fill_borders_with_garbage(T &&tensor, D &&distribution, std: } template <typename T, typename D> +void AssetsLibrary::fill_boxes(T &&tensor, D &&distribution, std::random_device::result_type seed_offset) const +{ + using ResultType = typename std::remove_reference<D>::type::result_type; + std::mt19937 gen(_seed + seed_offset); + TensorShape shape(tensor.shape()); + const int num_boxes = tensor.num_elements() / 4; + // Iterate over all elements + std::uniform_real_distribution<> size_dist(0.f, 1.f); + for(int element_idx = 0; element_idx < num_boxes * 4; element_idx += 4) + { + const ResultType delta = size_dist(gen); + const ResultType epsilon = size_dist(gen); + const ResultType left = distribution(gen); + const ResultType top = distribution(gen); + const ResultType right = left + delta; + const ResultType bottom = top + epsilon; + const std::tuple<ResultType, ResultType, ResultType, ResultType> box(left, top, right, bottom); + Coordinates x1 = index2coord(shape, element_idx); + Coordinates y1 = index2coord(shape, element_idx + 1); + Coordinates x2 = index2coord(shape, element_idx + 2); + Coordinates y2 = index2coord(shape, element_idx + 3); + ResultType &target_value_x1 = reinterpret_cast<ResultType *>(tensor(x1))[0]; + ResultType &target_value_y1 = reinterpret_cast<ResultType *>(tensor(y1))[0]; + ResultType &target_value_x2 = reinterpret_cast<ResultType *>(tensor(x2))[0]; + ResultType &target_value_y2 = reinterpret_cast<ResultType *>(tensor(y2))[0]; + store_value_with_data_type(&target_value_x1, std::get<0>(box), tensor.data_type()); + store_value_with_data_type(&target_value_y1, std::get<1>(box), tensor.data_type()); + store_value_with_data_type(&target_value_x2, std::get<2>(box), tensor.data_type()); + store_value_with_data_type(&target_value_y2, std::get<3>(box), tensor.data_type()); + } + fill_borders_with_garbage(tensor, distribution, seed_offset); +} + +template <typename T, typename D> void AssetsLibrary::fill(T &&tensor, D &&distribution, std::random_device::result_type seed_offset) const { using ResultType = typename std::remove_reference<D>::type::result_type; |