blob: 0eba97c47cd5b14dc6a362b47acaf13e1c8208c2 [file] [log] [blame]
Abe Mbise31bbce12017-09-19 16:19:13 +01001/*
Pablo Tellod8b03dd2018-08-07 11:23:54 +01002 * Copyright (c) 2017-2018 ARM Limited.
Abe Mbise31bbce12017-09-19 16:19:13 +01003 *
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 Pinitas5a7e7762017-12-01 16:27:29 +000034#include "tests/validation/reference/Utils.h"
35#include "tests/validation/reference/WarpPerspective.h"
Abe Mbise31bbce12017-09-19 16:19:13 +010036
37#include <random>
38
39namespace arm_compute
40{
41namespace test
42{
43namespace validation
44{
45template <typename TensorType, typename AccessorType, typename FunctionType, typename T>
46class WarpPerspectiveValidationFixture : public framework::Fixture
47{
48public:
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 Tellod616cb92017-09-27 10:07:45 +010065 fill_warp_matrix<9>(matrix);
Abe Mbise31bbce12017-09-19 16:19:13 +010066
Pablo Tellod8b03dd2018-08-07 11:23:54 +010067 _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 Mbise31bbce12017-09-19 16:19:13 +010069 }
70
71protected:
72 template <typename U>
Isabella Gottardi764f39e2017-11-09 11:27:14 +000073 void fill(U &&tensor)
Abe Mbise31bbce12017-09-19 16:19:13 +010074 {
Isabella Gottardi764f39e2017-11-09 11:27:14 +000075 library->fill_tensor_uniform(tensor, 0);
Abe Mbise31bbce12017-09-19 16:19:13 +010076 }
77
Pablo Tellod8b03dd2018-08-07 11:23:54 +010078 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 Mbise31bbce12017-09-19 16:19:13 +010080 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 Tellod8b03dd2018-08-07 11:23:54 +0100109 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 Mbise31bbce12017-09-19 16:19:13 +0100111 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 Gottardi764f39e2017-11-09 11:27:14 +0000117
118 // Create the valid mask Tensor
119 _valid_mask = SimpleTensor<T>(shape, data_type);
Abe Mbise31bbce12017-09-19 16:19:13 +0100120
121 // Fill reference
Isabella Gottardi764f39e2017-11-09 11:27:14 +0000122 fill(src);
Abe Mbise31bbce12017-09-19 16:19:13 +0100123
124 // Compute reference
Pablo Tellod8b03dd2018-08-07 11:23:54 +0100125 return reference::warp_perspective<T>(src, _valid_mask, matrix.data(), policy, border_mode, constant_border_value);
Abe Mbise31bbce12017-09-19 16:19:13 +0100126 }
127
128 TensorType _target{};
129 SimpleTensor<T> _reference{};
130 BorderMode _border_mode{};
Isabella Gottardi764f39e2017-11-09 11:27:14 +0000131 SimpleTensor<T> _valid_mask{};
Abe Mbise31bbce12017-09-19 16:19:13 +0100132};
133} // namespace validation
134} // namespace test
135} // namespace arm_compute
136#endif /* ARM_COMPUTE_TEST_WARP_PERSPECTIVE_FIXTURE */