Compute Library
 21.08
ComputeAllAnchors.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2019-2020 Arm Limited.
3  *
4  * SPDX-License-Identifier: MIT
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to
8  * deal in the Software without restriction, including without limitation the
9  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10  * sell copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in all
14  * copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * SOFTWARE.
23  */
24 #include "ComputeAllAnchors.h"
25 
26 #include "arm_compute/core/Types.h"
30 
31 namespace arm_compute
32 {
33 namespace test
34 {
35 namespace validation
36 {
37 namespace reference
38 {
39 template <typename T>
41 {
42  const int num_anchors = anchors.shape()[1];
43  const auto width = int(info.feat_width());
44  const auto height = int(info.feat_height());
45  const float stride = 1. / info.spatial_scale();
46 
47  SimpleTensor<T> all_anchors(TensorShape(4, width * height * num_anchors), anchors.data_type());
48  const T *anchors_ptr = anchors.data();
49  T *all_anchors_ptr = all_anchors.data();
50 
51  // Iterate over the input grid and anchors
52 #if defined(_OPENMP)
53  #pragma omp parallel for schedule(dynamic, 1) collapse(3)
54 #endif /* _OPENMP */
55  for(int y = 0; y < height; y++)
56  {
57  for(int x = 0; x < width; x++)
58  {
59  for(int a = 0; a < num_anchors; a++)
60  {
61  const T shift_x = T(x) * T(stride);
62  const T shift_y = T(y) * T(stride);
63  const size_t anchor_id = a + x * num_anchors + y * width * num_anchors;
64  // x1
65  all_anchors_ptr[anchor_id * 4] = anchors_ptr[4 * a] + shift_x;
66  // y1
67  all_anchors_ptr[anchor_id * 4 + 1] = anchors_ptr[4 * a + 1] + shift_y;
68  // x2
69  all_anchors_ptr[anchor_id * 4 + 2] = anchors_ptr[4 * a + 2] + shift_x;
70  // y2
71  all_anchors_ptr[anchor_id * 4 + 3] = anchors_ptr[4 * a + 3] + shift_y;
72  }
73  }
74  }
75  return all_anchors;
76 }
79 
80 template <>
82 {
83  SimpleTensor<float> anchors_tmp = convert_from_symmetric(anchors);
84  SimpleTensor<float> all_anchors_tmp = compute_all_anchors(anchors_tmp, info);
85  SimpleTensor<int16_t> all_anchors = convert_to_symmetric<int16_t>(all_anchors_tmp, anchors.quantization_info());
86  return all_anchors;
87 }
88 } // namespace reference
89 } // namespace validation
90 } // namespace test
91 } // namespace arm_compute
Shape of a tensor.
Definition: TensorShape.h:39
DataType data_type() const override
Data type of the tensor.
Definition: SimpleTensor.h:357
TensorShape shape() const override
Shape of the tensor.
Definition: SimpleTensor.h:320
float spatial_scale() const
Definition: Types.h:1389
Copyright (c) 2017-2021 Arm Limited.
Simple tensor object that stores elements in a consecutive chunk of memory.
Definition: SimpleTensor.h:58
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)
ComputeAnchors information class.
Definition: Types.h:1358
SimpleTensor< T > compute_all_anchors(const SimpleTensor< T > &anchors, const ComputeAnchorsInfo &info)
QuantizationInfo quantization_info() const override
Quantization info in case of asymmetric quantized type.
Definition: SimpleTensor.h:332
SimpleTensor< float > convert_from_symmetric(const SimpleTensor< int16_t > &src)
Definition: Helpers.cpp:147
const T * data() const
Constant pointer to the underlying buffer.
Definition: SimpleTensor.h:418