Abe Mbise | 31bbce1 | 2017-09-19 16:19:13 +0100 | [diff] [blame] | 1 | /* |
Pablo Tello | d8b03dd | 2018-08-07 11:23:54 +0100 | [diff] [blame] | 2 | * Copyright (c) 2017-2018 ARM Limited. |
Abe Mbise | 31bbce1 | 2017-09-19 16:19:13 +0100 | [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_WARP_PERSPECTIVE_FIXTURE |
| 25 | #define ARM_COMPUTE_TEST_WARP_PERSPECTIVE_FIXTURE |
| 26 | |
| 27 | #include "arm_compute/core/TensorShape.h" |
| 28 | #include "arm_compute/core/Types.h" |
| 29 | #include "tests/AssetsLibrary.h" |
| 30 | #include "tests/Globals.h" |
| 31 | #include "tests/IAccessor.h" |
| 32 | #include "tests/framework/Asserts.h" |
| 33 | #include "tests/framework/Fixture.h" |
Georgios Pinitas | 5a7e776 | 2017-12-01 16:27:29 +0000 | [diff] [blame] | 34 | #include "tests/validation/reference/Utils.h" |
| 35 | #include "tests/validation/reference/WarpPerspective.h" |
Abe Mbise | 31bbce1 | 2017-09-19 16:19:13 +0100 | [diff] [blame] | 36 | |
| 37 | #include <random> |
| 38 | |
| 39 | namespace arm_compute |
| 40 | { |
| 41 | namespace test |
| 42 | { |
| 43 | namespace validation |
| 44 | { |
| 45 | template <typename TensorType, typename AccessorType, typename FunctionType, typename T> |
| 46 | class WarpPerspectiveValidationFixture : public framework::Fixture |
| 47 | { |
| 48 | public: |
| 49 | template <typename...> |
| 50 | void setup(TensorShape input_shape, DataType data_type, InterpolationPolicy policy, BorderMode border_mode) |
| 51 | { |
| 52 | uint8_t constant_border_value = 0; |
| 53 | // Generate a random constant value if border_mode is constant |
| 54 | if(border_mode == BorderMode::CONSTANT) |
| 55 | { |
| 56 | std::mt19937 gen(library->seed()); |
| 57 | std::uniform_int_distribution<uint8_t> distribution_u8(0, 255); |
| 58 | constant_border_value = distribution_u8(gen); |
| 59 | } |
| 60 | |
| 61 | const TensorShape vmask_shape(input_shape); |
| 62 | |
| 63 | // Create the matrix |
| 64 | std::array<float, 9> matrix = { { 0 } }; |
Pablo Tello | d616cb9 | 2017-09-27 10:07:45 +0100 | [diff] [blame] | 65 | fill_warp_matrix<9>(matrix); |
Abe Mbise | 31bbce1 | 2017-09-19 16:19:13 +0100 | [diff] [blame] | 66 | |
Pablo Tello | d8b03dd | 2018-08-07 11:23:54 +0100 | [diff] [blame] | 67 | _target = compute_target(input_shape, vmask_shape, matrix, policy, border_mode, constant_border_value, data_type); |
| 68 | _reference = compute_reference(input_shape, vmask_shape, matrix, policy, border_mode, constant_border_value, data_type); |
Abe Mbise | 31bbce1 | 2017-09-19 16:19:13 +0100 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | protected: |
| 72 | template <typename U> |
Isabella Gottardi | 764f39e | 2017-11-09 11:27:14 +0000 | [diff] [blame] | 73 | void fill(U &&tensor) |
Abe Mbise | 31bbce1 | 2017-09-19 16:19:13 +0100 | [diff] [blame] | 74 | { |
Isabella Gottardi | 764f39e | 2017-11-09 11:27:14 +0000 | [diff] [blame] | 75 | library->fill_tensor_uniform(tensor, 0); |
Abe Mbise | 31bbce1 | 2017-09-19 16:19:13 +0100 | [diff] [blame] | 76 | } |
| 77 | |
Pablo Tello | d8b03dd | 2018-08-07 11:23:54 +0100 | [diff] [blame] | 78 | TensorType compute_target(const TensorShape &shape, const TensorShape &vmask_shape, const std::array<float, 9> &matrix, InterpolationPolicy policy, BorderMode border_mode, |
| 79 | uint8_t constant_border_value, |
Abe Mbise | 31bbce1 | 2017-09-19 16:19:13 +0100 | [diff] [blame] | 80 | DataType data_type) |
| 81 | { |
| 82 | // Create tensors |
| 83 | TensorType src = create_tensor<TensorType>(shape, data_type); |
| 84 | TensorType dst = create_tensor<TensorType>(shape, data_type); |
| 85 | |
| 86 | // Create and configure function |
| 87 | FunctionType warp_perspective; |
| 88 | warp_perspective.configure(&src, &dst, matrix, policy, border_mode, constant_border_value); |
| 89 | |
| 90 | ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 91 | ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 92 | |
| 93 | // Allocate tensors |
| 94 | src.allocator()->allocate(); |
| 95 | dst.allocator()->allocate(); |
| 96 | |
| 97 | ARM_COMPUTE_EXPECT(!src.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 98 | ARM_COMPUTE_EXPECT(!dst.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 99 | |
| 100 | // Fill tensors |
| 101 | fill(AccessorType(src)); |
| 102 | |
| 103 | // Compute function |
| 104 | warp_perspective.run(); |
| 105 | |
| 106 | return dst; |
| 107 | } |
| 108 | |
Pablo Tello | d8b03dd | 2018-08-07 11:23:54 +0100 | [diff] [blame] | 109 | SimpleTensor<T> compute_reference(const TensorShape &shape, const TensorShape &vmask_shape, const std::array<float, 9> &matrix, InterpolationPolicy policy, BorderMode border_mode, |
| 110 | uint8_t constant_border_value, |
Abe Mbise | 31bbce1 | 2017-09-19 16:19:13 +0100 | [diff] [blame] | 111 | DataType data_type) |
| 112 | { |
| 113 | ARM_COMPUTE_ERROR_ON(data_type != DataType::U8); |
| 114 | |
| 115 | // Create reference |
| 116 | SimpleTensor<T> src{ shape, data_type }; |
Isabella Gottardi | 764f39e | 2017-11-09 11:27:14 +0000 | [diff] [blame] | 117 | |
| 118 | // Create the valid mask Tensor |
| 119 | _valid_mask = SimpleTensor<T>(shape, data_type); |
Abe Mbise | 31bbce1 | 2017-09-19 16:19:13 +0100 | [diff] [blame] | 120 | |
| 121 | // Fill reference |
Isabella Gottardi | 764f39e | 2017-11-09 11:27:14 +0000 | [diff] [blame] | 122 | fill(src); |
Abe Mbise | 31bbce1 | 2017-09-19 16:19:13 +0100 | [diff] [blame] | 123 | |
| 124 | // Compute reference |
Pablo Tello | d8b03dd | 2018-08-07 11:23:54 +0100 | [diff] [blame] | 125 | return reference::warp_perspective<T>(src, _valid_mask, matrix.data(), policy, border_mode, constant_border_value); |
Abe Mbise | 31bbce1 | 2017-09-19 16:19:13 +0100 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | TensorType _target{}; |
| 129 | SimpleTensor<T> _reference{}; |
| 130 | BorderMode _border_mode{}; |
Isabella Gottardi | 764f39e | 2017-11-09 11:27:14 +0000 | [diff] [blame] | 131 | SimpleTensor<T> _valid_mask{}; |
Abe Mbise | 31bbce1 | 2017-09-19 16:19:13 +0100 | [diff] [blame] | 132 | }; |
| 133 | } // namespace validation |
| 134 | } // namespace test |
| 135 | } // namespace arm_compute |
| 136 | #endif /* ARM_COMPUTE_TEST_WARP_PERSPECTIVE_FIXTURE */ |