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