blob: 22a0d97057430df648cff641fc353d606b20b8a3 [file] [log] [blame]
Michalis Spyrou6c7c38e2018-08-29 16:28:11 +01001/*
2 * Copyright (c) 2018 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
32namespace arm_compute
33{
34namespace test
35{
36namespace datasets
37{
38class PriorBoxLayerDataset
39{
40public:
41 using type = std::tuple<TensorShape, PriorBoxLayerInfo>;
42
43 struct iterator
44 {
45 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
52 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
78 iterator begin() const
79 {
80 return iterator(_src_shapes.begin(), _infos.begin());
81 }
82
83 int size() const
84 {
85 return std::min(_src_shapes.size(), _infos.size());
86 }
87
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
94protected:
95 PriorBoxLayerDataset() = default;
96 PriorBoxLayerDataset(PriorBoxLayerDataset &&) = default;
97
98private:
99 std::vector<TensorShape> _src_shapes{};
100 std::vector<PriorBoxLayerInfo> _infos{};
101};
102
103class SmallPriorBoxLayerDataset final : public PriorBoxLayerDataset
104{
105public:
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
114 add_config(TensorShape(4U, 4U), PriorBoxLayerInfo(min_val, var, 0.5f, true, false, max_val, aspect_ratio, Coordinates2D{ 8, 8 }, steps));
115 }
116};
117
118class LargePriorBoxLayerDataset final : public PriorBoxLayerDataset
119{
120public:
121 LargePriorBoxLayerDataset()
122 {
123 std::vector<float> min_val = { 30.f };
124 std::vector<float> var = { 0.1, 0.1, 0.2, 0.2 };
125 std::vector<float> max_val = { 60.f };
126 std::vector<float> aspect_ratio = { 2.f };
127 std::array<float, 2> steps = { 8.f, 8.f };
128 add_config(TensorShape(150U, 245U, 4U, 12U), PriorBoxLayerInfo(min_val, var, 0.5f, true, false, max_val, aspect_ratio, Coordinates2D{ 8, 8 }, steps));
129 }
130};
131} // namespace datasets
132} // namespace test
133} // namespace arm_compute
134#endif /* ARM_COMPUTE_TEST_PRIORBOX_LAYER_DATASET */