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 | |
| 11 | #include <boost/test/unit_test.hpp> |
| 12 | |
| 13 | BOOST_AUTO_TEST_SUITE(TensorflowLiteParser) |
| 14 | |
| 15 | struct LoadScopeDynamicTensorFixture : public ParserFlatbuffersFixture |
| 16 | { |
| 17 | explicit LoadScopeDynamicTensorFixture(const std::string& shape0, |
| 18 | const std::string& shape1, |
| 19 | const std::string& shape2) |
| 20 | { |
| 21 | m_JsonString = R"( |
| 22 | { |
| 23 | "version": 3, |
| 24 | "operator_codes": [ |
| 25 | { |
| 26 | "builtin_code": "AVERAGE_POOL_2D", |
| 27 | "version": 1 |
| 28 | }, |
| 29 | { |
| 30 | "builtin_code": "SOFTMAX", |
| 31 | "version": 1 |
| 32 | } |
| 33 | ], |
| 34 | "subgraphs": [ |
| 35 | { |
| 36 | "tensors": [ |
| 37 | { |
| 38 | "shape": )" + shape0 + R"(, |
| 39 | "type": "FLOAT32", |
| 40 | "buffer": 1, |
| 41 | "name": "input0", |
| 42 | "quantization": { |
| 43 | "details_type": 0, |
| 44 | "quantized_dimension": 0 |
| 45 | }, |
| 46 | "is_variable": false |
| 47 | }, |
| 48 | { |
| 49 | "shape": )" + shape1 + R"(, |
| 50 | "type": "FLOAT32", |
| 51 | "buffer": 3, |
| 52 | "name": "output", |
| 53 | "quantization": { |
| 54 | "details_type": 0, |
| 55 | "quantized_dimension": 0 |
| 56 | }, |
| 57 | "is_variable": false |
| 58 | }, |
| 59 | { |
| 60 | "shape": )" + shape2 + R"(, |
| 61 | "type": "FLOAT32", |
| 62 | "buffer": 2, |
| 63 | "name": "model/average_pooling2d/AvgPool", |
| 64 | "quantization": { |
| 65 | "details_type": 0, |
| 66 | "quantized_dimension": 0 |
| 67 | }, |
| 68 | "is_variable": false |
| 69 | } |
| 70 | ], |
| 71 | "inputs": [ |
| 72 | 0 |
| 73 | ], |
| 74 | "outputs": [ |
| 75 | 1 |
| 76 | ], |
| 77 | "operators": [ |
| 78 | { |
| 79 | "opcode_index": 1, |
| 80 | "inputs": [ |
| 81 | 2 |
| 82 | ], |
| 83 | "outputs": [ |
| 84 | 1 |
| 85 | ], |
| 86 | "builtin_options_type": "SoftmaxOptions", |
| 87 | "builtin_options": { |
| 88 | "beta": 1.0 |
| 89 | }, |
| 90 | "custom_options_format": "FLEXBUFFERS" |
| 91 | }, |
| 92 | { |
| 93 | "opcode_index": 0, |
| 94 | "inputs": [ |
| 95 | 0 |
| 96 | ], |
| 97 | "outputs": [ |
| 98 | 2 |
| 99 | ], |
| 100 | "builtin_options_type": "Pool2DOptions", |
| 101 | "builtin_options": { |
| 102 | "padding": "VALID", |
| 103 | "stride_w": 2, |
| 104 | "stride_h": 2, |
| 105 | "filter_width": 2, |
| 106 | "filter_height": 2, |
| 107 | "fused_activation_function": "NONE" |
| 108 | }, |
| 109 | "custom_options_format": "FLEXBUFFERS" |
| 110 | } |
| 111 | ], |
| 112 | "name": "main" |
| 113 | } |
| 114 | ], |
| 115 | "description": "MLIR Converted.", |
| 116 | "buffers": [ |
| 117 | { |
| 118 | }, |
| 119 | { |
| 120 | }, |
| 121 | { |
| 122 | }, |
| 123 | { |
| 124 | } |
| 125 | ] |
| 126 | } |
| 127 | )"; |
| 128 | Setup(); |
| 129 | } |
| 130 | }; |
| 131 | |
| 132 | struct LoadScopeDynamicTensor0Fixture : LoadScopeDynamicTensorFixture |
| 133 | { |
| 134 | LoadScopeDynamicTensor0Fixture() : LoadScopeDynamicTensorFixture("[ 1, 2, 3, 2 ]", "[]", "[]") {} |
| 135 | }; |
| 136 | |
| 137 | struct LoadScopeDynamicTensor1Fixture : LoadScopeDynamicTensorFixture |
| 138 | { |
| 139 | LoadScopeDynamicTensor1Fixture() : LoadScopeDynamicTensorFixture("[ 1, 2, 4, 1 ]", "[ 1, 1, 2, 1 ]", "[]") {} |
| 140 | }; |
| 141 | |
| 142 | struct LoadScopeDynamicTensor2Fixture : LoadScopeDynamicTensorFixture |
| 143 | { |
| 144 | LoadScopeDynamicTensor2Fixture() : LoadScopeDynamicTensorFixture("[ 1, 3, 3, 2 ]", "[ ]", "[ 1, 1, 1, 2 ]") {} |
| 145 | }; |
| 146 | |
| 147 | BOOST_FIXTURE_TEST_CASE(LoadScopeDynamicTensor0, LoadScopeDynamicTensor0Fixture) |
| 148 | { |
| 149 | RunTest<4, armnn::DataType::Float32, armnn::DataType::Float32>( |
| 150 | 0, |
| 151 | { {"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 }} }, |
| 152 | { {"output", { 0.26894143f, 0.7310586f }} }, |
| 153 | true); |
| 154 | } |
| 155 | |
| 156 | BOOST_FIXTURE_TEST_CASE(LoadScopeDynamicTensor1, LoadScopeDynamicTensor1Fixture) |
| 157 | { |
| 158 | RunTest<4, armnn::DataType::Float32, armnn::DataType::Float32>( |
| 159 | 0, |
| 160 | { {"input0", { 0.f, 1.f, 2.f, 3.f, 4.f, 5.f, 6.f, 7.f }} }, |
| 161 | { {"output", { 1.f, 1.f }} }, |
| 162 | true); |
| 163 | } |
| 164 | |
| 165 | BOOST_FIXTURE_TEST_CASE(LoadScopeDynamicTensor2, LoadScopeDynamicTensor2Fixture) |
| 166 | { |
| 167 | RunTest<4, armnn::DataType::Float32, armnn::DataType::Float32>( |
| 168 | 0, |
| 169 | { {"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 }} }, |
| 170 | { {"output", { 0.7772999f, 0.22270015f }} }, |
| 171 | true); |
| 172 | } |
| 173 | |
| 174 | BOOST_AUTO_TEST_SUITE_END() |