Narumol Prangnawarat | bbf71a6 | 2020-09-07 14:05:22 +0100 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2020 Arm Ltd and Contributors. All rights reserved. |
| 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
| 6 | #include "armnnTfLiteParser/ITfLiteParser.hpp" |
| 7 | #include "ParserFlatbuffersFixture.hpp" |
| 8 | |
| 9 | #include <string> |
| 10 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 11 | TEST_SUITE("TensorflowLiteParser_LoadScopeDynamicTensor") |
| 12 | { |
Narumol Prangnawarat | bbf71a6 | 2020-09-07 14:05:22 +0100 | [diff] [blame] | 13 | struct LoadScopeDynamicTensorFixture : public ParserFlatbuffersFixture |
| 14 | { |
| 15 | explicit LoadScopeDynamicTensorFixture(const std::string& shape0, |
| 16 | const std::string& shape1, |
| 17 | const std::string& shape2) |
| 18 | { |
| 19 | m_JsonString = R"( |
| 20 | { |
| 21 | "version": 3, |
| 22 | "operator_codes": [ |
| 23 | { |
| 24 | "builtin_code": "AVERAGE_POOL_2D", |
| 25 | "version": 1 |
| 26 | }, |
| 27 | { |
| 28 | "builtin_code": "SOFTMAX", |
| 29 | "version": 1 |
| 30 | } |
| 31 | ], |
| 32 | "subgraphs": [ |
| 33 | { |
| 34 | "tensors": [ |
| 35 | { |
| 36 | "shape": )" + shape0 + R"(, |
| 37 | "type": "FLOAT32", |
| 38 | "buffer": 1, |
| 39 | "name": "input0", |
| 40 | "quantization": { |
| 41 | "details_type": 0, |
| 42 | "quantized_dimension": 0 |
| 43 | }, |
| 44 | "is_variable": false |
| 45 | }, |
| 46 | { |
| 47 | "shape": )" + shape1 + R"(, |
| 48 | "type": "FLOAT32", |
| 49 | "buffer": 3, |
| 50 | "name": "output", |
| 51 | "quantization": { |
| 52 | "details_type": 0, |
| 53 | "quantized_dimension": 0 |
| 54 | }, |
| 55 | "is_variable": false |
| 56 | }, |
| 57 | { |
| 58 | "shape": )" + shape2 + R"(, |
| 59 | "type": "FLOAT32", |
| 60 | "buffer": 2, |
| 61 | "name": "model/average_pooling2d/AvgPool", |
| 62 | "quantization": { |
| 63 | "details_type": 0, |
| 64 | "quantized_dimension": 0 |
| 65 | }, |
| 66 | "is_variable": false |
| 67 | } |
| 68 | ], |
| 69 | "inputs": [ |
| 70 | 0 |
| 71 | ], |
| 72 | "outputs": [ |
| 73 | 1 |
| 74 | ], |
| 75 | "operators": [ |
| 76 | { |
| 77 | "opcode_index": 1, |
| 78 | "inputs": [ |
| 79 | 2 |
| 80 | ], |
| 81 | "outputs": [ |
| 82 | 1 |
| 83 | ], |
| 84 | "builtin_options_type": "SoftmaxOptions", |
| 85 | "builtin_options": { |
| 86 | "beta": 1.0 |
| 87 | }, |
| 88 | "custom_options_format": "FLEXBUFFERS" |
| 89 | }, |
| 90 | { |
| 91 | "opcode_index": 0, |
| 92 | "inputs": [ |
| 93 | 0 |
| 94 | ], |
| 95 | "outputs": [ |
| 96 | 2 |
| 97 | ], |
| 98 | "builtin_options_type": "Pool2DOptions", |
| 99 | "builtin_options": { |
| 100 | "padding": "VALID", |
| 101 | "stride_w": 2, |
| 102 | "stride_h": 2, |
| 103 | "filter_width": 2, |
| 104 | "filter_height": 2, |
| 105 | "fused_activation_function": "NONE" |
| 106 | }, |
| 107 | "custom_options_format": "FLEXBUFFERS" |
| 108 | } |
| 109 | ], |
| 110 | "name": "main" |
| 111 | } |
| 112 | ], |
| 113 | "description": "MLIR Converted.", |
| 114 | "buffers": [ |
| 115 | { |
| 116 | }, |
| 117 | { |
| 118 | }, |
| 119 | { |
| 120 | }, |
| 121 | { |
| 122 | } |
| 123 | ] |
| 124 | } |
| 125 | )"; |
| 126 | Setup(); |
| 127 | } |
| 128 | }; |
| 129 | |
| 130 | struct LoadScopeDynamicTensor0Fixture : LoadScopeDynamicTensorFixture |
| 131 | { |
| 132 | LoadScopeDynamicTensor0Fixture() : LoadScopeDynamicTensorFixture("[ 1, 2, 3, 2 ]", "[]", "[]") {} |
| 133 | }; |
| 134 | |
| 135 | struct LoadScopeDynamicTensor1Fixture : LoadScopeDynamicTensorFixture |
| 136 | { |
| 137 | LoadScopeDynamicTensor1Fixture() : LoadScopeDynamicTensorFixture("[ 1, 2, 4, 1 ]", "[ 1, 1, 2, 1 ]", "[]") {} |
| 138 | }; |
| 139 | |
| 140 | struct LoadScopeDynamicTensor2Fixture : LoadScopeDynamicTensorFixture |
| 141 | { |
| 142 | LoadScopeDynamicTensor2Fixture() : LoadScopeDynamicTensorFixture("[ 1, 3, 3, 2 ]", "[ ]", "[ 1, 1, 1, 2 ]") {} |
| 143 | }; |
| 144 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 145 | TEST_CASE_FIXTURE(LoadScopeDynamicTensor0Fixture, "LoadScopeDynamicTensor0") |
Narumol Prangnawarat | bbf71a6 | 2020-09-07 14:05:22 +0100 | [diff] [blame] | 146 | { |
| 147 | RunTest<4, armnn::DataType::Float32, armnn::DataType::Float32>( |
| 148 | 0, |
| 149 | { {"input0", { 0.f, 1.f, 2.f, 3.f, 4.f, 5.f, 6.f, 7.f, 8.f, 9.f, 10.f, 11.f }} }, |
| 150 | { {"output", { 0.26894143f, 0.7310586f }} }, |
| 151 | true); |
| 152 | } |
| 153 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 154 | TEST_CASE_FIXTURE(LoadScopeDynamicTensor1Fixture, "LoadScopeDynamicTensor1") |
Narumol Prangnawarat | bbf71a6 | 2020-09-07 14:05:22 +0100 | [diff] [blame] | 155 | { |
| 156 | RunTest<4, armnn::DataType::Float32, armnn::DataType::Float32>( |
| 157 | 0, |
| 158 | { {"input0", { 0.f, 1.f, 2.f, 3.f, 4.f, 5.f, 6.f, 7.f }} }, |
| 159 | { {"output", { 1.f, 1.f }} }, |
| 160 | true); |
| 161 | } |
| 162 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 163 | TEST_CASE_FIXTURE(LoadScopeDynamicTensor2Fixture, "LoadScopeDynamicTensor2") |
Narumol Prangnawarat | bbf71a6 | 2020-09-07 14:05:22 +0100 | [diff] [blame] | 164 | { |
| 165 | RunTest<4, armnn::DataType::Float32, armnn::DataType::Float32>( |
| 166 | 0, |
| 167 | { {"input0", { 0.f, 1.f, 2.f, 3.f, 4.f, 5.f, 6.f, 7.f, 8.f, 0.f, 1.f, 2.f, 3.f, 4.f, 5.f, 6.f, 7.f, 8.f }} }, |
| 168 | { {"output", { 0.7772999f, 0.22270015f }} }, |
| 169 | true); |
| 170 | } |
| 171 | |
Narumol Prangnawarat | 16f82f9 | 2020-09-14 16:12:44 +0100 | [diff] [blame] | 172 | struct LoadScopeDynamicTensorBroadcastingFixture : public ParserFlatbuffersFixture |
| 173 | { |
| 174 | explicit LoadScopeDynamicTensorBroadcastingFixture(const std::string& inputShape0, |
| 175 | const std::string& inputShape1, |
| 176 | const std::string& inputShape2, |
| 177 | const std::string& addShape, |
| 178 | const std::string& outputShape) |
| 179 | { |
| 180 | m_JsonString = R"( |
| 181 | { |
| 182 | "version": 3, |
| 183 | "operator_codes": [ |
| 184 | { |
| 185 | "builtin_code": "ADD", |
| 186 | "version": 1 |
| 187 | }, |
| 188 | { |
| 189 | "builtin_code": "SUB", |
| 190 | "version": 1 |
| 191 | } |
| 192 | ], |
| 193 | "subgraphs": [ |
| 194 | { |
| 195 | "tensors": [ |
| 196 | { |
| 197 | "shape": )" + inputShape0 + R"(, |
| 198 | "type": "FLOAT32", |
| 199 | "buffer": 1, |
| 200 | "name": "input0", |
| 201 | "quantization": { |
| 202 | "details_type": 0, |
| 203 | "quantized_dimension": 0 |
| 204 | }, |
| 205 | "is_variable": false |
| 206 | }, |
| 207 | { |
| 208 | "shape": )" + inputShape1 + R"(, |
| 209 | "type": "FLOAT32", |
| 210 | "buffer": 2, |
| 211 | "name": "input1", |
| 212 | "quantization": { |
| 213 | "details_type": 0, |
| 214 | "quantized_dimension": 0 |
| 215 | }, |
| 216 | "is_variable": false |
| 217 | }, |
| 218 | { |
| 219 | "shape": )" + outputShape + R"(, |
| 220 | "type": "FLOAT32", |
| 221 | "buffer": 5, |
| 222 | "name": "output", |
| 223 | "quantization": { |
| 224 | "details_type": 0, |
| 225 | "quantized_dimension": 0 |
| 226 | }, |
| 227 | "is_variable": false |
| 228 | }, |
| 229 | |
| 230 | { |
| 231 | "shape": )" + addShape + R"(, |
| 232 | "type": "FLOAT32", |
| 233 | "buffer": 4, |
| 234 | "name": "model/add/add", |
| 235 | "quantization": { |
| 236 | "details_type": 0, |
| 237 | "quantized_dimension": 0 |
| 238 | }, |
| 239 | "is_variable": false |
| 240 | }, |
| 241 | { |
| 242 | "shape": )" + inputShape2 + R"(, |
| 243 | "type": "FLOAT32", |
| 244 | "buffer": 3, |
| 245 | "name": "input2", |
| 246 | "quantization": { |
| 247 | "details_type": 0, |
| 248 | "quantized_dimension": 0 |
| 249 | }, |
| 250 | "is_variable": false |
| 251 | }, |
| 252 | ], |
| 253 | "inputs": [ |
| 254 | 0, |
| 255 | 1, |
| 256 | 4 |
| 257 | ], |
| 258 | "outputs": [ |
| 259 | 2 |
| 260 | ], |
| 261 | "operators": [ |
| 262 | { |
| 263 | "opcode_index": 0, |
| 264 | "inputs": [ |
| 265 | 0, |
| 266 | 1 |
| 267 | ], |
| 268 | "outputs": [ |
| 269 | 3 |
| 270 | ], |
| 271 | "builtin_options_type": "AddOptions", |
| 272 | "builtin_options": { |
| 273 | "fused_activation_function": "NONE" |
| 274 | }, |
| 275 | "custom_options_format": "FLEXBUFFERS" |
| 276 | }, |
| 277 | { |
| 278 | "opcode_index": 1, |
| 279 | "inputs": [ |
| 280 | 3, |
| 281 | 4 |
| 282 | ], |
| 283 | "outputs": [ |
| 284 | 2 |
| 285 | ], |
| 286 | "builtin_options_type": "SubOptions", |
| 287 | "builtin_options": { |
| 288 | "fused_activation_function": "NONE" |
| 289 | }, |
| 290 | "custom_options_format": "FLEXBUFFERS" |
| 291 | } |
| 292 | ], |
| 293 | "name": "main" |
| 294 | } |
| 295 | ], |
| 296 | "buffers": [ |
| 297 | { |
| 298 | }, |
| 299 | { |
| 300 | }, |
| 301 | { |
| 302 | }, |
| 303 | { |
| 304 | }, |
| 305 | { |
| 306 | }, |
| 307 | { |
| 308 | } |
| 309 | ] |
| 310 | } |
| 311 | )"; |
| 312 | Setup(); |
| 313 | } |
| 314 | }; |
| 315 | |
| 316 | struct LoadScopeDynamicTensorBroadcasting3DFixture : LoadScopeDynamicTensorBroadcastingFixture |
| 317 | { |
| 318 | LoadScopeDynamicTensorBroadcasting3DFixture() : LoadScopeDynamicTensorBroadcastingFixture("[ 1, 2, 3, 2 ]", |
| 319 | "[ 2, 3, 2 ]", |
| 320 | "[ 2, 3, 2 ]", |
| 321 | "[ 1, 2, 3, 2 ]", "[]") {} |
| 322 | }; |
| 323 | |
| 324 | struct LoadScopeDynamicTensorBroadcasting2DFixture : LoadScopeDynamicTensorBroadcastingFixture |
| 325 | { |
| 326 | LoadScopeDynamicTensorBroadcasting2DFixture() : LoadScopeDynamicTensorBroadcastingFixture("[ 1, 2, 3, 2 ]", |
| 327 | "[ 3, 2 ]", |
| 328 | "[ 3, 2 ]", |
| 329 | "[]", "[]") {} |
| 330 | }; |
| 331 | |
| 332 | struct LoadScopeDynamicTensorBroadcasting1DFixture : LoadScopeDynamicTensorBroadcastingFixture |
| 333 | { |
| 334 | LoadScopeDynamicTensorBroadcasting1DFixture() : LoadScopeDynamicTensorBroadcastingFixture("[ 1, 2, 3, 2 ]", |
| 335 | "[ 1 ]", |
| 336 | "[ 1 ]", |
| 337 | "[]", |
| 338 | "[ 1, 2, 3, 2 ]") {} |
| 339 | }; |
| 340 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 341 | TEST_CASE_FIXTURE(LoadScopeDynamicTensorBroadcasting3DFixture, "LoadScopeDynamicTensorBroadcasting3D") |
Narumol Prangnawarat | 16f82f9 | 2020-09-14 16:12:44 +0100 | [diff] [blame] | 342 | { |
| 343 | RunTest<4, armnn::DataType::Float32, armnn::DataType::Float32>( |
| 344 | 0, |
| 345 | { {"input0", { 0.f, 1.f, 2.f, 3.f, 4.f, 5.f, 6.f, 7.f, 8.f, 9.f, 10.f, 11.f }}, |
| 346 | {"input1", { 3.f, 4.f, 5.f, 6.f, 7.f, 8.f, 9.f, 10.f, 11.f, 12.f, 13.f, 14.f }}, |
| 347 | {"input2", { 1.f, 2.f, 3.f, 4.f, 5.f, 6.f, 7.f, 8.f, 9.f, 10.f, 11.f, 12.f }} |
| 348 | }, |
| 349 | { {"output", { 2.f, 3.f, 4.f, 5.f, 6.f, 7.f, 8.f, 9.f, 10.f, 11.f, 12.f, 13.f }} }, |
| 350 | true); |
| 351 | } |
| 352 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 353 | TEST_CASE_FIXTURE(LoadScopeDynamicTensorBroadcasting2DFixture, "LoadScopeDynamicTensorBroadcasting2D") |
Narumol Prangnawarat | 16f82f9 | 2020-09-14 16:12:44 +0100 | [diff] [blame] | 354 | { |
| 355 | RunTest<4, armnn::DataType::Float32, armnn::DataType::Float32>( |
| 356 | 0, |
| 357 | { {"input0", { 0.f, 1.f, 2.f, 3.f, 4.f, 5.f, 6.f, 7.f, 8.f, 9.f, 10.f, 11.f }}, |
| 358 | {"input1", { 3.f, 4.f, 5.f, 6.f, 7.f, 8.f }}, |
| 359 | {"input2", { -1.f, -2.f, 3.f, 4.f, 5.f, 6.f }} |
| 360 | }, |
| 361 | { {"output", { 4.f, 7.f, 4.f, 5.f, 6.f, 7.f, 10.f, 13.f, 10.f, 11.f, 12.f, 13.f }} }, |
| 362 | true); |
| 363 | } |
| 364 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 365 | TEST_CASE_FIXTURE(LoadScopeDynamicTensorBroadcasting1DFixture, "LoadScopeDynamicTensorBroadcasting1D") |
Narumol Prangnawarat | 16f82f9 | 2020-09-14 16:12:44 +0100 | [diff] [blame] | 366 | { |
| 367 | RunTest<4, armnn::DataType::Float32, armnn::DataType::Float32>( |
| 368 | 0, |
| 369 | { {"input0", { 0.f, 1.f, 2.f, 3.f, 4.f, 5.f, 6.f, 7.f, 8.f, 9.f, 10.f, 11.f }}, |
| 370 | {"input1", { 5.f }}, |
| 371 | {"input2", { 1.f }} |
| 372 | }, |
| 373 | { {"output", { 4.f, 5.f, 6.f, 7.f, 8.f, 9.f, 10.f, 11.f, 12.f, 13.f, 14.f, 15.f }} }, |
| 374 | true); |
| 375 | } |
| 376 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 377 | } |