xref: /aosp_15_r20/external/ComputeLibrary/tests/datasets/PriorBoxLayerDataset.h (revision c217d954acce2dbc11938adb493fc0abd69584f3)
1 /*
2  * Copyright (c) 2018-2019 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 #ifndef ARM_COMPUTE_TEST_PRIORBOX_LAYER_DATASET
25 #define ARM_COMPUTE_TEST_PRIORBOX_LAYER_DATASET
26 
27 #include "utils/TypePrinter.h"
28 
29 #include "arm_compute/core/TensorShape.h"
30 #include "arm_compute/core/Types.h"
31 
32 namespace arm_compute
33 {
34 namespace test
35 {
36 namespace datasets
37 {
38 class PriorBoxLayerDataset
39 {
40 public:
41     using type = std::tuple<TensorShape, PriorBoxLayerInfo>;
42 
43     struct iterator
44     {
iteratoriterator45         iterator(std::vector<TensorShape>::const_iterator       src_it,
46                  std::vector<PriorBoxLayerInfo>::const_iterator infos_it)
47             : _src_it{ std::move(src_it) },
48               _infos_it{ std::move(infos_it) }
49         {
50         }
51 
descriptioniterator52         std::string description() const
53         {
54             std::stringstream description;
55             description << "In=" << *_src_it << ":";
56             description << "Info=" << *_infos_it << ":";
57             return description.str();
58         }
59 
60         PriorBoxLayerDataset::type operator*() const
61         {
62             return std::make_tuple(*_src_it, *_infos_it);
63         }
64 
65         iterator &operator++()
66         {
67             ++_src_it;
68             ++_infos_it;
69 
70             return *this;
71         }
72 
73     private:
74         std::vector<TensorShape>::const_iterator       _src_it;
75         std::vector<PriorBoxLayerInfo>::const_iterator _infos_it;
76     };
77 
begin()78     iterator begin() const
79     {
80         return iterator(_src_shapes.begin(), _infos.begin());
81     }
82 
size()83     int size() const
84     {
85         return std::min(_src_shapes.size(), _infos.size());
86     }
87 
add_config(TensorShape src,PriorBoxLayerInfo info)88     void add_config(TensorShape src, PriorBoxLayerInfo info)
89     {
90         _src_shapes.emplace_back(std::move(src));
91         _infos.emplace_back(std::move(info));
92     }
93 
94 protected:
95     PriorBoxLayerDataset()                        = default;
96     PriorBoxLayerDataset(PriorBoxLayerDataset &&) = default;
97 
98 private:
99     std::vector<TensorShape>       _src_shapes{};
100     std::vector<PriorBoxLayerInfo> _infos{};
101 };
102 
103 class SmallPriorBoxLayerDataset final : public PriorBoxLayerDataset
104 {
105 public:
SmallPriorBoxLayerDataset()106     SmallPriorBoxLayerDataset()
107     {
108         std::vector<float> min_val      = { 30.f };
109         std::vector<float> var          = { 0.1, 0.1, 0.2, 0.2 };
110         std::vector<float> max_val      = { 60.f };
111         std::vector<float> aspect_ratio = { 2.f };
112         std::array<float, 2> steps = { { 8.f, 8.f } };
113         add_config(TensorShape(4U, 4U), PriorBoxLayerInfo(min_val, var, 0.5f, true, false, max_val, aspect_ratio, Coordinates2D{ 8, 8 }, steps));
114     }
115 };
116 
117 class LargePriorBoxLayerDataset final : public PriorBoxLayerDataset
118 {
119 public:
LargePriorBoxLayerDataset()120     LargePriorBoxLayerDataset()
121     {
122         std::vector<float> min_val      = { 30.f };
123         std::vector<float> var          = { 0.1, 0.1, 0.2, 0.2 };
124         std::vector<float> max_val      = { 60.f };
125         std::vector<float> aspect_ratio = { 2.f };
126         std::array<float, 2> steps = { { 8.f, 8.f } };
127         add_config(TensorShape(150U, 245U, 4U, 12U), PriorBoxLayerInfo(min_val, var, 0.5f, true, false, max_val, aspect_ratio, Coordinates2D{ 8, 8 }, steps));
128     }
129 };
130 } // namespace datasets
131 } // namespace test
132 } // namespace arm_compute
133 #endif /* ARM_COMPUTE_TEST_PRIORBOX_LAYER_DATASET */
134