From ec5f85f85c0195b16c0e7714d1f89f23c75cf2bc Mon Sep 17 00:00:00 2001 From: Manuel Bottini Date: Wed, 13 Feb 2019 16:34:56 +0000 Subject: COMPMID-1999: Add support for GenerateProposals operator in CL Change-Id: Ie08a6874347085f96b00f25bdb605eee7d683c25 Signed-off-by: giuros01 Reviewed-on: https://review.mlplatform.org/719 Tested-by: Arm Jenkins Reviewed-by: Georgios Pinitas Reviewed-by: Michalis Spyrou --- tests/validation/reference/ComputeAllAnchors.cpp | 79 ++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 tests/validation/reference/ComputeAllAnchors.cpp (limited to 'tests/validation/reference/ComputeAllAnchors.cpp') diff --git a/tests/validation/reference/ComputeAllAnchors.cpp b/tests/validation/reference/ComputeAllAnchors.cpp new file mode 100644 index 0000000000..3f0498015a --- /dev/null +++ b/tests/validation/reference/ComputeAllAnchors.cpp @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2019 ARM Limited. + * + * SPDX-License-Identifier: MIT + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +#include "ComputeAllAnchors.h" + +#include "arm_compute/core/Types.h" +#include "arm_compute/core/utils/misc/ShapeCalculator.h" +#include "arm_compute/core/utils/misc/Utility.h" +#include "tests/validation/Helpers.h" + +namespace arm_compute +{ +namespace test +{ +namespace validation +{ +namespace reference +{ +template +SimpleTensor compute_all_anchors(const SimpleTensor &anchors, const ComputeAnchorsInfo &info) +{ + const int num_anchors = anchors.shape()[1]; + const auto width = int(info.feat_width()); + const auto height = int(info.feat_height()); + const float stride = 1. / info.spatial_scale(); + + SimpleTensor all_anchors(TensorShape(4, width * height * num_anchors), anchors.data_type()); + const T *anchors_ptr = anchors.data(); + T *all_anchors_ptr = all_anchors.data(); + + // Iterate over the input grid and anchors + for(int y = 0; y < height; y++) + { + for(int x = 0; x < width; x++) + { + for(int a = 0; a < num_anchors; a++) + { + const T shift_x = T(x) * T(stride); + const T shift_y = T(y) * T(stride); + const size_t anchor_id = a + x * num_anchors + y * width * num_anchors; + // x1 + all_anchors_ptr[anchor_id * 4] = anchors_ptr[4 * a] + shift_x; + // y1 + all_anchors_ptr[anchor_id * 4 + 1] = anchors_ptr[4 * a + 1] + shift_y; + // x2 + all_anchors_ptr[anchor_id * 4 + 2] = anchors_ptr[4 * a + 2] + shift_x; + // y2 + all_anchors_ptr[anchor_id * 4 + 3] = anchors_ptr[4 * a + 3] + shift_y; + } + } + } + return all_anchors; +} +template SimpleTensor compute_all_anchors(const SimpleTensor &anchors, const ComputeAnchorsInfo &info); +template SimpleTensor compute_all_anchors(const SimpleTensor &anchors, const ComputeAnchorsInfo &info); +} // namespace reference +} // namespace validation +} // namespace test +} // namespace arm_compute -- cgit v1.2.1