Aron Virginas-Tar | 00d306e | 2019-08-28 18:08:46 +0100 | [diff] [blame] | 1 | // |
Teresa Charlin | fbf0e5b | 2020-08-17 01:01:06 +0100 | [diff] [blame] | 2 | // Copyright © 2017 Arm Ltd and Contributors. All rights reserved. |
Aron Virginas-Tar | 00d306e | 2019-08-28 18:08:46 +0100 | [diff] [blame] | 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
| 6 | #pragma once |
| 7 | |
| 8 | #include "LayerTestResult.hpp" |
| 9 | |
| 10 | #include <ResolveType.hpp> |
| 11 | |
Aron Virginas-Tar | 00d306e | 2019-08-28 18:08:46 +0100 | [diff] [blame] | 12 | |
Matteo Martincigh | e5b8eb9 | 2019-11-28 15:45:42 +0000 | [diff] [blame] | 13 | #include <armnn/backends/IBackendInternal.hpp> |
Aron Virginas-Tar | 00d306e | 2019-08-28 18:08:46 +0100 | [diff] [blame] | 14 | #include <backendsCommon/WorkloadFactory.hpp> |
| 15 | |
| 16 | #include <backendsCommon/test/DataTypeUtils.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 | template<armnn::DataType ArmnnType, |
| 26 | std::size_t InputDim, |
| 27 | std::size_t OutputDim, |
| 28 | typename T = armnn::ResolveType<ArmnnType>> |
| 29 | LayerTestResult<T, OutputDim> BatchToSpaceNdHelper( |
| 30 | armnn::IWorkloadFactory &workloadFactory, |
| 31 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, |
| 32 | const armnn::DataLayout& dataLayout, |
| 33 | const unsigned int *inputShape, |
| 34 | const std::vector<float> &inputData, |
| 35 | const std::vector<unsigned int> &blockShape, |
| 36 | const std::vector<std::pair<unsigned int, unsigned int>> &crops, |
| 37 | const unsigned int *outputShape, |
| 38 | const std::vector<float> &outputData, |
| 39 | float scale = 1.0f, |
| 40 | int32_t offset = 0) |
| 41 | { |
Jan Eilers | 8eb2560 | 2020-03-09 12:13:48 +0000 | [diff] [blame] | 42 | IgnoreUnused(memoryManager); |
Derek Lamberti | c374ff0 | 2019-12-10 21:57:35 +0000 | [diff] [blame] | 43 | |
Aron Virginas-Tar | 00d306e | 2019-08-28 18:08:46 +0100 | [diff] [blame] | 44 | armnn::TensorInfo inputTensorInfo(InputDim, inputShape, ArmnnType); |
| 45 | armnn::TensorInfo outputTensorInfo(OutputDim, outputShape, ArmnnType); |
| 46 | |
| 47 | inputTensorInfo.SetQuantizationScale(scale); |
| 48 | inputTensorInfo.SetQuantizationOffset(offset); |
| 49 | |
| 50 | outputTensorInfo.SetQuantizationScale(scale); |
| 51 | outputTensorInfo.SetQuantizationOffset(offset); |
| 52 | |
| 53 | auto input = MakeTensor<T, InputDim>(inputTensorInfo, ConvertToDataType<ArmnnType>(inputData, inputTensorInfo)); |
| 54 | |
| 55 | LayerTestResult<T, OutputDim> result(outputTensorInfo); |
| 56 | result.outputExpected = MakeTensor<T, OutputDim>(outputTensorInfo, |
| 57 | ConvertToDataType<ArmnnType>(outputData, outputTensorInfo)); |
| 58 | |
Teresa Charlin | fbf0e5b | 2020-08-17 01:01:06 +0100 | [diff] [blame] | 59 | ARMNN_NO_DEPRECATE_WARN_BEGIN |
Aron Virginas-Tar | 00d306e | 2019-08-28 18:08:46 +0100 | [diff] [blame] | 60 | std::unique_ptr<armnn::ITensorHandle> inputHandle = workloadFactory.CreateTensorHandle(inputTensorInfo); |
| 61 | std::unique_ptr<armnn::ITensorHandle> outputHandle = workloadFactory.CreateTensorHandle(outputTensorInfo); |
Teresa Charlin | fbf0e5b | 2020-08-17 01:01:06 +0100 | [diff] [blame] | 62 | ARMNN_NO_DEPRECATE_WARN_END |
Aron Virginas-Tar | 00d306e | 2019-08-28 18:08:46 +0100 | [diff] [blame] | 63 | |
| 64 | armnn::BatchToSpaceNdQueueDescriptor data; |
| 65 | data.m_Parameters.m_DataLayout = dataLayout; |
| 66 | data.m_Parameters.m_BlockShape = blockShape; |
| 67 | data.m_Parameters.m_Crops = crops; |
| 68 | armnn::WorkloadInfo info; |
| 69 | AddInputToWorkload(data, info, inputTensorInfo, inputHandle.get()); |
| 70 | AddOutputToWorkload(data, info, outputTensorInfo, outputHandle.get()); |
| 71 | |
| 72 | std::unique_ptr<armnn::IWorkload> workload = workloadFactory.CreateBatchToSpaceNd(data, info); |
| 73 | |
| 74 | inputHandle->Allocate(); |
| 75 | outputHandle->Allocate(); |
| 76 | |
| 77 | CopyDataToITensorHandle(inputHandle.get(), input.origin()); |
| 78 | |
| 79 | workload->PostAllocationConfigure(); |
| 80 | workload->Execute(); |
| 81 | |
| 82 | CopyDataFromITensorHandle(&result.output[0][0][0][0], outputHandle.get()); |
| 83 | |
| 84 | return result; |
| 85 | } |
| 86 | |
| 87 | } // anonymous namespace |
| 88 | |
| 89 | template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>> |
| 90 | LayerTestResult<T, 4> BatchToSpaceNdNhwcTest1( |
| 91 | armnn::IWorkloadFactory& workloadFactory, |
| 92 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
| 93 | { |
| 94 | const unsigned int inputShape[] = {4, 2, 2, 1}; |
| 95 | const unsigned int outputShape[] = {1, 4, 4, 1}; |
| 96 | |
| 97 | std::vector<float> input({ |
| 98 | // Batch 0, Height 0, Width (2) x Channel (1) |
| 99 | 1.0f, 3.0f, |
| 100 | // Batch 0, Height 1, Width (2) x Channel (1) |
| 101 | 9.0f, 11.0f, |
| 102 | |
| 103 | |
| 104 | // Batch 1, Height 0, Width (2) x Channel (1) |
| 105 | 2.0f, 4.0f, |
| 106 | // Batch 1, Height 1, Width (2) x Channel (1) |
| 107 | 10.0f, 12.0f, |
| 108 | |
| 109 | |
| 110 | // Batch 2, Height 0, Width (2) x Channel (1) |
| 111 | 5.0f, 7.0f, |
| 112 | // Batch 2, Height 1, Width (2) x Channel (1) |
| 113 | 13.0f, 15.0f, |
| 114 | |
| 115 | // Batch 3, Height 0, Width (2) x Channel (3) |
| 116 | 6.0f, 8.0f, |
| 117 | // Batch 3, Height 1, Width (2) x Channel (1) |
| 118 | 14.0f, 16.0f |
| 119 | }); |
| 120 | |
| 121 | std::vector<float> expectedOutput({ |
| 122 | 1.0f, 2.0f, 3.0f, 4.0f, |
| 123 | 5.0f, 6.0f, 7.0f, 8.0f, |
| 124 | 9.0f, 10.0f, 11.0f, 12.0f, |
| 125 | 13.0f, 14.0f, 15.0f, 16.0f |
| 126 | }); |
| 127 | |
| 128 | std::vector<unsigned int> blockShape {2, 2}; |
| 129 | std::vector<std::pair<unsigned int, unsigned int>> crops = {{0, 0}, {0, 0}}; |
| 130 | |
| 131 | return BatchToSpaceNdHelper<ArmnnType, 4, 4>(workloadFactory, memoryManager, |
| 132 | armnn::DataLayout::NHWC, inputShape, input, blockShape, |
| 133 | crops, outputShape, expectedOutput); |
| 134 | } |
| 135 | |
| 136 | template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>> |
| 137 | LayerTestResult<T, 4> BatchToSpaceNdNhwcTest2( |
| 138 | armnn::IWorkloadFactory& workloadFactory, |
| 139 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
| 140 | { |
| 141 | const unsigned int inputShape[] = {4, 1, 1, 1}; |
| 142 | const unsigned int outputShape[] = {1, 2, 2, 1}; |
| 143 | |
| 144 | std::vector<float> input({ |
| 145 | // Batch 0, Height 0, Width (2) x Channel (1) |
| 146 | 1.0f, 2.0f, 3.0f, 4.0f |
| 147 | }); |
| 148 | |
| 149 | std::vector<float> expectedOutput({1.0f, 2.0f, 3.0f, 4.0f}); |
| 150 | |
| 151 | std::vector<unsigned int> blockShape({2, 2}); |
| 152 | std::vector<std::pair<unsigned int, unsigned int>> crops = {{0, 0}, {0, 0}}; |
| 153 | |
| 154 | return BatchToSpaceNdHelper<ArmnnType, 4, 4>(workloadFactory, memoryManager, |
| 155 | armnn::DataLayout::NHWC, inputShape, input, blockShape, |
| 156 | crops, outputShape, expectedOutput); |
| 157 | } |
| 158 | |
| 159 | template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>> |
| 160 | LayerTestResult<T, 4> BatchToSpaceNdNhwcTest3( |
| 161 | armnn::IWorkloadFactory& workloadFactory, |
| 162 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
| 163 | { |
| 164 | const unsigned int inputShape[] = {4, 1, 1, 3}; |
| 165 | const unsigned int outputShape[] = {1, 2, 2, 3}; |
| 166 | |
| 167 | std::vector<float> input({1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f, 12.0f}); |
| 168 | |
| 169 | std::vector<float> expectedOutput({1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f, 12.0f}); |
| 170 | |
| 171 | std::vector<unsigned int> blockShape({2, 2}); |
| 172 | std::vector<std::pair<unsigned int, unsigned int>> crops = {{0, 0}, {0, 0}}; |
| 173 | |
| 174 | return BatchToSpaceNdHelper<ArmnnType, 4, 4>(workloadFactory, memoryManager, |
| 175 | armnn::DataLayout::NHWC, inputShape, input, blockShape, |
| 176 | crops, outputShape, expectedOutput); |
| 177 | } |
| 178 | |
| 179 | template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>> |
| 180 | LayerTestResult<T, 4> BatchToSpaceNdNhwcTest4( |
| 181 | armnn::IWorkloadFactory& workloadFactory, |
| 182 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
| 183 | { |
| 184 | const unsigned int inputShape[] = {8, 1, 3, 1}; |
| 185 | const unsigned int outputShape[] = {2, 2, 4, 1}; |
| 186 | |
| 187 | std::vector<float> input({ |
| 188 | 0.0f, 1.0f, 3.0f, |
| 189 | 0.0f, 9.0f, 11.0f, |
| 190 | 0.0f, 2.0f, 4.0f, |
| 191 | 0.0f, 10.0f, 12.0f, |
| 192 | 0.0f, 5.0f, 7.0f, |
| 193 | 0.0f, 13.0f, 15.0f, |
| 194 | 0.0f, 6.0f, 8.0f, |
| 195 | 0.0f, 14.0f, 16.0f |
| 196 | }); |
| 197 | |
| 198 | std::vector<float> expectedOutput({ |
| 199 | 1.0f, 2.0f, 3.0f, 4.0f, |
| 200 | 5.0f, 6.0f, 7.0f, 8.0f, |
| 201 | 9.0f, 10.0f, 11.0f, 12.0f, |
| 202 | 13.0f, 14.0f, 15.0f, 16.0f |
| 203 | }); |
| 204 | |
| 205 | std::vector<unsigned int> blockShape({2, 2}); |
| 206 | std::vector<std::pair<unsigned int, unsigned int>> crops = {{0, 0}, {2, 0}}; |
| 207 | |
| 208 | return BatchToSpaceNdHelper<ArmnnType, 4, 4>(workloadFactory, memoryManager, |
| 209 | armnn::DataLayout::NHWC, inputShape, input, blockShape, |
| 210 | crops, outputShape, expectedOutput); |
| 211 | } |
| 212 | |
| 213 | template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>> |
| 214 | LayerTestResult<T, 4> BatchToSpaceNdNhwcTest5( |
| 215 | armnn::IWorkloadFactory& workloadFactory, |
| 216 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
| 217 | { |
| 218 | const unsigned int inputShape[] = {4, 2, 2, 1}; |
| 219 | const unsigned int outputShape[] = {1, 4, 4, 1}; |
| 220 | |
| 221 | std::vector<float> input({1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}); |
| 222 | std::vector<float> expectedOutput({1, 5, 2, 6, 9, 13, 10, 14, 3, 7, 4, 8, 11, 15, 12, 16}); |
| 223 | |
| 224 | std::vector<unsigned int> blockShape({2, 2}); |
| 225 | std::vector<std::pair<unsigned int, unsigned int>> crops = {{0, 0}, {0, 0}}; |
| 226 | |
| 227 | return BatchToSpaceNdHelper<ArmnnType, 4, 4>(workloadFactory, memoryManager, armnn::DataLayout::NHWC, inputShape, |
| 228 | input, blockShape, crops, outputShape, expectedOutput); |
| 229 | } |
| 230 | |
| 231 | template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>> |
| 232 | LayerTestResult<T, 4> BatchToSpaceNdNhwcTest6( |
| 233 | armnn::IWorkloadFactory& workloadFactory, |
| 234 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
| 235 | { |
| 236 | const unsigned int inputShape[] = {4, 1, 1, 1}; |
| 237 | const unsigned int outputShape[] = {1, 2, 2, 1}; |
| 238 | |
| 239 | std::vector<float> input({ |
| 240 | // Batch 0, Height 0, Width (2) x Channel (1) |
| 241 | 1, 2, 3, 4 |
| 242 | }); |
| 243 | |
| 244 | std::vector<float> expectedOutput({1, 2, 3, 4}); |
| 245 | |
| 246 | std::vector<unsigned int> blockShape({2, 2}); |
| 247 | std::vector<std::pair<unsigned int, unsigned int>> crops = {{0, 0}, {0, 0}}; |
| 248 | |
| 249 | return BatchToSpaceNdHelper<ArmnnType, 4, 4>(workloadFactory, memoryManager, |
| 250 | armnn::DataLayout::NHWC, inputShape, input, blockShape, |
| 251 | crops, outputShape, expectedOutput); |
| 252 | } |
| 253 | |
| 254 | template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>> |
| 255 | LayerTestResult<T, 4> BatchToSpaceNdNhwcTest7( |
| 256 | armnn::IWorkloadFactory& workloadFactory, |
| 257 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
| 258 | { |
| 259 | const unsigned int inputShape[] = {4, 1, 1, 3}; |
| 260 | const unsigned int outputShape[] = {1, 2, 2, 3}; |
| 261 | |
| 262 | std::vector<float> input({1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}); |
| 263 | |
| 264 | std::vector<float> expectedOutput({1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}); |
| 265 | |
| 266 | std::vector<unsigned int> blockShape({2, 2}); |
| 267 | std::vector<std::pair<unsigned int, unsigned int>> crops = {{0, 0}, {0, 0}}; |
| 268 | |
| 269 | return BatchToSpaceNdHelper<ArmnnType, 4, 4>(workloadFactory, memoryManager, |
| 270 | armnn::DataLayout::NHWC, inputShape, input, blockShape, |
| 271 | crops, outputShape, expectedOutput); |
| 272 | } |
| 273 | |
| 274 | template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>> |
| 275 | LayerTestResult<T, 4> BatchToSpaceNdNchwTest1( |
| 276 | armnn::IWorkloadFactory &workloadFactory, |
| 277 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
| 278 | { |
| 279 | const unsigned int inputShape[] = {4, 3, 1, 1}; |
| 280 | const unsigned int outputShape[] = {1, 3, 2, 2}; |
| 281 | |
| 282 | std::vector<float> input({1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f, 12.0f}); |
| 283 | |
| 284 | std::vector<float> expectedOutput({ |
| 285 | // Batch 0, Channel 0, Height (2) x Width (2) |
| 286 | 1.0f, 4.0f, |
| 287 | 7.0f, 10.0f, |
| 288 | |
| 289 | // Batch 0, Channel 1, Height (2) x Width (2) |
| 290 | 2.0f, 5.0f, |
| 291 | 8.0f, 11.0f, |
| 292 | |
| 293 | // Batch 0, Channel 2, Height (2) x Width (2) |
| 294 | 3.0f, 6.0f, |
| 295 | 9.0f, 12.0f, |
| 296 | }); |
| 297 | |
| 298 | std::vector<unsigned int> blockShape({2, 2}); |
| 299 | std::vector<std::pair<unsigned int, unsigned int>> crops = {{0, 0}, {0, 0}}; |
| 300 | |
| 301 | return BatchToSpaceNdHelper<ArmnnType, 4, 4>(workloadFactory, memoryManager, |
| 302 | armnn::DataLayout::NCHW, inputShape, input, blockShape, |
| 303 | crops, outputShape, expectedOutput); |
| 304 | } |
| 305 | |
| 306 | template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>> |
| 307 | LayerTestResult<T, 4> BatchToSpaceNdNchwTest2( |
| 308 | armnn::IWorkloadFactory& workloadFactory, |
| 309 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
| 310 | { |
| 311 | const unsigned int inputShape[] = {4, 1, 1, 1}; |
| 312 | const unsigned int outputShape[] = {1, 1, 2, 2}; |
| 313 | |
| 314 | std::vector<float> input({ |
| 315 | // Batch 0, Height 0, Width (2) x Channel (1) |
| 316 | 1.0f, 2.0f, 3.0f, 4.0f |
| 317 | }); |
| 318 | |
| 319 | std::vector<float> expectedOutput({1.0f, 2.0f, 3.0f, 4.0f}); |
| 320 | |
| 321 | std::vector<unsigned int> blockShape({2, 2}); |
| 322 | std::vector<std::pair<unsigned int, unsigned int>> crops = {{0, 0}, {0, 0}}; |
| 323 | |
| 324 | return BatchToSpaceNdHelper<ArmnnType, 4, 4>(workloadFactory, memoryManager, |
| 325 | armnn::DataLayout::NCHW, inputShape, input, blockShape, |
| 326 | crops, outputShape, expectedOutput); |
| 327 | } |
| 328 | |
| 329 | template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>> |
| 330 | LayerTestResult<T, 4> BatchToSpaceNdNchwTest3( |
| 331 | armnn::IWorkloadFactory& workloadFactory, |
| 332 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
| 333 | { |
| 334 | const unsigned int inputShape[] = {4, 3, 1, 1}; |
| 335 | const unsigned int outputShape[] = {1, 3, 2, 2}; |
| 336 | |
| 337 | std::vector<float> input({1.0f, 3.0f, 5.0f, 7.0f, 9.0f, 11.0f, 2.0f, 4.0f, 6.0f, 8.0f, 10.0f, 12.0f}); |
| 338 | |
| 339 | std::vector<float> expectedOutput({ |
| 340 | // Batch 0, Channel 0, Height (2) x Width (2) |
| 341 | 1.0f, 7.0f, |
| 342 | 2.0f, 8.0f, |
| 343 | |
| 344 | // Batch 0, Channel 1, Height (2) x Width (2) |
| 345 | 3.0f, 9.0f, |
| 346 | 4.0f, 10.0f, |
| 347 | |
| 348 | // Batch 0, Channel 2, Height (2) x Width (2) |
| 349 | 5.0f, 11.0f, |
| 350 | 6.0f, 12.0f, |
| 351 | }); |
| 352 | |
| 353 | std::vector<unsigned int> blockShape({2, 2}); |
| 354 | std::vector<std::pair<unsigned int, unsigned int>> crops = {{0, 0}, {0, 0}}; |
| 355 | |
| 356 | return BatchToSpaceNdHelper<ArmnnType, 4, 4>(workloadFactory, memoryManager, |
| 357 | armnn::DataLayout::NCHW, inputShape, input, blockShape, |
| 358 | crops, outputShape, expectedOutput); |
| 359 | } |
| 360 | |
| 361 | template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>> |
| 362 | LayerTestResult<T, 4> BatchToSpaceNdNchwTest4( |
| 363 | armnn::IWorkloadFactory &workloadFactory, |
| 364 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
| 365 | { |
| 366 | const unsigned int inputShape[] = {4, 3, 1, 1}; |
| 367 | const unsigned int outputShape[] = {1, 3, 2, 2}; |
| 368 | |
| 369 | std::vector<float> input({1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}); |
| 370 | |
| 371 | std::vector<float> expectedOutput({ |
| 372 | // Batch 0, Channel 0, Height (2) x Width (2) |
| 373 | 1, 4, |
| 374 | 7, 10, |
| 375 | |
| 376 | // Batch 0, Channel 1, Height (2) x Width (2) |
| 377 | 2, 5, |
| 378 | 8, 11, |
| 379 | |
| 380 | // Batch 0, Channel 2, Height (2) x Width (2) |
| 381 | 3, 6, |
| 382 | 9, 12, |
| 383 | }); |
| 384 | |
| 385 | std::vector<unsigned int> blockShape({2, 2}); |
| 386 | std::vector<std::pair<unsigned int, unsigned int>> crops = {{0, 0}, {0, 0}}; |
| 387 | |
| 388 | return BatchToSpaceNdHelper<ArmnnType, 4, 4>(workloadFactory, memoryManager, |
| 389 | armnn::DataLayout::NCHW, inputShape, input, blockShape, |
| 390 | crops, outputShape, expectedOutput); |
| 391 | } |
| 392 | |
| 393 | template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>> |
| 394 | LayerTestResult<T, 4> BatchToSpaceNdNchwTest5( |
| 395 | armnn::IWorkloadFactory& workloadFactory, |
| 396 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
| 397 | { |
| 398 | const unsigned int inputShape[] = {4, 1, 1, 1}; |
| 399 | const unsigned int outputShape[] = {1, 1, 2, 2}; |
| 400 | |
| 401 | std::vector<float> input({ |
| 402 | // Batch 0, Height 0, Width (2) x Channel (1) |
| 403 | 1, 2, 3, 4 |
| 404 | }); |
| 405 | |
| 406 | std::vector<float> expectedOutput({1, 2, 3, 4}); |
| 407 | |
| 408 | std::vector<unsigned int> blockShape({2, 2}); |
| 409 | std::vector<std::pair<unsigned int, unsigned int>> crops = {{0, 0}, {0, 0}}; |
| 410 | |
| 411 | return BatchToSpaceNdHelper<ArmnnType, 4, 4>(workloadFactory, memoryManager, |
| 412 | armnn::DataLayout::NCHW, inputShape, input, blockShape, |
| 413 | crops, outputShape, expectedOutput); |
| 414 | } |
| 415 | |
| 416 | template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>> |
| 417 | LayerTestResult<T, 4> BatchToSpaceNdNchwTest6( |
| 418 | armnn::IWorkloadFactory& workloadFactory, |
| 419 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
| 420 | { |
| 421 | const unsigned int inputShape[] = {4, 3, 1, 1}; |
| 422 | const unsigned int outputShape[] = {1, 3, 2, 2}; |
| 423 | |
| 424 | std::vector<float> input({1, 3, 5, 7, 9, 11, 2, 4, 6, 8, 10, 12}); |
| 425 | |
| 426 | std::vector<float> expectedOutput({ |
| 427 | // Batch 0, Channel 0, Height (2) x Width (2) |
| 428 | 1, 7, |
| 429 | 2, 8, |
| 430 | |
| 431 | // Batch 0, Channel 1, Height (2) x Width (2) |
| 432 | 3, 9, |
| 433 | 4, 10, |
| 434 | |
| 435 | // Batch 0, Channel 2, Height (2) x Width (2) |
| 436 | 5, 11, |
| 437 | 6, 12, |
| 438 | }); |
| 439 | |
| 440 | std::vector<unsigned int> blockShape({2, 2}); |
| 441 | std::vector<std::pair<unsigned int, unsigned int>> crops = {{0, 0}, {0, 0}}; |
| 442 | |
| 443 | return BatchToSpaceNdHelper<ArmnnType, 4, 4>(workloadFactory, memoryManager, |
| 444 | armnn::DataLayout::NCHW, inputShape, input, blockShape, |
| 445 | crops, outputShape, expectedOutput); |
| 446 | } |
| 447 | |
| 448 | template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>> |
| 449 | LayerTestResult<T, 4> BatchToSpaceNdNchwTest7( |
| 450 | armnn::IWorkloadFactory& workloadFactory, |
| 451 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
| 452 | { |
| 453 | const unsigned int inputShape[] = {8, 1, 1, 3}; |
| 454 | const unsigned int outputShape[] = {2, 1, 2, 4}; |
| 455 | |
| 456 | std::vector<float> input({ |
| 457 | 0, 1, 3, 0, 9, 11, |
| 458 | 0, 2, 4, 0, 10, 12, |
| 459 | 0, 5, 7, 0, 13, 15, |
| 460 | 0, 6, 8, 0, 14, 16 |
| 461 | }); |
| 462 | |
| 463 | std::vector<float> expectedOutput({ |
| 464 | 1, 2, 3, 4, |
| 465 | 5, 6, 7, 8, |
| 466 | 9, 10, 11, 12, |
| 467 | 13, 14, 15, 16 |
| 468 | }); |
| 469 | |
| 470 | std::vector<unsigned int> blockShape({2, 2}); |
| 471 | std::vector<std::pair<unsigned int, unsigned int>> crops = {{0, 0}, {2, 0}}; |
| 472 | |
| 473 | return BatchToSpaceNdHelper<ArmnnType, 4, 4>(workloadFactory, memoryManager, |
| 474 | armnn::DataLayout::NCHW, inputShape, input, blockShape, |
| 475 | crops, outputShape, expectedOutput); |
| 476 | } |