Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2017 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 | #include "ReferenceCPP.h" |
| 25 | |
| 26 | #include "TensorFactory.h" |
| 27 | #include "TensorOperations.h" |
| 28 | #include "TensorVisitors.h" |
| 29 | #include "TypePrinter.h" |
| 30 | |
| 31 | #include "arm_compute/core/Coordinates.h" |
| 32 | #include "arm_compute/core/Error.h" |
| 33 | #include "arm_compute/core/TensorInfo.h" |
| 34 | #include "arm_compute/core/TensorShape.h" |
| 35 | #include "arm_compute/runtime/Tensor.h" |
| 36 | |
| 37 | #include "boost_wrapper.h" |
| 38 | |
Georgios Pinitas | ac4e873 | 2017-07-05 17:02:25 +0100 | [diff] [blame] | 39 | #include <algorithm> |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 40 | #include <functional> |
Georgios Pinitas | ac4e873 | 2017-07-05 17:02:25 +0100 | [diff] [blame] | 41 | #include <memory> |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 42 | #include <numeric> |
| 43 | #include <vector> |
| 44 | |
| 45 | using namespace arm_compute::test::validation::tensor_visitors; |
| 46 | |
| 47 | namespace arm_compute |
| 48 | { |
| 49 | namespace test |
| 50 | { |
| 51 | namespace validation |
| 52 | { |
Giorgio Arena | 50f9fd7 | 2017-06-19 17:05:30 +0100 | [diff] [blame] | 53 | // Sobel 3x3 |
| 54 | void ReferenceCPP::sobel_3x3(RawTensor &src, RawTensor &dst_x, RawTensor &dst_y, BorderMode border_mode, uint8_t constant_border_value) |
| 55 | { |
| 56 | ARM_COMPUTE_ERROR_ON(src.data_type() != DataType::U8 || dst_x.data_type() != DataType::S16 || dst_y.data_type() != DataType::S16); |
| 57 | Tensor<uint8_t> s(src.shape(), src.data_type(), src.fixed_point_position(), reinterpret_cast<const uint8_t *>(src.data())); |
| 58 | Tensor<int16_t> dx(dst_x.shape(), dst_x.data_type(), dst_x.fixed_point_position(), reinterpret_cast<int16_t *>(dst_x.data())); |
| 59 | Tensor<int16_t> dy(dst_y.shape(), dst_y.data_type(), dst_y.fixed_point_position(), reinterpret_cast<int16_t *>(dst_y.data())); |
| 60 | tensor_operations::sobel_3x3(s, dx, dy, border_mode, constant_border_value); |
| 61 | } |
| 62 | |
| 63 | // Sobel 5x5 |
| 64 | void ReferenceCPP::sobel_5x5(RawTensor &src, RawTensor &dst_x, RawTensor &dst_y, BorderMode border_mode, uint8_t constant_border_value) |
| 65 | { |
| 66 | ARM_COMPUTE_ERROR_ON(src.data_type() != DataType::U8 || dst_x.data_type() != DataType::S16 || dst_y.data_type() != DataType::S16); |
| 67 | Tensor<uint8_t> s(src.shape(), src.data_type(), src.fixed_point_position(), reinterpret_cast<const uint8_t *>(src.data())); |
| 68 | Tensor<int16_t> dx(dst_x.shape(), dst_x.data_type(), dst_x.fixed_point_position(), reinterpret_cast<int16_t *>(dst_x.data())); |
| 69 | Tensor<int16_t> dy(dst_y.shape(), dst_y.data_type(), dst_y.fixed_point_position(), reinterpret_cast<int16_t *>(dst_y.data())); |
| 70 | tensor_operations::sobel_5x5(s, dx, dy, border_mode, constant_border_value); |
| 71 | } |
| 72 | |
Giorgio Arena | fc2817d | 2017-06-27 17:26:37 +0100 | [diff] [blame] | 73 | // Harris corners |
| 74 | void ReferenceCPP::harris_corners(RawTensor &src, RawTensor &Gx, RawTensor &Gy, const RawTensor &candidates, const RawTensor &non_maxima, float threshold, float min_dist, float sensitivity, |
| 75 | int32_t gradient_size, int32_t block_size, KeyPointArray &corners, BorderMode border_mode, uint8_t constant_border_value) |
| 76 | { |
| 77 | ARM_COMPUTE_ERROR_ON(src.data_type() != DataType::U8 || (Gx.data_type() != DataType::S16 && Gx.data_type() != DataType::S32) || (Gy.data_type() != DataType::S16 && Gy.data_type() != DataType::S32) |
| 78 | || candidates.data_type() != DataType::F32 || non_maxima.data_type() != DataType::F32); |
| 79 | |
| 80 | Tensor<uint8_t> s(src.shape(), src.data_type(), src.fixed_point_position(), reinterpret_cast<const uint8_t *>(src.data())); |
| 81 | Tensor<float> c(candidates.shape(), candidates.data_type(), candidates.fixed_point_position(), const_cast<float *>(reinterpret_cast<const float *>(candidates.data()))); // NOLINT |
| 82 | Tensor<float> nm(non_maxima.shape(), non_maxima.data_type(), non_maxima.fixed_point_position(), const_cast<float *>(reinterpret_cast<const float *>(non_maxima.data()))); // NOLINT |
| 83 | |
| 84 | if(gradient_size == 7) |
| 85 | { |
| 86 | Tensor<int32_t> gx(Gx.shape(), Gx.data_type(), Gx.fixed_point_position(), reinterpret_cast<int32_t *>(Gx.data())); |
| 87 | Tensor<int32_t> gy(Gy.shape(), Gy.data_type(), Gy.fixed_point_position(), reinterpret_cast<int32_t *>(Gy.data())); |
| 88 | tensor_operations::harris_corners(s, gx, gy, c, nm, threshold, min_dist, sensitivity, gradient_size, block_size, corners, border_mode, constant_border_value); |
| 89 | } |
| 90 | else |
| 91 | { |
| 92 | Tensor<int16_t> gx(Gx.shape(), Gx.data_type(), Gx.fixed_point_position(), reinterpret_cast<int16_t *>(Gx.data())); |
| 93 | Tensor<int16_t> gy(Gy.shape(), Gy.data_type(), Gy.fixed_point_position(), reinterpret_cast<int16_t *>(Gy.data())); |
| 94 | tensor_operations::harris_corners(s, gx, gy, c, nm, threshold, min_dist, sensitivity, gradient_size, block_size, corners, border_mode, constant_border_value); |
| 95 | } |
| 96 | } |
| 97 | |
Giorgio Arena | 2ca209e | 2017-06-13 15:49:37 +0100 | [diff] [blame] | 98 | // Minimum maximum location |
Michele Di Giorgio | ef4b4ae | 2017-07-04 17:19:43 +0100 | [diff] [blame] | 99 | void ReferenceCPP::min_max_location(const RawTensor &src, void *min, void *max, IArray<Coordinates2D> &min_loc, IArray<Coordinates2D> &max_loc, uint32_t &min_count, uint32_t &max_count) |
Giorgio Arena | 2ca209e | 2017-06-13 15:49:37 +0100 | [diff] [blame] | 100 | { |
| 101 | const TensorVariant s = TensorFactory::get_tensor(src); |
| 102 | boost::apply_visitor(tensor_visitors::min_max_location_visitor(min, max, min_loc, max_loc, min_count, max_count), s); |
| 103 | } |
| 104 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 105 | // Absolute difference |
| 106 | void ReferenceCPP::absolute_difference(const RawTensor &src1, const RawTensor &src2, RawTensor &dst) |
| 107 | { |
| 108 | const TensorVariant s1 = TensorFactory::get_tensor(src1); |
| 109 | const TensorVariant s2 = TensorFactory::get_tensor(src2); |
| 110 | TensorVariant d = TensorFactory::get_tensor(dst); |
| 111 | boost::apply_visitor(absolute_difference_visitor(), s1, s2, d); |
| 112 | } |
Giorgio Arena | f795986 | 2017-06-13 15:19:51 +0100 | [diff] [blame] | 113 | |
| 114 | // Mean and standard deviation |
| 115 | void ReferenceCPP::mean_and_standard_deviation(const RawTensor &src, float &mean, float &std_dev) |
| 116 | { |
| 117 | ARM_COMPUTE_ERROR_ON(src.data_type() != DataType::U8); |
| 118 | const Tensor<uint8_t> s(src.shape(), src.data_type(), src.fixed_point_position(), reinterpret_cast<const uint8_t *>(src.data())); |
| 119 | tensor_operations::mean_and_standard_deviation(s, mean, std_dev); |
| 120 | } |
| 121 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 122 | // Integral image |
| 123 | void ReferenceCPP::integral_image(const RawTensor &src, RawTensor &dst) |
| 124 | { |
| 125 | ARM_COMPUTE_ERROR_ON(src.data_type() != DataType::U8 || dst.data_type() != DataType::U32); |
| 126 | const Tensor<uint8_t> s(src.shape(), src.data_type(), src.fixed_point_position(), reinterpret_cast<const uint8_t *>(src.data())); |
| 127 | Tensor<uint32_t> d(dst.shape(), dst.data_type(), dst.fixed_point_position(), reinterpret_cast<uint32_t *>(dst.data())); |
| 128 | tensor_operations::integral_image(s, d); |
| 129 | } |
Giorgio Arena | f795986 | 2017-06-13 15:19:51 +0100 | [diff] [blame] | 130 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 131 | // Accumulate |
| 132 | void ReferenceCPP::accumulate(const RawTensor &src, RawTensor &dst) |
| 133 | { |
| 134 | ARM_COMPUTE_ERROR_ON(src.data_type() != DataType::U8 || dst.data_type() != DataType::S16); |
| 135 | const Tensor<uint8_t> s(src.shape(), src.data_type(), src.fixed_point_position(), reinterpret_cast<const uint8_t *>(src.data())); |
| 136 | Tensor<int16_t> d(dst.shape(), dst.data_type(), dst.fixed_point_position(), reinterpret_cast<int16_t *>(dst.data())); |
| 137 | tensor_operations::accumulate(s, d); |
| 138 | } |
| 139 | |
| 140 | // Accumulate squared |
| 141 | void ReferenceCPP::accumulate_squared(const RawTensor &src, RawTensor &dst, uint32_t shift) |
| 142 | { |
| 143 | ARM_COMPUTE_ERROR_ON(src.data_type() != DataType::U8 || dst.data_type() != DataType::S16); |
| 144 | const Tensor<uint8_t> s(src.shape(), src.data_type(), src.fixed_point_position(), reinterpret_cast<const uint8_t *>(src.data())); |
| 145 | Tensor<int16_t> d(dst.shape(), dst.data_type(), dst.fixed_point_position(), reinterpret_cast<int16_t *>(dst.data())); |
| 146 | tensor_operations::accumulate_squared(s, d, shift); |
| 147 | } |
| 148 | |
| 149 | // Accumulate weighted |
| 150 | void ReferenceCPP::accumulate_weighted(const RawTensor &src, RawTensor &dst, float alpha) |
| 151 | { |
| 152 | ARM_COMPUTE_ERROR_ON(src.data_type() != DataType::U8 || dst.data_type() != DataType::U8); |
| 153 | const Tensor<uint8_t> s(src.shape(), src.data_type(), src.fixed_point_position(), reinterpret_cast<const uint8_t *>(src.data())); |
| 154 | Tensor<uint8_t> d(dst.shape(), dst.data_type(), dst.fixed_point_position(), reinterpret_cast<uint8_t *>(dst.data())); |
| 155 | tensor_operations::accumulate_weighted(s, d, alpha); |
| 156 | } |
| 157 | |
| 158 | // Arithmetic addition |
| 159 | void ReferenceCPP::arithmetic_addition(const RawTensor &src1, const RawTensor &src2, RawTensor &dst, ConvertPolicy convert_policy) |
| 160 | { |
| 161 | const TensorVariant s1 = TensorFactory::get_tensor(src1); |
| 162 | const TensorVariant s2 = TensorFactory::get_tensor(src2); |
| 163 | TensorVariant d = TensorFactory::get_tensor(dst); |
| 164 | boost::apply_visitor(arithmetic_addition_visitor(convert_policy), s1, s2, d); |
| 165 | } |
| 166 | |
| 167 | // Arithmetic subtraction |
| 168 | void ReferenceCPP::arithmetic_subtraction(const RawTensor &src1, const RawTensor &src2, RawTensor &dst, ConvertPolicy convert_policy) |
| 169 | { |
| 170 | const TensorVariant s1 = TensorFactory::get_tensor(src1); |
| 171 | const TensorVariant s2 = TensorFactory::get_tensor(src2); |
| 172 | TensorVariant d = TensorFactory::get_tensor(dst); |
| 173 | boost::apply_visitor(arithmetic_subtraction_visitor(convert_policy), s1, s2, d); |
| 174 | } |
| 175 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 176 | // Bitwise not |
| 177 | void ReferenceCPP::bitwise_not(const RawTensor &src, RawTensor &dst) |
| 178 | { |
| 179 | ARM_COMPUTE_ERROR_ON(src.data_type() != DataType::U8 || dst.data_type() != DataType::U8); |
| 180 | const Tensor<uint8_t> s(src.shape(), src.data_type(), src.fixed_point_position(), reinterpret_cast<const uint8_t *>(src.data())); |
| 181 | Tensor<uint8_t> d(dst.shape(), dst.data_type(), dst.fixed_point_position(), reinterpret_cast<uint8_t *>(dst.data())); |
| 182 | tensor_operations::bitwise_not(s, d); |
| 183 | } |
| 184 | |
SiCong Li | bacaf9a | 2017-06-19 13:41:45 +0100 | [diff] [blame] | 185 | // Box3x3 filter |
| 186 | void ReferenceCPP::box3x3(const RawTensor &src, RawTensor &dst, BorderMode border_mode, uint8_t constant_border_value) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 187 | { |
| 188 | ARM_COMPUTE_ERROR_ON(src.data_type() != DataType::U8 || dst.data_type() != DataType::U8); |
| 189 | const Tensor<uint8_t> s(src.shape(), src.data_type(), src.fixed_point_position(), reinterpret_cast<const uint8_t *>(src.data())); |
| 190 | Tensor<uint8_t> d(dst.shape(), dst.data_type(), dst.fixed_point_position(), reinterpret_cast<uint8_t *>(dst.data())); |
SiCong Li | bacaf9a | 2017-06-19 13:41:45 +0100 | [diff] [blame] | 191 | tensor_operations::box3x3(s, d, border_mode, constant_border_value); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 192 | } |
| 193 | |
| 194 | // Depth conversion |
| 195 | void ReferenceCPP::depth_convert(const RawTensor &src, RawTensor &dst, ConvertPolicy policy, uint32_t shift) |
| 196 | { |
| 197 | const TensorVariant s = TensorFactory::get_tensor(src); |
| 198 | TensorVariant d = TensorFactory::get_tensor(dst); |
| 199 | boost::apply_visitor(tensor_visitors::depth_convert_visitor(policy, shift), s, d); |
| 200 | } |
| 201 | |
SiCong Li | 5a53664 | 2017-06-19 14:47:05 +0100 | [diff] [blame] | 202 | // Gaussian3x3 filter |
| 203 | void ReferenceCPP::gaussian3x3(const RawTensor &src, RawTensor &dst, BorderMode border_mode, uint8_t constant_border_value) |
| 204 | { |
| 205 | ARM_COMPUTE_ERROR_ON(src.data_type() != DataType::U8 || dst.data_type() != DataType::U8); |
| 206 | const Tensor<uint8_t> s(src.shape(), src.data_type(), src.fixed_point_position(), reinterpret_cast<const uint8_t *>(src.data())); |
| 207 | Tensor<uint8_t> d(dst.shape(), dst.data_type(), dst.fixed_point_position(), reinterpret_cast<uint8_t *>(dst.data())); |
| 208 | tensor_operations::gaussian3x3(s, d, border_mode, constant_border_value); |
| 209 | } |
| 210 | |
SiCong Li | 3eb263e | 2017-06-19 15:31:43 +0100 | [diff] [blame] | 211 | // Gaussian5x5 filter |
| 212 | void ReferenceCPP::gaussian5x5(const RawTensor &src, RawTensor &dst, BorderMode border_mode, uint8_t constant_border_value) |
| 213 | { |
| 214 | ARM_COMPUTE_ERROR_ON(src.data_type() != DataType::U8 || dst.data_type() != DataType::U8); |
| 215 | const Tensor<uint8_t> s(src.shape(), src.data_type(), src.fixed_point_position(), reinterpret_cast<const uint8_t *>(src.data())); |
| 216 | Tensor<uint8_t> d(dst.shape(), dst.data_type(), dst.fixed_point_position(), reinterpret_cast<uint8_t *>(dst.data())); |
| 217 | tensor_operations::gaussian5x5(s, d, border_mode, constant_border_value); |
| 218 | } |
| 219 | |
Isabella Gottardi | 3b77e9d | 2017-06-22 11:05:41 +0100 | [diff] [blame] | 220 | // Non linear filter |
| 221 | void ReferenceCPP::non_linear_filter(const RawTensor &src, RawTensor &dst, NonLinearFilterFunction function, unsigned int mask_size, |
| 222 | MatrixPattern pattern, const uint8_t *mask, BorderMode border_mode, uint8_t constant_border_value) |
| 223 | { |
| 224 | ARM_COMPUTE_ERROR_ON(src.data_type() != DataType::U8 || dst.data_type() != DataType::U8); |
| 225 | const Tensor<uint8_t> s(src.shape(), src.data_type(), src.fixed_point_position(), reinterpret_cast<const uint8_t *>(src.data())); |
| 226 | Tensor<uint8_t> d(dst.shape(), dst.data_type(), dst.fixed_point_position(), reinterpret_cast<uint8_t *>(dst.data())); |
| 227 | tensor_operations::non_linear_filter(s, d, function, mask_size, pattern, mask, border_mode, constant_border_value); |
| 228 | } |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 229 | |
| 230 | // Pixel-wise multiplication |
| 231 | void ReferenceCPP::pixel_wise_multiplication(const RawTensor &src1, const RawTensor &src2, RawTensor &dst, float scale, ConvertPolicy convert_policy, RoundingPolicy rounding_policy) |
| 232 | { |
| 233 | const TensorVariant s1 = TensorFactory::get_tensor(src1); |
| 234 | const TensorVariant s2 = TensorFactory::get_tensor(src2); |
| 235 | TensorVariant d = TensorFactory::get_tensor(dst); |
| 236 | boost::apply_visitor(pixel_wise_multiplication_visitor(scale, convert_policy, rounding_policy), s1, s2, d); |
| 237 | } |
| 238 | |
| 239 | // Fixed-point Pixel-wise multiplication |
| 240 | void ReferenceCPP::fixed_point_pixel_wise_multiplication(const RawTensor &src1, const RawTensor &src2, RawTensor &dst, float scale, ConvertPolicy convert_policy, RoundingPolicy rounding_policy) |
| 241 | { |
| 242 | const TensorVariant s1 = TensorFactory::get_tensor(src1); |
| 243 | const TensorVariant s2 = TensorFactory::get_tensor(src2); |
| 244 | TensorVariant d = TensorFactory::get_tensor(dst); |
| 245 | boost::apply_visitor(tensor_visitors::fixed_point_pixel_wise_multiplication_visitor(s1, s2, scale, convert_policy, rounding_policy), d); |
| 246 | } |
| 247 | |
Isabella Gottardi | b797fa2 | 2017-06-23 15:02:11 +0100 | [diff] [blame] | 248 | // Table lookup |
| 249 | template <typename T> |
| 250 | void ReferenceCPP::table_lookup(const RawTensor &src, RawTensor &dst, std::map<T, T> &lut) |
| 251 | { |
| 252 | const TensorVariant s = TensorFactory::get_tensor(src); |
| 253 | TensorVariant d = TensorFactory::get_tensor(dst); |
| 254 | boost::apply_visitor(tensor_visitors::table_lookup<T>(s, lut), d); |
| 255 | } |
| 256 | #ifndef DOXYGEN_SKIP_THIS |
| 257 | template void arm_compute::test::validation::ReferenceCPP::table_lookup<uint8_t>(const RawTensor &src, RawTensor &dst, std::map<uint8_t, uint8_t> &lut); |
| 258 | template void arm_compute::test::validation::ReferenceCPP::table_lookup<int16_t>(const RawTensor &src, RawTensor &dst, std::map<int16_t, int16_t> &lut); |
| 259 | #endif /* DOXYGEN_SKIP_THIS */ |
| 260 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 261 | // Threshold |
| 262 | void ReferenceCPP::threshold(const RawTensor &src, RawTensor &dst, uint8_t threshold, uint8_t false_value, uint8_t true_value, ThresholdType type, uint8_t upper) |
| 263 | { |
| 264 | ARM_COMPUTE_ERROR_ON(src.data_type() != DataType::U8 || dst.data_type() != DataType::U8); |
| 265 | const Tensor<uint8_t> s(src.shape(), src.data_type(), src.fixed_point_position(), reinterpret_cast<const uint8_t *>(src.data())); |
| 266 | Tensor<uint8_t> d(dst.shape(), dst.data_type(), dst.fixed_point_position(), reinterpret_cast<uint8_t *>(dst.data())); |
Isabella Gottardi | b797fa2 | 2017-06-23 15:02:11 +0100 | [diff] [blame] | 267 | tensor_operations::threshold(s, d, threshold, false_value, true_value, type, upper); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 268 | } |
| 269 | |
Isabella Gottardi | 6203153 | 2017-07-04 11:21:28 +0100 | [diff] [blame] | 270 | // Warp perspective |
| 271 | void ReferenceCPP::warp_perspective(const RawTensor &src, RawTensor &dst, RawTensor &valid_mask, const float *matrix, InterpolationPolicy policy, BorderMode border_mode, uint8_t constant_border_value) |
| 272 | { |
| 273 | ARM_COMPUTE_ERROR_ON(src.data_type() != DataType::U8 || dst.data_type() != DataType::U8); |
| 274 | const Tensor<uint8_t> s(src.shape(), src.data_type(), src.fixed_point_position(), reinterpret_cast<const uint8_t *>(src.data())); |
| 275 | Tensor<uint8_t> d(dst.shape(), dst.data_type(), dst.fixed_point_position(), reinterpret_cast<uint8_t *>(dst.data())); |
| 276 | Tensor<uint8_t> vmask(valid_mask.shape(), valid_mask.data_type(), valid_mask.fixed_point_position(), reinterpret_cast<uint8_t *>(valid_mask.data())); |
| 277 | tensor_operations::warp_perspective(s, d, vmask, matrix, policy, border_mode, constant_border_value); |
| 278 | } |
| 279 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 280 | // Batch Normalization Layer |
| 281 | void ReferenceCPP::batch_normalization_layer(const RawTensor &src, RawTensor &dst, const RawTensor &mean, const RawTensor &var, const RawTensor &beta, const RawTensor &gamma, float epsilon, |
| 282 | int fixed_point_position) |
| 283 | { |
| 284 | const TensorVariant s = TensorFactory::get_tensor(src); |
| 285 | TensorVariant d = TensorFactory::get_tensor(dst); |
| 286 | const TensorVariant m = TensorFactory::get_tensor(mean); |
| 287 | const TensorVariant v = TensorFactory::get_tensor(var); |
| 288 | const TensorVariant b = TensorFactory::get_tensor(beta); |
| 289 | const TensorVariant g = TensorFactory::get_tensor(gamma); |
| 290 | boost::apply_visitor(tensor_visitors::batch_normalization_layer_visitor(s, m, v, b, g, epsilon, fixed_point_position), d); |
| 291 | } |
| 292 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 293 | // Fully connected layer |
| 294 | void ReferenceCPP::fully_connected_layer(const RawTensor &src, const RawTensor &weights, const RawTensor &bias, RawTensor &dst) |
| 295 | { |
| 296 | const TensorVariant s = TensorFactory::get_tensor(src); |
| 297 | const TensorVariant w = TensorFactory::get_tensor(weights); |
| 298 | const TensorVariant b = TensorFactory::get_tensor(bias); |
| 299 | TensorVariant d = TensorFactory::get_tensor(dst); |
| 300 | boost::apply_visitor(tensor_visitors::fully_connected_layer_visitor(s, w, b), d); |
| 301 | } |
| 302 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 303 | // Pooling Layer |
Michalis Spyrou | bbd9fb9 | 2017-06-22 12:57:51 +0100 | [diff] [blame] | 304 | void ReferenceCPP::pooling_layer(const RawTensor &src, RawTensor &dst, PoolingLayerInfo pool_info) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 305 | { |
| 306 | const TensorVariant s = TensorFactory::get_tensor(src); |
| 307 | TensorVariant d = TensorFactory::get_tensor(dst); |
Michalis Spyrou | bbd9fb9 | 2017-06-22 12:57:51 +0100 | [diff] [blame] | 308 | boost::apply_visitor(tensor_visitors::pooling_layer_visitor(s, pool_info), d); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 309 | } |
| 310 | |
Georgios Pinitas | 7b7858d | 2017-06-21 16:44:24 +0100 | [diff] [blame] | 311 | // ROI Pooling Layer |
| 312 | void ReferenceCPP::roi_pooling_layer(const RawTensor &src, RawTensor &dst, const std::vector<ROI> &rois, const ROIPoolingLayerInfo &pool_info) |
| 313 | { |
| 314 | const TensorVariant s = TensorFactory::get_tensor(src); |
| 315 | TensorVariant d = TensorFactory::get_tensor(dst); |
| 316 | boost::apply_visitor(tensor_visitors::roi_pooling_layer_visitor(s, rois, pool_info), d); |
| 317 | } |
| 318 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 319 | // Fixed point operation |
| 320 | void ReferenceCPP::fixed_point_operation(const RawTensor &src, RawTensor &dst, FixedPointOp op) |
| 321 | { |
| 322 | const TensorVariant s = TensorFactory::get_tensor(src); |
| 323 | TensorVariant d = TensorFactory::get_tensor(dst); |
| 324 | boost::apply_visitor(tensor_visitors::fixed_point_operation_visitor(s, op), d); |
| 325 | } |
| 326 | |
| 327 | } // namespace validation |
| 328 | } // namespace test |
| 329 | } // namespace arm_compute |