Compute Library
 21.02
CLPyramid.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016-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  */
25 
26 #include "arm_compute/core/Error.h"
30 
31 #include <array>
32 #include <cmath>
33 
34 using namespace arm_compute;
35 
37  : _info(), _pyramid()
38 {
39 }
40 
42 {
43  internal_init(info, false);
44 }
45 
47 {
48  internal_init(info, true);
49 }
50 
51 void CLPyramid::internal_init(const PyramidInfo &info, bool auto_padding)
52 {
53  _info = info;
54  _pyramid.resize(_info.num_levels());
55 
56  size_t w = _info.width();
57  size_t h = _info.height();
58  size_t ref_w = w;
59  size_t ref_h = h;
60  const bool is_orb_scale = (SCALE_PYRAMID_ORB == _info.scale());
61  TensorShape tensor_shape = _info.tensor_shape();
62 
63  // Note: Look-up table used by the OpenVX sample implementation
64  const std::array<float, 4> c_orbscale =
65  {
66  {
67  0.5f,
70  SCALE_PYRAMID_ORB *SCALE_PYRAMID_ORB * SCALE_PYRAMID_ORB
71  }
72  };
73 
74  for(size_t i = 0; i < _info.num_levels(); ++i)
75  {
76  TensorInfo tensor_info(tensor_shape, _info.format());
77 
78  if(auto_padding)
79  {
80  tensor_info.auto_padding();
81  }
82 
83  _pyramid[i].allocator()->init(tensor_info);
84 
85  if(is_orb_scale)
86  {
87  const float orb_scale = c_orbscale[(i + 1) % 4];
88  w = std::ceil(ref_w * orb_scale);
89  h = std::ceil(ref_h * orb_scale);
90 
91  if(0 == ((i + 1) % 4))
92  {
93  ref_w = w;
94  ref_h = h;
95  }
96  }
97  else
98  {
99  w = (w + 1) * _info.scale();
100  h = (h + 1) * _info.scale();
101  }
102 
103  // Update tensor_shape
104  tensor_shape.set(0, w);
105  tensor_shape.set(1, h);
106  }
107 }
108 
110 {
111  for(size_t i = 0; i < _info.num_levels(); ++i)
112  {
113  _pyramid[i].allocator()->allocate();
114  }
115 }
116 
118 {
119  return &_info;
120 }
121 
123 {
124  ARM_COMPUTE_ERROR_ON(index >= _info.num_levels());
125 
126  return &_pyramid[index];
127 }
constexpr float SCALE_PYRAMID_ORB
Constant value used to indicate a ORB scaled pyramid.
Definition: Types.h:115
const TensorShape & tensor_shape() const
Return the TensorShape of the o-th level tensor.
Definition: PyramidInfo.cpp:92
void init_auto_padding(const PyramidInfo &info)
Initialize pyramid data-object using the given Pyramid&#39;s metadata.
Definition: CLPyramid.cpp:46
SimpleTensor< float > w
Definition: DFT.cpp:156
Shape of a tensor.
Definition: TensorShape.h:39
const PyramidInfo * info() const override
Interface to be implemented by the child class to return the Pyramid&#39;s metadata.
Definition: CLPyramid.cpp:117
Format format() const
Return the image format of all tensor in the pyramid.
Definition: PyramidInfo.cpp:97
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:466
bool auto_padding() override
Update the offset to the first element and the strides to automatically computed values.
Definition: TensorInfo.cpp:224
Copyright (c) 2017-2021 Arm Limited.
void init(const PyramidInfo &info)
Initialize pyramid data-object using the given Pyramid&#39;s metadata.
Definition: CLPyramid.cpp:41
void allocate()
Allocate the planes in the pyramid.
Definition: CLPyramid.cpp:109
CLPyramid()
Default constructor.
Definition: CLPyramid.cpp:36
float scale() const
Return the scale factor of the pyramid.
Store the Pyramid&#39;s metadata.
Definition: PyramidInfo.h:35
CLTensor * get_pyramid_level(size_t index) const override
Retrieves a level of the pyramid as a ITensor pointer.
Definition: CLPyramid.cpp:122
Store the tensor&#39;s metadata.
Definition: TensorInfo.h:45
size_t width() const
Return the width of the 0th level tensor.
Definition: PyramidInfo.cpp:82
size_t num_levels() const
Return the number of the pyramid levels.
Definition: PyramidInfo.cpp:77
size_t height() const
Return the height of the 0th level tensor.
Definition: PyramidInfo.cpp:87
TensorShape & set(size_t dimension, size_t value, bool apply_dim_correction=true, bool increase_dim_unit=true)
Accessor to set the value of one of the dimensions.
Definition: TensorShape.h:79
Basic implementation of the OpenCL tensor interface.
Definition: CLTensor.h:41