John Richardson | 25f2368 | 2017-11-27 14:35:09 +0000 | [diff] [blame] | 1 | /* |
Michele Di Giorgio | d9eaf61 | 2020-07-08 11:12:57 +0100 | [diff] [blame] | 2 | * Copyright (c) 2017, 2018 Arm Limited. |
John Richardson | 25f2368 | 2017-11-27 14:35:09 +0000 | [diff] [blame] | 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_HOG_DESCRIPTOR_DATASET |
| 25 | #define ARM_COMPUTE_TEST_HOG_DESCRIPTOR_DATASET |
| 26 | |
| 27 | #include "utils/TypePrinter.h" |
| 28 | |
| 29 | namespace arm_compute |
| 30 | { |
| 31 | namespace test |
| 32 | { |
| 33 | namespace datasets |
| 34 | { |
| 35 | class HOGDescriptorDataset |
| 36 | { |
| 37 | public: |
| 38 | using type = std::tuple<std::string, HOGInfo>; |
| 39 | |
| 40 | struct iterator |
| 41 | { |
| 42 | iterator(std::vector<std::string>::const_iterator image_it, |
| 43 | std::vector<HOGInfo>::const_iterator hog_info_it) |
| 44 | : _image_it{ std::move(image_it) }, |
| 45 | _hog_info_it{ std::move(hog_info_it) } |
| 46 | { |
| 47 | } |
| 48 | |
| 49 | std::string description() const |
| 50 | { |
| 51 | std::stringstream description; |
| 52 | description << "Image=" << *_image_it << ":"; |
| 53 | description << "HOGInfo=" << *_hog_info_it; |
| 54 | |
| 55 | return description.str(); |
| 56 | } |
| 57 | |
| 58 | HOGDescriptorDataset::type operator*() const |
| 59 | { |
| 60 | return std::make_tuple(*_image_it, *_hog_info_it); |
| 61 | } |
| 62 | |
| 63 | iterator &operator++() |
| 64 | { |
| 65 | ++_image_it; |
| 66 | ++_hog_info_it; |
| 67 | |
| 68 | return *this; |
| 69 | } |
| 70 | |
| 71 | private: |
| 72 | std::vector<std::string>::const_iterator _image_it; |
| 73 | std::vector<HOGInfo>::const_iterator _hog_info_it; |
| 74 | }; |
| 75 | |
| 76 | iterator begin() const |
| 77 | { |
| 78 | return iterator(_image.begin(), _hog_info.begin()); |
| 79 | } |
| 80 | |
| 81 | int size() const |
| 82 | { |
| 83 | return std::min(_image.size(), _hog_info.size()); |
| 84 | } |
| 85 | |
| 86 | void add_config(std::string image, |
| 87 | Size2D cell_size, Size2D block_size, Size2D detection_window_size, Size2D block_stride, |
| 88 | size_t num_bins, HOGNormType normalization_type, float l2_hyst_threshold, PhaseType phase_type) |
| 89 | { |
| 90 | _image.emplace_back(std::move(image)); |
| 91 | _hog_info.emplace_back(HOGInfo(cell_size, block_size, detection_window_size, block_stride, num_bins, normalization_type, l2_hyst_threshold, phase_type)); |
| 92 | } |
| 93 | |
| 94 | protected: |
| 95 | HOGDescriptorDataset() = default; |
| 96 | HOGDescriptorDataset(HOGDescriptorDataset &&) = default; |
| 97 | |
| 98 | private: |
| 99 | std::vector<std::string> _image{}; |
| 100 | std::vector<HOGInfo> _hog_info{}; |
| 101 | }; |
| 102 | |
| 103 | // *INDENT-OFF* |
| 104 | // clang-format off |
| 105 | class SmallHOGDescriptorDataset final : public HOGDescriptorDataset |
| 106 | { |
| 107 | public: |
| 108 | SmallHOGDescriptorDataset() |
| 109 | { |
| 110 | // image cell_size block_size detection_size block_stride bin normalization_type thresh phase_type |
| 111 | add_config("800x600.ppm", Size2D(8U, 8U), Size2D(16U, 16U), Size2D(64U, 128U), Size2D(8U, 8U), 9U, HOGNormType::L2HYS_NORM, 0.2f, PhaseType::SIGNED); |
| 112 | add_config("800x600.ppm", Size2D(8U, 8U), Size2D(16U, 16U), Size2D(64U, 128U), Size2D(8U, 8U), 9U, HOGNormType::L2HYS_NORM, 0.2f, PhaseType::UNSIGNED); |
| 113 | } |
| 114 | }; |
| 115 | |
| 116 | class LargeHOGDescriptorDataset final : public HOGDescriptorDataset |
| 117 | { |
| 118 | public: |
| 119 | LargeHOGDescriptorDataset() |
| 120 | { |
| 121 | // image cell_size block_size detection_size block_stride bin normalization_type thresh phase_type |
| 122 | add_config("1920x1080.ppm", Size2D(8U, 8U), Size2D(16U, 16U), Size2D(64U, 128U), Size2D(8U, 8U), 9U, HOGNormType::L2HYS_NORM, 0.2f, PhaseType::SIGNED); |
| 123 | add_config("1920x1080.ppm", Size2D(8U, 8U), Size2D(16U, 16U), Size2D(64U, 128U), Size2D(8U, 8U), 9U, HOGNormType::L2_NORM, 0.2f, PhaseType::SIGNED); |
| 124 | add_config("1920x1080.ppm", Size2D(8U, 8U), Size2D(16U, 16U), Size2D(64U, 128U), Size2D(8U, 8U), 9U, HOGNormType::L1_NORM, 0.2f, PhaseType::SIGNED); |
| 125 | |
| 126 | add_config("1920x1080.ppm", Size2D(8U, 8U), Size2D(16U, 16U), Size2D(64U, 128U), Size2D(8U, 8U), 9U, HOGNormType::L2HYS_NORM, 0.2f, PhaseType::UNSIGNED); |
| 127 | add_config("1920x1080.ppm", Size2D(8U, 8U), Size2D(16U, 16U), Size2D(64U, 128U), Size2D(8U, 8U), 9U, HOGNormType::L2_NORM, 0.2f, PhaseType::UNSIGNED); |
| 128 | add_config("1920x1080.ppm", Size2D(8U, 8U), Size2D(16U, 16U), Size2D(64U, 128U), Size2D(8U, 8U), 9U, HOGNormType::L1_NORM, 0.2f, PhaseType::UNSIGNED); |
| 129 | } |
| 130 | }; |
| 131 | // clang-format on |
| 132 | // *INDENT-ON* |
| 133 | |
| 134 | } // namespace datasets |
| 135 | } // namespace test |
| 136 | } // namespace arm_compute |
| 137 | #endif /* ARM_COMPUTE_TEST_HOG_DESCRIPTOR_DATASET */ |