John Richardson | a8fdbbb | 2018-06-06 15:34:21 +0100 | [diff] [blame] | 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_TEST_HOG_DETECTOR_FIXTURE |
| 25 | #define ARM_COMPUTE_TEST_HOG_DETECTOR_FIXTURE |
| 26 | |
| 27 | #include "arm_compute/core/TensorShape.h" |
| 28 | #include "arm_compute/core/Types.h" |
| 29 | #include "tests/Globals.h" |
| 30 | #include "tests/Utils.h" |
| 31 | #include "tests/benchmark/fixtures/HOGDescriptorFixture.h" |
| 32 | #include "tests/framework/Fixture.h" |
| 33 | |
| 34 | namespace arm_compute |
| 35 | { |
| 36 | namespace test |
| 37 | { |
| 38 | namespace benchmark |
| 39 | { |
| 40 | template <typename TensorType, |
| 41 | typename HOGType, |
| 42 | typename Function, |
| 43 | typename Accessor, |
| 44 | typename HOGAccessor, |
| 45 | typename HOGDescriptorType, |
| 46 | typename ArrayType> |
| 47 | class HOGDetectorFixture : public HOGDescriptorFixture<TensorType, HOGType, HOGDescriptorType, Accessor> |
| 48 | { |
| 49 | public: |
| 50 | template <typename...> |
| 51 | void setup(Size2D detection_window_stride, std::string image, HOGInfo hog_info, Format format, BorderMode border_mode) |
| 52 | { |
| 53 | HDF::setup(image, hog_info, format, border_mode); |
| 54 | HDF::run(); |
| 55 | |
| 56 | // Initialise descriptor (linear SVM coefficients). |
| 57 | // NOTE: Fixed values are used to keep the number of detection windows detected |
| 58 | // consistent in order to have meaningful validation tolerances. |
| 59 | // The values are "unbalanced" to reduce the number of detected objects |
| 60 | const std::random_device::result_type seed = 0; |
| 61 | std::vector<float> descriptor = generate_random_real(hog_info.descriptor_size(), -0.505f, 0.495f, seed); |
| 62 | |
| 63 | // Create HOG |
| 64 | hog = create_HOG<HOGType>(hog_info); |
| 65 | |
| 66 | // Copy HOG descriptor values to HOG memory |
| 67 | { |
| 68 | HOGAccessor hog_accessor(hog); |
| 69 | std::memcpy(hog_accessor.descriptor(), descriptor.data(), descriptor.size() * sizeof(float)); |
| 70 | } |
| 71 | |
| 72 | // Create and configure function |
| 73 | hog_detector_func.configure(&(HDF::dst), &hog, &detection_windows, detection_window_stride); |
| 74 | |
| 75 | // Reset detection windows |
| 76 | detection_windows.clear(); |
| 77 | } |
| 78 | |
| 79 | void run() |
| 80 | { |
| 81 | hog_detector_func.run(); |
| 82 | } |
| 83 | |
| 84 | void sync() |
| 85 | { |
| 86 | sync_if_necessary<TensorType>(); |
| 87 | } |
| 88 | |
| 89 | private: |
| 90 | static const unsigned int max_num_detection_windows = 100000; |
| 91 | |
| 92 | HOGType hog{}; |
| 93 | Function hog_detector_func{}; |
| 94 | ArrayType detection_windows{ max_num_detection_windows }; |
| 95 | |
| 96 | using HDF = HOGDescriptorFixture<TensorType, HOGType, HOGDescriptorType, Accessor>; |
| 97 | }; |
| 98 | } // namespace benchmark |
| 99 | } // namespace test |
| 100 | } // namespace arm_compute |
| 101 | #endif /* ARM_COMPUTE_TEST_HOG_DETECTOR_FIXTURE */ |