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