Aron Virginas-Tar | b3670b1 | 2019-10-28 16:06:50 +0000 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2019 Arm Ltd. All rights reserved. |
| 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
| 6 | #include "ResizeTestImpl.hpp" |
| 7 | |
Aron Virginas-Tar | b3670b1 | 2019-10-28 16:06:50 +0000 | [diff] [blame] | 8 | #include <QuantizeHelper.hpp> |
Aron Virginas-Tar | b3670b1 | 2019-10-28 16:06:50 +0000 | [diff] [blame] | 9 | |
| 10 | #include <armnn/ArmNN.hpp> |
| 11 | |
Matteo Martincigh | e011d20 | 2019-11-28 11:35:47 +0000 | [diff] [blame] | 12 | #include <armnnUtils/TensorUtils.hpp> |
| 13 | #include <armnnUtils/DataLayoutIndexed.hpp> |
| 14 | #include <armnnUtils/Permute.hpp> |
| 15 | |
Aron Virginas-Tar | b3670b1 | 2019-10-28 16:06:50 +0000 | [diff] [blame] | 16 | #include <backendsCommon/test/DataLayoutUtils.hpp> |
| 17 | #include <backendsCommon/test/TensorCopyUtils.hpp> |
| 18 | #include <backendsCommon/test/WorkloadTestUtils.hpp> |
| 19 | |
| 20 | #include <test/TensorHelpers.hpp> |
| 21 | |
| 22 | namespace |
| 23 | { |
| 24 | |
| 25 | struct ResizeTestParams |
| 26 | { |
| 27 | ResizeTestParams() |
| 28 | : m_ResizeMethod(armnn::ResizeMethod::Bilinear) |
| 29 | , m_DataLayout(armnn::DataLayout::NCHW) |
| 30 | , m_InQuantScale(1.0f) |
| 31 | , m_InQuantOffset(0) |
| 32 | , m_OutQuantScale(1.0f) |
| 33 | , m_OutQuantOffset(0) {} |
| 34 | |
| 35 | armnn::ResizeMethod m_ResizeMethod; |
| 36 | armnn::DataLayout m_DataLayout; |
| 37 | |
| 38 | armnn::TensorShape m_InputShape; |
| 39 | armnn::TensorShape m_OutputShape; |
| 40 | |
| 41 | std::vector<float> m_InputData; |
| 42 | std::vector<float> m_ExpectedOutputData; |
| 43 | |
| 44 | float m_InQuantScale; |
| 45 | int32_t m_InQuantOffset; |
| 46 | |
| 47 | float m_OutQuantScale; |
| 48 | int32_t m_OutQuantOffset; |
| 49 | |
| 50 | void SetInQuantParams(float quantScale, int32_t quantOffset) |
| 51 | { |
| 52 | m_InQuantScale = quantScale; |
| 53 | m_InQuantOffset = quantOffset; |
| 54 | } |
| 55 | |
| 56 | void SetOutQuantParams(float quantScale, int32_t quantOffset) |
| 57 | { |
| 58 | m_OutQuantScale = quantScale; |
| 59 | m_OutQuantOffset = quantOffset; |
| 60 | } |
| 61 | |
| 62 | void SetInOutQuantParams(float quantScale, int32_t quantOffset) |
| 63 | { |
| 64 | SetInQuantParams(quantScale, quantOffset); |
| 65 | SetOutQuantParams(quantScale, quantOffset); |
| 66 | } |
| 67 | }; |
| 68 | |
| 69 | template<size_t NumDims, |
| 70 | armnn::DataType ArmnnType, |
| 71 | typename T = armnn::ResolveType<ArmnnType>> |
| 72 | LayerTestResult<T, NumDims> ResizeTestImpl( |
| 73 | armnn::IWorkloadFactory& workloadFactory, |
| 74 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, |
| 75 | const ResizeTestParams& params) |
| 76 | { |
Derek Lamberti | c374ff0 | 2019-12-10 21:57:35 +0000 | [diff] [blame] | 77 | boost::ignore_unused(memoryManager); |
Aron Virginas-Tar | b3670b1 | 2019-10-28 16:06:50 +0000 | [diff] [blame] | 78 | armnn::TensorInfo inputInfo(params.m_InputShape, ArmnnType); |
| 79 | armnn::TensorInfo outputInfo(params.m_OutputShape, ArmnnType); |
| 80 | |
| 81 | if (armnn::IsQuantizedType<T>()) |
| 82 | { |
| 83 | inputInfo.SetQuantizationScale(params.m_InQuantScale); |
| 84 | inputInfo.SetQuantizationOffset(params.m_InQuantOffset); |
| 85 | |
| 86 | outputInfo.SetQuantizationScale(params.m_OutQuantScale); |
| 87 | outputInfo.SetQuantizationOffset(params.m_OutQuantOffset); |
| 88 | } |
| 89 | |
| 90 | std::vector<T> inputData = |
| 91 | armnnUtils::QuantizedVector<T>(params.m_InputData, params.m_InQuantScale, params.m_InQuantOffset); |
| 92 | |
| 93 | std::vector<T> expectedOutputData = |
| 94 | armnnUtils::QuantizedVector<T>(params.m_ExpectedOutputData, |
| 95 | params.m_OutQuantScale, |
| 96 | params.m_OutQuantOffset); |
| 97 | |
| 98 | if (params.m_DataLayout == armnn::DataLayout::NHWC) |
| 99 | { |
| 100 | PermuteTensorNchwToNhwc(inputInfo, inputData); |
| 101 | PermuteTensorNchwToNhwc(outputInfo, expectedOutputData); |
| 102 | } |
| 103 | |
| 104 | auto input = MakeTensor<T, NumDims>(inputInfo, inputData); |
| 105 | |
| 106 | LayerTestResult<T, NumDims> result(outputInfo); |
| 107 | result.outputExpected = MakeTensor<T, NumDims>(outputInfo, expectedOutputData); |
| 108 | |
| 109 | std::unique_ptr<armnn::ITensorHandle> inputHandle = workloadFactory.CreateTensorHandle(inputInfo); |
| 110 | std::unique_ptr<armnn::ITensorHandle> outputHandle = workloadFactory.CreateTensorHandle(outputInfo); |
| 111 | |
| 112 | armnn::ResizeQueueDescriptor descriptor; |
| 113 | descriptor.m_Parameters.m_Method = params.m_ResizeMethod; |
| 114 | descriptor.m_Parameters.m_DataLayout = params.m_DataLayout; |
| 115 | |
| 116 | armnnUtils::DataLayoutIndexed dataLayoutIndexed(params.m_DataLayout); |
| 117 | descriptor.m_Parameters.m_TargetWidth = params.m_OutputShape[dataLayoutIndexed.GetWidthIndex()]; |
| 118 | descriptor.m_Parameters.m_TargetHeight = params.m_OutputShape[dataLayoutIndexed.GetHeightIndex()]; |
| 119 | |
| 120 | armnn::WorkloadInfo info; |
| 121 | AddInputToWorkload(descriptor, info, inputInfo, inputHandle.get()); |
| 122 | AddOutputToWorkload(descriptor, info, outputInfo, outputHandle.get()); |
| 123 | |
| 124 | std::unique_ptr<armnn::IWorkload> workload = workloadFactory.CreateResize(descriptor, info); |
| 125 | |
| 126 | inputHandle->Allocate(); |
| 127 | outputHandle->Allocate(); |
| 128 | CopyDataToITensorHandle(inputHandle.get(), input.origin()); |
| 129 | |
| 130 | workload->PostAllocationConfigure(); |
| 131 | workload->Execute(); |
| 132 | |
| 133 | CopyDataFromITensorHandle(result.output.origin(), outputHandle.get()); |
| 134 | return result; |
| 135 | } |
| 136 | |
| 137 | } // anonymous namespace |
| 138 | |
| 139 | // |
| 140 | // Bilinear |
| 141 | // |
| 142 | |
| 143 | template<armnn::DataType ArmnnType, typename T> |
| 144 | LayerTestResult<T, 4> ResizeBilinearNopTest( |
| 145 | armnn::IWorkloadFactory& workloadFactory, |
| 146 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, |
| 147 | const armnn::DataLayout dataLayout) |
| 148 | { |
| 149 | ResizeTestParams testParams; |
| 150 | testParams.m_ResizeMethod = armnn::ResizeMethod::Bilinear; |
| 151 | testParams.m_DataLayout = dataLayout; |
| 152 | |
| 153 | testParams.m_InputShape = { 1, 2, 4, 4 }; |
| 154 | testParams.m_OutputShape = testParams.m_InputShape; |
| 155 | |
| 156 | testParams.m_InputData = |
| 157 | { |
| 158 | 1.0f, 2.0f, 3.0f, 4.0f, |
| 159 | 2.0f, 3.0f, 4.0f, 5.0f, |
| 160 | 3.0f, 4.0f, 5.0f, 6.0f, |
| 161 | 4.0f, 5.0f, 6.0f, 7.0f, |
| 162 | |
| 163 | 1.0f, 2.0f, 3.0f, 4.0f, |
| 164 | 2.0f, 3.0f, 4.0f, 5.0f, |
| 165 | 3.0f, 4.0f, 5.0f, 6.0f, |
| 166 | 4.0f, 5.0f, 6.0f, 7.0f |
| 167 | }; |
| 168 | |
| 169 | testParams.m_ExpectedOutputData = testParams.m_InputData; |
| 170 | |
| 171 | testParams.SetInOutQuantParams(1.5f, 3); |
| 172 | |
| 173 | return ResizeTestImpl<4, ArmnnType>(workloadFactory, memoryManager, testParams); |
| 174 | } |
| 175 | |
| 176 | template<armnn::DataType ArmnnType, typename T> |
| 177 | LayerTestResult<T, 4> SimpleResizeBilinearTest( |
| 178 | armnn::IWorkloadFactory& workloadFactory, |
| 179 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, |
| 180 | const armnn::DataLayout dataLayout) |
| 181 | { |
| 182 | ResizeTestParams testParams; |
| 183 | testParams.m_ResizeMethod = armnn::ResizeMethod::Bilinear; |
| 184 | testParams.m_DataLayout = dataLayout; |
| 185 | |
| 186 | testParams.m_InputShape = { 1, 2, 2, 2 }; |
| 187 | testParams.m_OutputShape = { 1, 2, 1, 1 }; |
| 188 | |
| 189 | testParams.m_InputData = |
| 190 | { |
| 191 | 1.0f, 255.0f, |
| 192 | 200.0f, 250.0f, |
| 193 | |
| 194 | 250.0f, 200.0f, |
| 195 | 250.0f, 1.0f |
| 196 | }; |
| 197 | |
| 198 | // The 'resize' operation projects the top-left corner of output texels into the input image, |
| 199 | // then figures out the interpolants and weights. Note this is different to projecting the centre of the |
| 200 | // output texel. Thus, for a input matrix of 2x2, we'll expect the output 1x1 matrix to contain, as |
| 201 | // its single element, the value that was at position (0,0) of the input matrix (rather than an average, |
| 202 | // which we would expect if projecting the centre). |
| 203 | testParams.m_ExpectedOutputData = |
| 204 | { |
| 205 | 1.0f, |
| 206 | |
| 207 | 250.0f |
| 208 | }; |
| 209 | |
| 210 | testParams.SetInOutQuantParams(0.1567f, 1); |
| 211 | |
| 212 | return ResizeTestImpl<4, ArmnnType>(workloadFactory, memoryManager, testParams); |
| 213 | } |
| 214 | |
| 215 | template<armnn::DataType ArmnnType, typename T> |
| 216 | LayerTestResult<T, 4> ResizeBilinearSqMinTest( |
| 217 | armnn::IWorkloadFactory& workloadFactory, |
| 218 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, |
| 219 | const armnn::DataLayout dataLayout) |
| 220 | { |
| 221 | ResizeTestParams testParams; |
| 222 | testParams.m_ResizeMethod = armnn::ResizeMethod::Bilinear; |
| 223 | testParams.m_DataLayout = dataLayout; |
| 224 | |
| 225 | testParams.m_InputShape = { 1, 2, 4, 4 }; |
| 226 | testParams.m_OutputShape = { 1, 2, 2, 2 }; |
| 227 | |
| 228 | testParams.m_InputData = |
| 229 | { |
| 230 | 1.0f, 2.0f, 3.0f, 4.0f, |
| 231 | 2.0f, 3.0f, 4.0f, 5.0f, |
| 232 | 3.0f, 4.0f, 5.0f, 6.0f, |
| 233 | 4.0f, 5.0f, 6.0f, 7.0f, |
| 234 | |
| 235 | 7.0f, 6.0f, 5.0f, 4.0f, |
| 236 | 6.0f, 5.0f, 4.0f, 3.0f, |
| 237 | 5.0f, 4.0f, 3.0f, 2.0f, |
| 238 | 4.0f, 3.0f, 2.0f, 1.0f |
| 239 | }; |
| 240 | |
| 241 | testParams.m_ExpectedOutputData = |
| 242 | { |
| 243 | 1.0f, 3.0f, |
| 244 | 3.0f, 5.0f, |
| 245 | |
| 246 | 7.0f, 5.0f, |
| 247 | 5.0f, 3.0f |
| 248 | }; |
| 249 | |
| 250 | testParams.SetInOutQuantParams(3.141592f, 3); |
| 251 | |
| 252 | return ResizeTestImpl<4, ArmnnType>(workloadFactory, memoryManager, testParams); |
| 253 | } |
| 254 | |
| 255 | template<armnn::DataType ArmnnType, typename T> |
| 256 | LayerTestResult<T, 4> ResizeBilinearMinTest( |
| 257 | armnn::IWorkloadFactory& workloadFactory, |
| 258 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, |
| 259 | const armnn::DataLayout dataLayout) |
| 260 | { |
| 261 | ResizeTestParams testParams; |
| 262 | testParams.m_ResizeMethod = armnn::ResizeMethod::Bilinear; |
| 263 | testParams.m_DataLayout = dataLayout; |
| 264 | |
| 265 | testParams.m_InputShape = { 1, 2, 3, 5 }; |
| 266 | testParams.m_OutputShape = { 1, 2, 2, 3 }; |
| 267 | |
| 268 | testParams.m_InputData = |
| 269 | { |
| 270 | 1.5f, 3.0f, 4.5f, 6.0f, 7.5f, |
| 271 | 9.0f, 10.5f, 12.0f, 13.5f, 15.0f, |
| 272 | 16.5f, 18.0f, 19.5f, 21.0f, 22.5f, |
| 273 | |
| 274 | 16.5f, 18.0f, 19.5f, 21.0f, 22.5f, |
| 275 | 9.0f, 10.5f, 12.0f, 13.5f, 15.0f, |
| 276 | 1.5f, 3.0f, 4.5f, 6.0f, 7.5f |
| 277 | }; |
| 278 | |
| 279 | testParams.m_ExpectedOutputData = |
| 280 | { |
| 281 | 1.50f, 4.00f, 6.50f, |
| 282 | 12.75f, 15.25f, 17.75f, |
| 283 | |
| 284 | 16.50f, 19.00f, 21.50f, |
| 285 | 5.25f, 7.75f, 10.25f |
| 286 | }; |
| 287 | |
| 288 | testParams.SetInOutQuantParams(1.5f, -1); |
| 289 | |
| 290 | return ResizeTestImpl<4, ArmnnType>(workloadFactory, memoryManager, testParams); |
| 291 | } |
| 292 | |
| 293 | template<armnn::DataType ArmnnType, typename T> |
| 294 | LayerTestResult<T, 4> ResizeBilinearMagTest( |
| 295 | armnn::IWorkloadFactory& workloadFactory, |
| 296 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, |
| 297 | const armnn::DataLayout dataLayout) |
| 298 | { |
| 299 | ResizeTestParams testParams; |
| 300 | testParams.m_ResizeMethod = armnn::ResizeMethod::Bilinear; |
| 301 | testParams.m_DataLayout = dataLayout; |
| 302 | |
| 303 | testParams.m_InputShape = { 1, 2, 3, 2 }; |
| 304 | testParams.m_OutputShape = { 1, 2, 3, 5 }; |
| 305 | |
| 306 | testParams.m_InputData = |
| 307 | { |
| 308 | 1.0f, 2.0f, |
| 309 | 13.0f, 21.0f, |
| 310 | 144.0f, 233.0f, |
| 311 | |
| 312 | 233.0f, 144.0f, |
| 313 | 21.0f, 13.0f, |
| 314 | 2.0f, 1.0f |
| 315 | }; |
| 316 | |
| 317 | testParams.m_ExpectedOutputData = |
| 318 | { |
| 319 | 1.0f, 1.4f, 1.8f, 2.0f, 2.0f, |
| 320 | 13.0f, 16.2f, 19.4f, 21.0f, 21.0f, |
| 321 | 144.0f, 179.6f, 215.2f, 233.0f, 233.0f, |
| 322 | |
| 323 | 233.0f, 197.4f, 161.8f, 144.0f, 144.0f, |
| 324 | 21.0f, 17.8f, 14.6f, 13.0f, 13.0f, |
| 325 | 2.0f, 1.6f, 1.2f, 1.0f, 1.0f |
| 326 | }; |
| 327 | |
| 328 | testParams.SetInQuantParams(1.0f, 0); |
| 329 | |
| 330 | return ResizeTestImpl<4, ArmnnType>(workloadFactory, memoryManager, testParams); |
| 331 | } |
| 332 | |
| 333 | // |
| 334 | // NearestNeighbor |
| 335 | // |
| 336 | |
| 337 | template<armnn::DataType ArmnnType, typename T> |
| 338 | LayerTestResult<T, 4> ResizeNearestNeighborNopTest( |
| 339 | armnn::IWorkloadFactory& workloadFactory, |
| 340 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, |
| 341 | const armnn::DataLayout dataLayout) |
| 342 | { |
| 343 | ResizeTestParams testParams; |
| 344 | testParams.m_ResizeMethod = armnn::ResizeMethod::NearestNeighbor; |
| 345 | testParams.m_DataLayout = dataLayout; |
| 346 | |
| 347 | testParams.m_InputShape = { 1, 2, 4, 4 }; |
| 348 | testParams.m_OutputShape = testParams.m_InputShape; |
| 349 | |
| 350 | testParams.m_InputData = |
| 351 | { |
| 352 | 1.0f, 2.0f, 3.0f, 4.0f, |
| 353 | 2.0f, 3.0f, 4.0f, 5.0f, |
| 354 | 3.0f, 4.0f, 5.0f, 6.0f, |
| 355 | 4.0f, 5.0f, 6.0f, 7.0f, |
| 356 | |
| 357 | 1.0f, 2.0f, 3.0f, 4.0f, |
| 358 | 2.0f, 3.0f, 4.0f, 5.0f, |
| 359 | 3.0f, 4.0f, 5.0f, 6.0f, |
| 360 | 4.0f, 5.0f, 6.0f, 7.0f |
| 361 | }; |
| 362 | |
| 363 | testParams.m_ExpectedOutputData = testParams.m_InputData; |
| 364 | |
| 365 | testParams.SetInOutQuantParams(1.5f, 3); |
| 366 | |
| 367 | return ResizeTestImpl<4, ArmnnType>(workloadFactory, memoryManager, testParams); |
| 368 | } |
| 369 | |
| 370 | template<armnn::DataType ArmnnType, typename T> |
| 371 | LayerTestResult<T, 4> SimpleResizeNearestNeighborTest( |
| 372 | armnn::IWorkloadFactory& workloadFactory, |
| 373 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, |
| 374 | const armnn::DataLayout dataLayout) |
| 375 | { |
| 376 | ResizeTestParams testParams; |
| 377 | testParams.m_ResizeMethod = armnn::ResizeMethod::NearestNeighbor; |
| 378 | testParams.m_DataLayout = dataLayout; |
| 379 | |
| 380 | testParams.m_InputShape = { 1, 2, 2, 2 }; |
| 381 | testParams.m_OutputShape = { 1, 2, 1, 1 }; |
| 382 | |
| 383 | testParams.m_InputData = |
| 384 | { |
| 385 | 1.0f, 255.0f, |
| 386 | 200.0f, 250.0f, |
| 387 | |
| 388 | 250.0f, 200.0f, |
| 389 | 250.0f, 1.0f |
| 390 | }; |
| 391 | |
| 392 | // The 'resize' operation projects the top-left corner of output texels into the input image, |
| 393 | // then figures out the interpolants and weights. Note this is different to projecting the centre of the |
| 394 | // output texel. Thus, for a input matrix of 2x2, we'll expect the output 1x1 matrix to contain, as |
| 395 | // its single element, the value that was at position (0,0) of the input matrix (rather than an average, |
| 396 | // which we would expect if projecting the centre). |
| 397 | testParams.m_ExpectedOutputData = |
| 398 | { |
| 399 | 1.0f, |
| 400 | |
| 401 | 250.0f |
| 402 | }; |
| 403 | |
| 404 | testParams.SetInOutQuantParams(0.1567f, 1); |
| 405 | |
| 406 | return ResizeTestImpl<4, ArmnnType>(workloadFactory, memoryManager, testParams); |
| 407 | } |
| 408 | |
| 409 | template<armnn::DataType ArmnnType, typename T> |
| 410 | LayerTestResult<T, 4> ResizeNearestNeighborSqMinTest( |
| 411 | armnn::IWorkloadFactory& workloadFactory, |
| 412 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, |
| 413 | const armnn::DataLayout dataLayout) |
| 414 | { |
| 415 | ResizeTestParams testParams; |
| 416 | testParams.m_ResizeMethod = armnn::ResizeMethod::NearestNeighbor; |
| 417 | testParams.m_DataLayout = dataLayout; |
| 418 | |
| 419 | testParams.m_InputShape = { 1, 2, 4, 4 }; |
| 420 | testParams.m_OutputShape = { 1, 2, 2, 2 }; |
| 421 | |
| 422 | testParams.m_InputData = |
| 423 | { |
| 424 | 1.0f, 2.0f, 3.0f, 4.0f, |
| 425 | 2.0f, 3.0f, 4.0f, 5.0f, |
| 426 | 3.0f, 4.0f, 5.0f, 6.0f, |
| 427 | 4.0f, 5.0f, 6.0f, 7.0f, |
| 428 | |
| 429 | 7.0f, 6.0f, 5.0f, 4.0f, |
| 430 | 6.0f, 5.0f, 4.0f, 3.0f, |
| 431 | 5.0f, 4.0f, 3.0f, 2.0f, |
| 432 | 4.0f, 3.0f, 2.0f, 1.0f |
| 433 | }; |
| 434 | |
| 435 | testParams.m_ExpectedOutputData = |
| 436 | { |
| 437 | 1.0f, 3.0f, |
| 438 | 3.0f, 5.0f, |
| 439 | |
| 440 | 7.0f, 5.0f, |
| 441 | 5.0f, 3.0f |
| 442 | }; |
| 443 | |
| 444 | testParams.SetInOutQuantParams(3.141592f, 3); |
| 445 | |
| 446 | return ResizeTestImpl<4, ArmnnType>(workloadFactory, memoryManager, testParams); |
| 447 | } |
| 448 | |
| 449 | template<armnn::DataType ArmnnType, typename T> |
| 450 | LayerTestResult<T, 4> ResizeNearestNeighborMinTest( |
| 451 | armnn::IWorkloadFactory& workloadFactory, |
| 452 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, |
| 453 | const armnn::DataLayout dataLayout) |
| 454 | { |
| 455 | ResizeTestParams testParams; |
| 456 | testParams.m_ResizeMethod = armnn::ResizeMethod::NearestNeighbor; |
| 457 | testParams.m_DataLayout = dataLayout; |
| 458 | |
| 459 | testParams.m_InputShape = { 1, 2, 3, 5 }; |
| 460 | testParams.m_OutputShape = { 1, 2, 2, 3 }; |
| 461 | |
| 462 | testParams.m_InputData = |
| 463 | { |
| 464 | 1.5f, 3.0f, 4.5f, 6.0f, 7.5f, |
| 465 | 9.0f, 10.5f, 12.0f, 13.5f, 15.0f, |
| 466 | 16.5f, 18.0f, 19.5f, 21.0f, 22.5f, |
| 467 | |
| 468 | 16.5f, 18.0f, 19.5f, 21.0f, 22.5f, |
| 469 | 9.0f, 10.5f, 12.0f, 13.5f, 15.0f, |
| 470 | 1.5f, 3.0f, 4.5f, 6.0f, 7.5f |
| 471 | }; |
| 472 | |
| 473 | testParams.m_ExpectedOutputData = |
| 474 | { |
| 475 | 1.5f, 3.0f, 6.0f, |
| 476 | 9.0f, 10.5f, 13.5f, |
| 477 | |
| 478 | 16.5f, 18.0f, 21.0f, |
| 479 | 9.0f, 10.5f, 13.5f |
| 480 | }; |
| 481 | |
| 482 | testParams.SetInOutQuantParams(1.5f, -1); |
| 483 | |
| 484 | return ResizeTestImpl<4, ArmnnType>(workloadFactory, memoryManager, testParams); |
| 485 | } |
| 486 | |
| 487 | template<armnn::DataType ArmnnType, typename T> |
| 488 | LayerTestResult<T, 4> ResizeNearestNeighborMagTest( |
| 489 | armnn::IWorkloadFactory& workloadFactory, |
| 490 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, |
| 491 | const armnn::DataLayout dataLayout, |
| 492 | float inQuantScale, |
| 493 | int32_t inQuantOffset, |
| 494 | float outQuantScale, |
| 495 | int32_t outQuantOffset) |
| 496 | { |
| 497 | ResizeTestParams testParams; |
| 498 | testParams.m_ResizeMethod = armnn::ResizeMethod::NearestNeighbor; |
| 499 | testParams.m_DataLayout = dataLayout; |
| 500 | |
| 501 | testParams.m_InputShape = { 1, 2, 3, 2 }; |
| 502 | testParams.m_OutputShape = { 1, 2, 3, 5 }; |
| 503 | |
| 504 | testParams.m_InputData = |
| 505 | { |
| 506 | 0.183005f, 2.379065f, |
| 507 | 1.054970f, 1.302565f, |
| 508 | 2.400595f, 0.688960f, |
| 509 | |
| 510 | 2.400595f, 0.688960f, |
| 511 | 1.054970f, 1.302565f, |
| 512 | 0.183005f, 2.379065f, |
| 513 | }; |
| 514 | |
| 515 | testParams.m_ExpectedOutputData = |
| 516 | { |
| 517 | 0.183005f, 0.183005f, 0.183005f, 2.379065f, 2.379065f, |
| 518 | 1.054970f, 1.054970f, 1.054970f, 1.302565f, 1.302565f, |
| 519 | 2.400595f, 2.400595f, 2.400595f, 0.688960f, 0.688960f, |
| 520 | |
| 521 | 2.400595f, 2.400595f, 2.400595f, 0.688960f, 0.688960f, |
| 522 | 1.054970f, 1.054970f, 1.054970f, 1.302565f, 1.302565f, |
| 523 | 0.183005f, 0.183005f, 0.183005f, 2.379065f, 2.379065f |
| 524 | }; |
| 525 | |
| 526 | testParams.SetInQuantParams(inQuantScale, inQuantOffset); |
| 527 | testParams.SetOutQuantParams(outQuantScale, outQuantOffset); |
| 528 | |
| 529 | return ResizeTestImpl<4, ArmnnType>(workloadFactory, memoryManager, testParams); |
| 530 | } |
| 531 | |
| 532 | // |
| 533 | // Explicit template instantiations |
| 534 | // |
| 535 | |
| 536 | // Float32 |
| 537 | template LayerTestResult<armnn::ResolveType<armnn::DataType::Float32>, 4> |
| 538 | ResizeBilinearNopTest<armnn::DataType::Float32>( |
| 539 | armnn::IWorkloadFactory& workloadFactory, |
| 540 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, |
| 541 | const armnn::DataLayout dataLayout); |
| 542 | |
| 543 | template LayerTestResult<armnn::ResolveType<armnn::DataType::Float32>, 4> |
| 544 | SimpleResizeBilinearTest<armnn::DataType::Float32>( |
| 545 | armnn::IWorkloadFactory& workloadFactory, |
| 546 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, |
| 547 | const armnn::DataLayout dataLayout); |
| 548 | |
| 549 | template LayerTestResult<armnn::ResolveType<armnn::DataType::Float32>, 4> |
| 550 | ResizeBilinearSqMinTest<armnn::DataType::Float32>( |
| 551 | armnn::IWorkloadFactory& workloadFactory, |
| 552 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, |
| 553 | const armnn::DataLayout dataLayout); |
| 554 | |
| 555 | template LayerTestResult<armnn::ResolveType<armnn::DataType::Float32>, 4> |
| 556 | ResizeBilinearMinTest<armnn::DataType::Float32>( |
| 557 | armnn::IWorkloadFactory& workloadFactory, |
| 558 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, |
| 559 | const armnn::DataLayout dataLayout); |
| 560 | |
| 561 | template LayerTestResult<armnn::ResolveType<armnn::DataType::Float32>, 4> |
| 562 | ResizeBilinearMagTest<armnn::DataType::Float32>( |
| 563 | armnn::IWorkloadFactory& workloadFactory, |
| 564 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, |
| 565 | const armnn::DataLayout dataLayout); |
| 566 | |
| 567 | template LayerTestResult<armnn::ResolveType<armnn::DataType::Float32>, 4> |
| 568 | ResizeNearestNeighborNopTest<armnn::DataType::Float32>( |
| 569 | armnn::IWorkloadFactory& workloadFactory, |
| 570 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, |
| 571 | const armnn::DataLayout dataLayout); |
| 572 | |
| 573 | template LayerTestResult<armnn::ResolveType<armnn::DataType::Float32>, 4> |
| 574 | SimpleResizeNearestNeighborTest<armnn::DataType::Float32>( |
| 575 | armnn::IWorkloadFactory& workloadFactory, |
| 576 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, |
| 577 | const armnn::DataLayout dataLayout); |
| 578 | |
| 579 | template LayerTestResult<armnn::ResolveType<armnn::DataType::Float32>, 4> |
| 580 | ResizeNearestNeighborSqMinTest<armnn::DataType::Float32>( |
| 581 | armnn::IWorkloadFactory& workloadFactory, |
| 582 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, |
| 583 | const armnn::DataLayout dataLayout); |
| 584 | |
| 585 | template LayerTestResult<armnn::ResolveType<armnn::DataType::Float32>, 4> |
| 586 | ResizeNearestNeighborMinTest<armnn::DataType::Float32>( |
| 587 | armnn::IWorkloadFactory& workloadFactory, |
| 588 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, |
| 589 | const armnn::DataLayout dataLayout); |
| 590 | |
| 591 | template LayerTestResult<armnn::ResolveType<armnn::DataType::Float32>, 4> |
| 592 | ResizeNearestNeighborMagTest<armnn::DataType::Float32>( |
| 593 | armnn::IWorkloadFactory& workloadFactory, |
| 594 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, |
| 595 | const armnn::DataLayout dataLayout, |
| 596 | float inQuantScale, |
| 597 | int32_t inQuantOffset, |
| 598 | float outQuantScale, |
| 599 | int32_t outQuantOffset); |
| 600 | |
| 601 | // Float16 |
| 602 | template LayerTestResult<armnn::ResolveType<armnn::DataType::Float16>, 4> |
| 603 | ResizeBilinearNopTest<armnn::DataType::Float16>( |
| 604 | armnn::IWorkloadFactory& workloadFactory, |
| 605 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, |
| 606 | const armnn::DataLayout dataLayout); |
| 607 | |
| 608 | template LayerTestResult<armnn::ResolveType<armnn::DataType::Float16>, 4> |
| 609 | SimpleResizeBilinearTest<armnn::DataType::Float16>( |
| 610 | armnn::IWorkloadFactory& workloadFactory, |
| 611 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, |
| 612 | const armnn::DataLayout dataLayout); |
| 613 | |
| 614 | template LayerTestResult<armnn::ResolveType<armnn::DataType::Float16>, 4> |
| 615 | ResizeBilinearSqMinTest<armnn::DataType::Float16>( |
| 616 | armnn::IWorkloadFactory& workloadFactory, |
| 617 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, |
| 618 | const armnn::DataLayout dataLayout); |
| 619 | |
| 620 | template LayerTestResult<armnn::ResolveType<armnn::DataType::Float16>, 4> |
| 621 | ResizeBilinearMinTest<armnn::DataType::Float16>( |
| 622 | armnn::IWorkloadFactory& workloadFactory, |
| 623 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, |
| 624 | const armnn::DataLayout dataLayout); |
| 625 | |
| 626 | template LayerTestResult<armnn::ResolveType<armnn::DataType::Float16>, 4> |
| 627 | ResizeBilinearMagTest<armnn::DataType::Float16>( |
| 628 | armnn::IWorkloadFactory& workloadFactory, |
| 629 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, |
| 630 | const armnn::DataLayout dataLayout); |
| 631 | |
| 632 | template LayerTestResult<armnn::ResolveType<armnn::DataType::Float16>, 4> |
| 633 | ResizeNearestNeighborNopTest<armnn::DataType::Float16>( |
| 634 | armnn::IWorkloadFactory& workloadFactory, |
| 635 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, |
| 636 | const armnn::DataLayout dataLayout); |
| 637 | |
| 638 | template LayerTestResult<armnn::ResolveType<armnn::DataType::Float16>, 4> |
| 639 | SimpleResizeNearestNeighborTest<armnn::DataType::Float16>( |
| 640 | armnn::IWorkloadFactory& workloadFactory, |
| 641 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, |
| 642 | const armnn::DataLayout dataLayout); |
| 643 | |
| 644 | template LayerTestResult<armnn::ResolveType<armnn::DataType::Float16>, 4> |
| 645 | ResizeNearestNeighborSqMinTest<armnn::DataType::Float16>( |
| 646 | armnn::IWorkloadFactory& workloadFactory, |
| 647 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, |
| 648 | const armnn::DataLayout dataLayout); |
| 649 | |
| 650 | template LayerTestResult<armnn::ResolveType<armnn::DataType::Float16>, 4> |
| 651 | ResizeNearestNeighborMinTest<armnn::DataType::Float16>( |
| 652 | armnn::IWorkloadFactory& workloadFactory, |
| 653 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, |
| 654 | const armnn::DataLayout dataLayout); |
| 655 | |
| 656 | template LayerTestResult<armnn::ResolveType<armnn::DataType::Float16>, 4> |
| 657 | ResizeNearestNeighborMagTest<armnn::DataType::Float16>( |
| 658 | armnn::IWorkloadFactory& workloadFactory, |
| 659 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, |
| 660 | const armnn::DataLayout dataLayout, |
| 661 | float inQuantScale, |
| 662 | int32_t inQuantOffset, |
| 663 | float outQuantScale, |
| 664 | int32_t outQuantOffset); |
| 665 | |
| 666 | // QAsymm8 |
| 667 | template LayerTestResult<armnn::ResolveType<armnn::DataType::QuantisedAsymm8>, 4> |
| 668 | ResizeBilinearNopTest<armnn::DataType::QuantisedAsymm8>( |
| 669 | armnn::IWorkloadFactory& workloadFactory, |
| 670 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, |
| 671 | const armnn::DataLayout dataLayout); |
| 672 | |
| 673 | template LayerTestResult<armnn::ResolveType<armnn::DataType::QuantisedAsymm8>, 4> |
| 674 | SimpleResizeBilinearTest<armnn::DataType::QuantisedAsymm8>( |
| 675 | armnn::IWorkloadFactory& workloadFactory, |
| 676 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, |
| 677 | const armnn::DataLayout dataLayout); |
| 678 | |
| 679 | template LayerTestResult<armnn::ResolveType<armnn::DataType::QuantisedAsymm8>, 4> |
| 680 | ResizeBilinearSqMinTest<armnn::DataType::QuantisedAsymm8>( |
| 681 | armnn::IWorkloadFactory& workloadFactory, |
| 682 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, |
| 683 | const armnn::DataLayout dataLayout); |
| 684 | |
| 685 | template LayerTestResult<armnn::ResolveType<armnn::DataType::QuantisedAsymm8>, 4> |
| 686 | ResizeBilinearMinTest<armnn::DataType::QuantisedAsymm8>( |
| 687 | armnn::IWorkloadFactory& workloadFactory, |
| 688 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, |
| 689 | const armnn::DataLayout dataLayout); |
| 690 | |
| 691 | template LayerTestResult<armnn::ResolveType<armnn::DataType::QuantisedAsymm8>, 4> |
| 692 | ResizeBilinearMagTest<armnn::DataType::QuantisedAsymm8>( |
| 693 | armnn::IWorkloadFactory& workloadFactory, |
| 694 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, |
| 695 | const armnn::DataLayout dataLayout); |
| 696 | |
| 697 | template LayerTestResult<armnn::ResolveType<armnn::DataType::QuantisedAsymm8>, 4> |
| 698 | ResizeNearestNeighborNopTest<armnn::DataType::QuantisedAsymm8>( |
| 699 | armnn::IWorkloadFactory& workloadFactory, |
| 700 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, |
| 701 | const armnn::DataLayout dataLayout); |
| 702 | |
| 703 | template LayerTestResult<armnn::ResolveType<armnn::DataType::QuantisedAsymm8>, 4> |
| 704 | SimpleResizeNearestNeighborTest<armnn::DataType::QuantisedAsymm8>( |
| 705 | armnn::IWorkloadFactory& workloadFactory, |
| 706 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, |
| 707 | const armnn::DataLayout dataLayout); |
| 708 | |
| 709 | template LayerTestResult<armnn::ResolveType<armnn::DataType::QuantisedAsymm8>, 4> |
| 710 | ResizeNearestNeighborSqMinTest<armnn::DataType::QuantisedAsymm8>( |
| 711 | armnn::IWorkloadFactory& workloadFactory, |
| 712 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, |
| 713 | const armnn::DataLayout dataLayout); |
| 714 | |
| 715 | template LayerTestResult<armnn::ResolveType<armnn::DataType::QuantisedAsymm8>, 4> |
| 716 | ResizeNearestNeighborMinTest<armnn::DataType::QuantisedAsymm8>( |
| 717 | armnn::IWorkloadFactory& workloadFactory, |
| 718 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, |
| 719 | const armnn::DataLayout dataLayout); |
| 720 | |
| 721 | template LayerTestResult<armnn::ResolveType<armnn::DataType::QuantisedAsymm8>, 4> |
| 722 | ResizeNearestNeighborMagTest<armnn::DataType::QuantisedAsymm8>( |
| 723 | armnn::IWorkloadFactory& workloadFactory, |
| 724 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, |
| 725 | const armnn::DataLayout dataLayout, |
| 726 | float inQuantScale, |
| 727 | int32_t inQuantOffset, |
| 728 | float outQuantScale, |
| 729 | int32_t outQuantOffset); |
| 730 | |
| 731 | // QSymm16 |
| 732 | template LayerTestResult<armnn::ResolveType<armnn::DataType::QuantisedSymm16>, 4> |
| 733 | ResizeBilinearNopTest<armnn::DataType::QuantisedSymm16>( |
| 734 | armnn::IWorkloadFactory& workloadFactory, |
| 735 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, |
| 736 | const armnn::DataLayout dataLayout); |
| 737 | |
| 738 | template LayerTestResult<armnn::ResolveType<armnn::DataType::QuantisedSymm16>, 4> |
| 739 | SimpleResizeBilinearTest<armnn::DataType::QuantisedSymm16>( |
| 740 | armnn::IWorkloadFactory& workloadFactory, |
| 741 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, |
| 742 | const armnn::DataLayout dataLayout); |
| 743 | |
| 744 | template LayerTestResult<armnn::ResolveType<armnn::DataType::QuantisedSymm16>, 4> |
| 745 | ResizeBilinearSqMinTest<armnn::DataType::QuantisedSymm16>( |
| 746 | armnn::IWorkloadFactory& workloadFactory, |
| 747 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, |
| 748 | const armnn::DataLayout dataLayout); |
| 749 | |
| 750 | template LayerTestResult<armnn::ResolveType<armnn::DataType::QuantisedSymm16>, 4> |
| 751 | ResizeBilinearMinTest<armnn::DataType::QuantisedSymm16>( |
| 752 | armnn::IWorkloadFactory& workloadFactory, |
| 753 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, |
| 754 | const armnn::DataLayout dataLayout); |
| 755 | |
| 756 | template LayerTestResult<armnn::ResolveType<armnn::DataType::QuantisedSymm16>, 4> |
| 757 | ResizeBilinearMagTest<armnn::DataType::QuantisedSymm16>( |
| 758 | armnn::IWorkloadFactory& workloadFactory, |
| 759 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, |
| 760 | const armnn::DataLayout dataLayout); |
| 761 | |
| 762 | template LayerTestResult<armnn::ResolveType<armnn::DataType::QuantisedSymm16>, 4> |
| 763 | ResizeNearestNeighborNopTest<armnn::DataType::QuantisedSymm16>( |
| 764 | armnn::IWorkloadFactory& workloadFactory, |
| 765 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, |
| 766 | const armnn::DataLayout dataLayout); |
| 767 | |
| 768 | template LayerTestResult<armnn::ResolveType<armnn::DataType::QuantisedSymm16>, 4> |
| 769 | SimpleResizeNearestNeighborTest<armnn::DataType::QuantisedSymm16>( |
| 770 | armnn::IWorkloadFactory& workloadFactory, |
| 771 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, |
| 772 | const armnn::DataLayout dataLayout); |
| 773 | |
| 774 | template LayerTestResult<armnn::ResolveType<armnn::DataType::QuantisedSymm16>, 4> |
| 775 | ResizeNearestNeighborSqMinTest<armnn::DataType::QuantisedSymm16>( |
| 776 | armnn::IWorkloadFactory& workloadFactory, |
| 777 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, |
| 778 | const armnn::DataLayout dataLayout); |
| 779 | |
| 780 | template LayerTestResult<armnn::ResolveType<armnn::DataType::QuantisedSymm16>, 4> |
| 781 | ResizeNearestNeighborMinTest<armnn::DataType::QuantisedSymm16>( |
| 782 | armnn::IWorkloadFactory& workloadFactory, |
| 783 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, |
| 784 | const armnn::DataLayout dataLayout); |
| 785 | |
| 786 | template LayerTestResult<armnn::ResolveType<armnn::DataType::QuantisedSymm16>, 4> |
| 787 | ResizeNearestNeighborMagTest<armnn::DataType::QuantisedSymm16>( |
| 788 | armnn::IWorkloadFactory& workloadFactory, |
| 789 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, |
| 790 | const armnn::DataLayout dataLayout, |
| 791 | float inQuantScale, |
| 792 | int32_t inQuantOffset, |
| 793 | float outQuantScale, |
| 794 | int32_t outQuantOffset); |