Ryan OShea | d21abaf | 2022-06-10 14:49:11 +0100 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2022 Arm Ltd and Contributors. All rights reserved. |
| 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
| 6 | #include "Pooling3dTestHelper.hpp" |
| 7 | |
| 8 | #include <armnn_delegate.hpp> |
| 9 | |
| 10 | #include <flatbuffers/flatbuffers.h> |
| 11 | #include <tensorflow/lite/interpreter.h> |
| 12 | #include <tensorflow/lite/kernels/register.h> |
| 13 | #include <tensorflow/lite/model.h> |
| 14 | #include <tensorflow/lite/schema/schema_generated.h> |
| 15 | #include <tensorflow/lite/version.h> |
| 16 | |
| 17 | #include <doctest/doctest.h> |
| 18 | |
| 19 | namespace armnnDelegate |
| 20 | { |
| 21 | |
| 22 | // Pool3D custom op was only added in tflite r2.6. |
| 23 | #if defined(ARMNN_POST_TFLITE_2_5) |
| 24 | |
| 25 | void MaxPool3dFP32PaddingValidTest(std::vector<armnn::BackendId>& backends) |
| 26 | { |
| 27 | // Set input and expected output data |
| 28 | std::vector<int32_t> inputShape = { 1, 2, 3, 4, 1 }; |
| 29 | std::vector<int32_t> outputShape = { 1, 1, 2, 3, 1 }; |
| 30 | |
| 31 | std::vector<float> inputValues = { 1, 2, 3, 4, 5, 6, |
| 32 | 1, 2, 3, 4, 5, 6, |
| 33 | 1, 2, 3, 4, 5, 6, |
| 34 | 1, 2, 3, 4, 5, 6 }; |
| 35 | std::vector<float> expectedOutputValues = { 6, 6, 4 }; |
| 36 | |
| 37 | // poolType string required to create the correct pooling operator |
| 38 | // Padding type required to create the padding in custom options |
| 39 | std::string poolType = "kMax"; |
| 40 | TfLitePadding padding = kTfLitePaddingValid; |
| 41 | |
| 42 | Pooling3dTest<float>(poolType, |
| 43 | ::tflite::TensorType_FLOAT32, |
| 44 | backends, |
| 45 | inputShape, |
| 46 | outputShape, |
| 47 | inputValues, |
| 48 | expectedOutputValues, |
| 49 | padding, |
| 50 | 1, |
| 51 | 1, |
| 52 | 1, |
| 53 | 2, |
| 54 | 2, |
| 55 | 2); |
| 56 | } |
| 57 | |
| 58 | void MaxPool3dFP32PaddingSameTest(std::vector<armnn::BackendId>& backends) |
| 59 | { |
| 60 | // Set input data and expected output data |
| 61 | std::vector<int32_t> inputShape = { 1, 2, 3, 4, 1 }; |
| 62 | std::vector<int32_t> outputShape = { 1, 2, 3, 4, 1 }; |
| 63 | |
| 64 | std::vector<float> inputValues = { 1, 2, 3, 4, 5, 6, |
| 65 | 1, 2, 3, 4, 5, 6, |
| 66 | 1, 2, 3, 4, 5, 6, |
| 67 | 1, 2, 3, 4, 5, 6 }; |
| 68 | std::vector<float> expectedOutputValues = { 6, 6, 4, 4, 6, 6, 6, 6, 4, 5, 6, 6, 6, 6, 4, 4 }; |
| 69 | |
| 70 | // poolType string required to create the correct pooling operator |
| 71 | // Padding type required to create the padding in custom options |
| 72 | std::string poolType = "kMax"; |
| 73 | TfLitePadding padding = kTfLitePaddingSame; |
| 74 | |
| 75 | Pooling3dTest<float>(poolType, |
| 76 | ::tflite::TensorType_FLOAT32, |
| 77 | backends, |
| 78 | inputShape, |
| 79 | outputShape, |
| 80 | inputValues, |
| 81 | expectedOutputValues, |
| 82 | padding, |
| 83 | 1, |
| 84 | 1, |
| 85 | 1, |
| 86 | 2, |
| 87 | 2, |
| 88 | 2); |
| 89 | } |
| 90 | |
| 91 | void MaxPool3dFP32H1Test(std::vector<armnn::BackendId>& backends) |
| 92 | { |
| 93 | // Set input data and expected output data |
| 94 | std::vector<int32_t> inputShape = { 1, 2, 3, 4, 1 }; |
| 95 | std::vector<int32_t> outputShape = { 1, 1, 3, 3, 1 }; |
| 96 | |
| 97 | std::vector<float> inputValues = { 1, 2, 3, 4, 5, 6, |
| 98 | 1, 2, 3, 4, 5, 6, |
| 99 | 1, 2, 3, 4, 5, 6, |
| 100 | 1, 2, 3, 4, 5, 6 }; |
| 101 | std::vector<float> expectedOutputValues = { 2, 3 }; |
| 102 | |
| 103 | // poolType string required to create the correct pooling operator |
| 104 | // Padding type required to create the padding in custom options |
| 105 | std::string poolType = "kMax"; |
| 106 | TfLitePadding padding = kTfLitePaddingValid; |
| 107 | |
| 108 | Pooling3dTest<float>(poolType, |
| 109 | ::tflite::TensorType_FLOAT32, |
| 110 | backends, |
| 111 | inputShape, |
| 112 | outputShape, |
| 113 | inputValues, |
| 114 | expectedOutputValues, |
| 115 | padding, |
| 116 | 1, |
| 117 | 1, |
| 118 | 1, |
| 119 | 2, |
| 120 | 1, |
| 121 | 2); |
| 122 | } |
| 123 | |
| 124 | void MaxPool3dFP32Test(std::vector<armnn::BackendId>& backends) |
| 125 | { |
| 126 | // Set input data and expected output data |
| 127 | std::vector<int32_t> inputShape = { 1, 2, 3, 4, 1 }; |
| 128 | std::vector<int32_t> outputShape = { 1, 2, 3, 4, 1 }; |
| 129 | |
| 130 | std::vector<float> inputValues = { 1, 2, 3, 4, 5, 6, |
| 131 | 1, 2, 3, 4, 5, 6, |
| 132 | 1, 2, 3, 4, 5, 6, |
| 133 | 1, 2, 3, 4, 5, 6 }; |
| 134 | std::vector<float> expectedOutputValues = { 6, 6 }; |
| 135 | |
| 136 | // poolType string required to create the correct pooling operator |
| 137 | // Padding type required to create the padding in custom options |
| 138 | std::string poolType = "kMax"; |
| 139 | TfLitePadding padding = kTfLitePaddingUnknown; |
| 140 | |
| 141 | Pooling3dTest<float>(poolType, |
| 142 | ::tflite::TensorType_FLOAT32, |
| 143 | backends, |
| 144 | inputShape, |
| 145 | outputShape, |
| 146 | inputValues, |
| 147 | expectedOutputValues, |
| 148 | padding, |
| 149 | 1, |
| 150 | 1, |
| 151 | 1, |
| 152 | 2, |
| 153 | 2, |
| 154 | 2); |
| 155 | } |
| 156 | |
| 157 | void AveragePool3dFP32PaddingValidTest(std::vector<armnn::BackendId>& backends) |
| 158 | { |
| 159 | // Set input data and expected output data. |
| 160 | std::vector<int32_t> inputShape = { 1, 2, 3, 4, 1 }; |
| 161 | std::vector<int32_t> outputShape = { 1, 1, 2, 3, 1 }; |
| 162 | |
| 163 | std::vector<float> inputValues = { 1, 2, 3, 4, 5, 6, |
| 164 | 1, 2, 3, 4, 5, 6, |
| 165 | 1, 2, 3, 4, 5, 6, |
| 166 | 1, 2, 3, 4, 5, 6 }; |
| 167 | std::vector<float> expectedOutputValues = { 3.5, 3, 2.5 }; |
| 168 | |
| 169 | // poolType string required to create the correct pooling operator |
| 170 | // Padding type required to create the padding in custom options |
| 171 | std::string poolType = "kAverage"; |
| 172 | TfLitePadding padding = kTfLitePaddingValid; |
| 173 | |
| 174 | Pooling3dTest<float>(poolType, |
| 175 | ::tflite::TensorType_FLOAT32, |
| 176 | backends, |
| 177 | inputShape, |
| 178 | outputShape, |
| 179 | inputValues, |
| 180 | expectedOutputValues, |
| 181 | padding, |
| 182 | 1, |
| 183 | 1, |
| 184 | 1, |
| 185 | 2, |
| 186 | 2, |
| 187 | 2); |
| 188 | } |
| 189 | |
| 190 | void AveragePool3dFP32PaddingSameTest(std::vector<armnn::BackendId>& backends) |
| 191 | { |
| 192 | // Set input data and expected output data |
| 193 | std::vector<int32_t> inputShape = { 4, 2, 3, 1, 1 }; |
| 194 | std::vector<int32_t> outputShape = { 4, 2, 3, 1, 1 }; |
| 195 | |
| 196 | std::vector<float> inputValues = { 1, 2, 3, 4, 5, 6, |
| 197 | 1, 2, 3, 4, 5, 6, |
| 198 | 1, 2, 3, 4, 5, 6, |
| 199 | 1, 2, 3, 4, 5, 6 }; |
| 200 | std::vector<float> expectedOutputValues = { 3, 4, 4.5, 4.5, 5.5, 6, 3, 4, 4.5, 4.5, 5.5, 6, 3, 4, 4.5, 4.5 }; |
| 201 | |
| 202 | // poolType string required to create the correct pooling operator |
| 203 | // Padding type required to create the padding in custom options |
| 204 | std::string poolType = "kAverage"; |
| 205 | TfLitePadding padding = kTfLitePaddingSame; |
| 206 | |
| 207 | Pooling3dTest<float>(poolType, |
| 208 | ::tflite::TensorType_FLOAT32, |
| 209 | backends, |
| 210 | inputShape, |
| 211 | outputShape, |
| 212 | inputValues, |
| 213 | expectedOutputValues, |
| 214 | padding, |
| 215 | 1, |
| 216 | 1, |
| 217 | 1, |
| 218 | 2, |
| 219 | 2, |
| 220 | 2); |
| 221 | } |
| 222 | |
| 223 | void AveragePool3dFP32H1Test(std::vector<armnn::BackendId>& backends) |
| 224 | { |
| 225 | // Set input data and expected output data |
| 226 | std::vector<int32_t> inputShape = { 1, 2, 3, 4, 1 }; |
| 227 | std::vector<int32_t> outputShape = { 1, 1, 2, 2, 1 }; |
| 228 | |
| 229 | std::vector<float> inputValues = { 1, 2, 3, 4, 5, 6, |
| 230 | 1, 2, 3, 4, 5, 6, |
| 231 | 1, 2, 3, 4, 5, 6, |
| 232 | 1, 2, 3, 4, 5, 6 }; |
| 233 | std::vector<float> expectedOutputValues = { 1.5, 3.5 }; |
| 234 | |
| 235 | // poolType string required to create the correct pooling operator |
| 236 | // Padding type required to create the padding in custom options |
| 237 | std::string poolType = "kAverage"; |
| 238 | TfLitePadding padding = kTfLitePaddingUnknown; |
| 239 | |
| 240 | Pooling3dTest<float>(poolType, |
| 241 | ::tflite::TensorType_FLOAT32, |
| 242 | backends, |
| 243 | inputShape, |
| 244 | outputShape, |
| 245 | inputValues, |
| 246 | expectedOutputValues, |
| 247 | padding, |
| 248 | 2, |
| 249 | 2, |
| 250 | 2, |
| 251 | 2, |
| 252 | 1, |
| 253 | 2); |
| 254 | } |
| 255 | |
| 256 | void AveragePool3dFP32Test(std::vector<armnn::BackendId>& backends) |
| 257 | { |
| 258 | // Set input data and expected output data |
| 259 | std::vector<int32_t> inputShape = { 4, 3, 2, 1, 1 }; |
| 260 | std::vector<int32_t> outputShape = { 1, 2, 2, 4, 1 }; |
| 261 | |
| 262 | std::vector<float> inputValues = { 1, 2, 3, 4, 5, 6, |
| 263 | 1, 2, 3, 4, 5, 6, |
| 264 | 1, 2, 3, 4, 5, 6, |
| 265 | 1, 2, 3, 4, 5, 6 }; |
| 266 | std::vector<float> expectedOutputValues = { 3.125, 4.25 }; |
| 267 | |
| 268 | // poolType string required to create the correct pooling operator |
| 269 | // Padding type required to create the padding in custom options |
| 270 | std::string poolType = "kMax"; |
| 271 | TfLitePadding padding = kTfLitePaddingUnknown; |
| 272 | |
| 273 | Pooling3dTest<float>(poolType, |
| 274 | ::tflite::TensorType_FLOAT32, |
| 275 | backends, |
| 276 | inputShape, |
| 277 | outputShape, |
| 278 | inputValues, |
| 279 | expectedOutputValues, |
| 280 | padding, |
| 281 | 2, |
| 282 | 2, |
| 283 | 2, |
| 284 | 2, |
| 285 | 2, |
| 286 | 2); |
| 287 | } |
| 288 | |
| 289 | TEST_SUITE("Pooling3d_GpuAccTests") |
| 290 | { |
| 291 | |
| 292 | TEST_CASE ("MaxPooling3d_FP32_GpuAcc_Test") |
| 293 | { |
| 294 | std::vector<armnn::BackendId> backends = { armnn::Compute::GpuAcc }; |
| 295 | MaxPool3dFP32Test(backends); |
| 296 | } |
| 297 | |
| 298 | TEST_CASE ("MaxPooling3d_FP32_PaddingValid_GpuAcc_Test") |
| 299 | { |
| 300 | std::vector<armnn::BackendId> backends = { armnn::Compute::GpuAcc }; |
| 301 | MaxPool3dFP32PaddingValidTest(backends); |
| 302 | } |
| 303 | |
| 304 | TEST_CASE ("MaxPooling3d_FP32_PaddingSame_GpuAcc_Test") |
| 305 | { |
| 306 | std::vector<armnn::BackendId> backends = { armnn::Compute::GpuAcc }; |
| 307 | MaxPool3dFP32PaddingSameTest(backends); |
| 308 | } |
| 309 | |
| 310 | TEST_CASE ("MaxPooling3d_FP32_H1_GpuAcc_Test") |
| 311 | { |
| 312 | std::vector<armnn::BackendId> backends = { armnn::Compute::GpuAcc }; |
| 313 | MaxPool3dFP32H1Test(backends); |
| 314 | } |
| 315 | |
| 316 | TEST_CASE ("AveragePooling3d_FP32_PaddingValid_GpuAcc_Test") |
| 317 | { |
| 318 | std::vector<armnn::BackendId> backends = { armnn::Compute::GpuAcc }; |
| 319 | AveragePool3dFP32PaddingValidTest(backends); |
| 320 | } |
| 321 | |
| 322 | TEST_CASE ("AveragePooling3d_FP32_PaddingSame_GpuAcc_Test") |
| 323 | { |
| 324 | std::vector<armnn::BackendId> backends = { armnn::Compute::GpuAcc }; |
| 325 | AveragePool3dFP32PaddingSameTest(backends); |
| 326 | } |
| 327 | |
| 328 | TEST_CASE ("AveragePooling3d_FP32_H1_GpuAcc_Test") |
| 329 | { |
| 330 | std::vector<armnn::BackendId> backends = { armnn::Compute::GpuAcc }; |
| 331 | AveragePool3dFP32H1Test(backends); |
| 332 | } |
| 333 | |
| 334 | } // TEST_SUITE("Pooling3d_GpuAccTests") |
| 335 | |
| 336 | TEST_SUITE("Pooling3d_CpuAccTests") |
| 337 | { |
| 338 | |
| 339 | TEST_CASE ("MaxPooling3d_FP32_PaddingValid_CpuAcc_Test") |
| 340 | { |
| 341 | std::vector<armnn::BackendId> backends = { armnn::Compute::CpuAcc }; |
| 342 | MaxPool3dFP32PaddingValidTest(backends); |
| 343 | } |
| 344 | |
| 345 | TEST_CASE ("MaxPooling3d_FP32_PaddingSame_CpuAcc_Test") |
| 346 | { |
| 347 | std::vector<armnn::BackendId> backends = { armnn::Compute::CpuAcc }; |
| 348 | MaxPool3dFP32PaddingSameTest(backends); |
| 349 | } |
| 350 | |
| 351 | TEST_CASE ("MaxPooling3d_FP32_CpuAcc_Test") |
| 352 | { |
| 353 | std::vector<armnn::BackendId> backends = { armnn::Compute::CpuAcc }; |
| 354 | MaxPool3dFP32Test(backends); |
| 355 | } |
| 356 | |
| 357 | TEST_CASE ("MaxPooling3d_FP32_H1_CpuAcc_Test") |
| 358 | { |
| 359 | std::vector<armnn::BackendId> backends = { armnn::Compute::CpuAcc }; |
| 360 | MaxPool3dFP32H1Test(backends); |
| 361 | } |
| 362 | |
| 363 | TEST_CASE ("AveragePooling3d_FP32_PaddingValid_CpuAcc_Test") |
| 364 | { |
| 365 | std::vector<armnn::BackendId> backends = { armnn::Compute::CpuAcc }; |
| 366 | AveragePool3dFP32PaddingValidTest(backends); |
| 367 | } |
| 368 | |
| 369 | TEST_CASE ("AveragePooling3d_FP32_PaddingSame_CpuAcc_Test") |
| 370 | { |
| 371 | std::vector<armnn::BackendId> backends = { armnn::Compute::CpuAcc }; |
| 372 | AveragePool3dFP32PaddingSameTest(backends); |
| 373 | } |
| 374 | |
| 375 | TEST_CASE ("AveragePooling3d_FP32_H1_CpuAcc_Test") |
| 376 | { |
| 377 | std::vector<armnn::BackendId> backends = { armnn::Compute::CpuAcc }; |
| 378 | AveragePool3dFP32H1Test(backends); |
| 379 | } |
| 380 | |
| 381 | } // TEST_SUITE("Pooling3d_CpuAccTests") |
| 382 | |
| 383 | TEST_SUITE("Pooling3d_CpuRefTests") |
| 384 | { |
| 385 | TEST_CASE ("MaxPooling3d_FP32_CpuRef_Test") |
| 386 | { |
| 387 | std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef }; |
| 388 | MaxPool3dFP32Test(backends); |
| 389 | } |
| 390 | |
| 391 | TEST_CASE ("MaxPooling3d_FP32_PaddingValid_CpuRef_Test") |
| 392 | { |
| 393 | std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef }; |
| 394 | MaxPool3dFP32PaddingValidTest(backends); |
| 395 | } |
| 396 | |
| 397 | TEST_CASE ("MaxPooling3d_FP32_PaddingSame_CpuRef_Test") |
| 398 | { |
| 399 | std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef }; |
| 400 | MaxPool3dFP32PaddingSameTest(backends); |
| 401 | } |
| 402 | |
| 403 | TEST_CASE ("MaxPooling3d_FP32_H1_CpuRef_Test") |
| 404 | { |
| 405 | std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef }; |
| 406 | MaxPool3dFP32H1Test(backends); |
| 407 | } |
| 408 | |
| 409 | TEST_CASE ("AveragePooling3d_FP32_PaddingValid_CpuRef_Test") |
| 410 | { |
| 411 | std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef }; |
| 412 | AveragePool3dFP32PaddingValidTest(backends); |
| 413 | } |
| 414 | |
| 415 | TEST_CASE ("AveragePooling3d_FP32_PaddingSame_CpuRef_Test") |
| 416 | { |
| 417 | std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef }; |
| 418 | AveragePool3dFP32PaddingSameTest(backends); |
| 419 | } |
| 420 | |
| 421 | TEST_CASE ("AveragePooling3d_FP32_H1_CpuRef_Test") |
| 422 | { |
| 423 | std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef }; |
| 424 | AveragePool3dFP32H1Test(backends); |
| 425 | } |
| 426 | |
| 427 | } // TEST_SUITE("Pooling3d_CpuRefTests") |
| 428 | |
| 429 | #endif |
| 430 | |
| 431 | } |