xref: /aosp_15_r20/external/ComputeLibrary/tests/datasets/HOGMultiDetectionDataset.h (revision c217d954acce2dbc11938adb493fc0abd69584f3)
1 /*
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_HOG_MULTI_DETECTION_DATASET
25 #define ARM_COMPUTE_HOG_MULTI_DETECTION_DATASET
26 
27 #include "arm_compute/core/HOGInfo.h"
28 #include "tests/framework/datasets/Datasets.h"
29 
30 namespace arm_compute
31 {
32 namespace test
33 {
34 namespace datasets
35 {
36 class HOGMultiDetectionDataset
37 {
38 public:
39     using type = std::tuple<std::string, std::vector<HOGInfo>>;
40 
41     struct iterator
42     {
iteratoriterator43         iterator(std::vector<std::string>::const_iterator          image_it,
44                  std::vector<std::string>::const_iterator          hog_infos_name_it,
45                  std::vector<std::vector<HOGInfo>>::const_iterator hog_infos_it)
46             : _image_it{ std::move(image_it) },
47               _hog_infos_name_it{ std::move(hog_infos_name_it) },
48               _hog_infos_it{ std::move(hog_infos_it) }
49         {
50         }
51 
descriptioniterator52         std::string description() const
53         {
54             std::stringstream description;
55             description << "Image=" << *_image_it << ":";
56             description << "HOGInfoSet=" << *_hog_infos_name_it;
57 
58             return description.str();
59         }
60 
61         HOGMultiDetectionDataset::type operator*() const
62         {
63             return std::make_tuple(*_image_it, *_hog_infos_it);
64         }
65 
66         iterator &operator++()
67         {
68             ++_image_it;
69             ++_hog_infos_name_it;
70             ++_hog_infos_it;
71 
72             return *this;
73         }
74 
75     private:
76         std::vector<std::string>::const_iterator          _image_it;
77         std::vector<std::string>::const_iterator          _hog_infos_name_it;
78         std::vector<std::vector<HOGInfo>>::const_iterator _hog_infos_it;
79     };
80 
begin()81     iterator begin() const
82     {
83         return iterator(_image.begin(), _hog_infos_name.begin(), _hog_infos.begin());
84     }
85 
size()86     int size() const
87     {
88         return std::min(_image.size(), _hog_infos.size());
89     }
90 
add_config(std::string image,std::string hog_infos_name,std::vector<HOGInfo> hog_info_vec)91     void add_config(std::string          image,
92                     std::string          hog_infos_name,
93                     std::vector<HOGInfo> hog_info_vec)
94     {
95         _image.emplace_back(std::move(image));
96         _hog_infos_name.emplace_back(std::move(hog_infos_name));
97         _hog_infos.emplace_back(hog_info_vec);
98     }
99 
100 protected:
101     HOGMultiDetectionDataset()                            = default;
102     HOGMultiDetectionDataset(HOGMultiDetectionDataset &&) = default;
103 
104 private:
105     std::vector<std::string>          _image{};
106     std::vector<std::string>          _hog_infos_name{};
107     std::vector<std::vector<HOGInfo>> _hog_infos{};
108 };
109 
110 using MultiHOGDataset = std::vector<HOGInfo>;
111 
112 // *INDENT-OFF*
113 // clang-format off
114 static const MultiHOGDataset mixed
115 {
116     //      cell_size         block_size        detection_size      block_stride      bin normalization_type    thresh phase_type
117     HOGInfo(Size2D(8U, 8U),   Size2D(16U, 16U), Size2D(64U, 128U),  Size2D(8U, 8U),   3U, HOGNormType::L1_NORM, 0.2f,  PhaseType::SIGNED),
118     HOGInfo(Size2D(8U, 8U),   Size2D(16U, 16U), Size2D(128U, 256U), Size2D(8U, 8U),   5U, HOGNormType::L1_NORM, 0.3f,  PhaseType::SIGNED),
119     HOGInfo(Size2D(16U, 16U), Size2D(32U, 32U), Size2D(64U, 128U),  Size2D(32U, 32U), 7U, HOGNormType::L1_NORM, 0.4f,  PhaseType::SIGNED),
120     HOGInfo(Size2D(16U, 16U), Size2D(32U, 32U), Size2D(128U, 256U), Size2D(32U, 32U), 9U, HOGNormType::L1_NORM, 0.5f,  PhaseType::SIGNED),
121 };
122 
123 // cell_size and bin_size fixed
124 static const MultiHOGDataset skip_binning
125 {
126     //      cell_size       block_size        detection_size      block_stride      bin normalization_type       thresh phase_type
127     HOGInfo(Size2D(8U, 8U), Size2D(16U, 16U), Size2D(64U, 128U),  Size2D(8U, 8U),   9U, HOGNormType::L2HYS_NORM, 0.2f,  PhaseType::SIGNED),
128     HOGInfo(Size2D(8U, 8U), Size2D(16U, 16U), Size2D(128U, 256U), Size2D(8U, 8U),   9U, HOGNormType::L2HYS_NORM, 0.2f,  PhaseType::SIGNED),
129     HOGInfo(Size2D(8U, 8U), Size2D(32U, 32U), Size2D(64U, 128U),  Size2D(16U, 16U), 9U, HOGNormType::L2HYS_NORM, 0.2f,  PhaseType::SIGNED),
130     HOGInfo(Size2D(8U, 8U), Size2D(32U, 32U), Size2D(128U, 256U), Size2D(16U, 16U), 9U, HOGNormType::L2HYS_NORM, 0.2f,  PhaseType::SIGNED),
131 };
132 
133 // cell_size and bin_size and block_size and block_stride fixed
134 static const MultiHOGDataset skip_normalization
135 {
136     //      cell_size       block_size        detection_size      block_stride    bin normalization_type    thresh phase_type
137     HOGInfo(Size2D(8U, 8U), Size2D(16U, 16U), Size2D(64U, 128U),  Size2D(8U, 8U), 9U, HOGNormType::L2_NORM, 0.2f,  PhaseType::SIGNED),
138     HOGInfo(Size2D(8U, 8U), Size2D(16U, 16U), Size2D(128U, 256U), Size2D(8U, 8U), 9U, HOGNormType::L2_NORM, 0.3f,  PhaseType::SIGNED),
139     HOGInfo(Size2D(8U, 8U), Size2D(16U, 16U), Size2D(64U, 128U),  Size2D(8U, 8U), 9U, HOGNormType::L2_NORM, 0.4f,  PhaseType::SIGNED),
140     HOGInfo(Size2D(8U, 8U), Size2D(16U, 16U), Size2D(128U, 256U), Size2D(8U, 8U), 9U, HOGNormType::L2_NORM, 0.5f,  PhaseType::SIGNED),
141 };
142 // clang-format on
143 // *INDENT-ON*
144 
145 class SmallHOGMultiDetectionDataset final : public HOGMultiDetectionDataset
146 {
147 public:
SmallHOGMultiDetectionDataset()148     SmallHOGMultiDetectionDataset()
149     {
150         add_config("800x600.ppm", "MIXED", mixed);
151         add_config("800x600.ppm", "SKIP_BINNING", skip_binning);
152         add_config("800x600.ppm", "SKIP_NORMALIZATION", skip_normalization);
153     }
154 };
155 
156 class LargeHOGMultiDetectionDataset final : public HOGMultiDetectionDataset
157 {
158 public:
LargeHOGMultiDetectionDataset()159     LargeHOGMultiDetectionDataset()
160     {
161         add_config("1920x1080.ppm", "MIXED", mixed);
162         add_config("1920x1080.ppm", "SKIP_BINNING", skip_binning);
163         add_config("1920x1080.ppm", "SKIP_NORMALIZATION", skip_normalization);
164     }
165 };
166 
167 } // namespace datasets
168 } // namespace test
169 } // namespace arm_compute
170 #endif /* ARM_COMPUTE_HOG_MULTI_DETECTION_DATASET */
171