Sadik Armagan | 479045b | 2018-10-01 11:51:37 +0100 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2017 Arm Ltd. All rights reserved. |
| 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
Sadik Armagan | 479045b | 2018-10-01 11:51:37 +0100 | [diff] [blame] | 6 | #include "ParserFlatbuffersFixture.hpp" |
| 7 | #include "../TfLiteParser.hpp" |
| 8 | |
| 9 | #include <string> |
| 10 | #include <iostream> |
| 11 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame^] | 12 | TEST_SUITE("TensorflowLiteParser_Concatenation") |
| 13 | { |
Sadik Armagan | 479045b | 2018-10-01 11:51:37 +0100 | [diff] [blame] | 14 | struct ConcatenationFixture : public ParserFlatbuffersFixture |
| 15 | { |
| 16 | explicit ConcatenationFixture(const std::string & inputShape1, |
| 17 | const std::string & inputShape2, |
| 18 | const std::string & outputShape, |
| 19 | const std::string & axis, |
| 20 | const std::string & activation="NONE") |
| 21 | { |
| 22 | m_JsonString = R"( |
| 23 | { |
| 24 | "version": 3, |
| 25 | "operator_codes": [ { "builtin_code": "CONCATENATION" } ], |
| 26 | "subgraphs": [ { |
| 27 | "tensors": [ |
| 28 | { |
| 29 | "shape": )" + inputShape1 + R"(, |
| 30 | "type": "UINT8", |
| 31 | "buffer": 0, |
| 32 | "name": "inputTensor1", |
| 33 | "quantization": { |
| 34 | "min": [ 0.0 ], |
| 35 | "max": [ 255.0 ], |
| 36 | "scale": [ 1.0 ], |
| 37 | "zero_point": [ 0 ], |
| 38 | } |
| 39 | }, |
| 40 | { |
| 41 | "shape": )" + inputShape2 + R"(, |
| 42 | "type": "UINT8", |
| 43 | "buffer": 1, |
| 44 | "name": "inputTensor2", |
| 45 | "quantization": { |
| 46 | "min": [ 0.0 ], |
| 47 | "max": [ 255.0 ], |
| 48 | "scale": [ 1.0 ], |
| 49 | "zero_point": [ 0 ], |
| 50 | } |
| 51 | }, |
| 52 | { |
| 53 | "shape": )" + outputShape + R"( , |
| 54 | "type": "UINT8", |
| 55 | "buffer": 2, |
| 56 | "name": "outputTensor", |
| 57 | "quantization": { |
| 58 | "min": [ 0.0 ], |
| 59 | "max": [ 255.0 ], |
| 60 | "scale": [ 1.0 ], |
| 61 | "zero_point": [ 0 ], |
| 62 | } |
| 63 | } |
| 64 | ], |
| 65 | "inputs": [ 0, 1 ], |
| 66 | "outputs": [ 2 ], |
| 67 | "operators": [ |
| 68 | { |
| 69 | "opcode_index": 0, |
| 70 | "inputs": [ 0, 1 ], |
| 71 | "outputs": [ 2 ], |
| 72 | "builtin_options_type": "ConcatenationOptions", |
| 73 | "builtin_options": { |
| 74 | "axis": )" + axis + R"(, |
| 75 | "fused_activation_function": )" + activation + R"( |
| 76 | }, |
| 77 | "custom_options_format": "FLEXBUFFERS" |
| 78 | } |
| 79 | ], |
| 80 | } ], |
| 81 | "buffers" : [ |
| 82 | { }, |
| 83 | { } |
| 84 | ] |
| 85 | } |
| 86 | )"; |
| 87 | Setup(); |
| 88 | } |
| 89 | }; |
| 90 | |
| 91 | |
| 92 | struct ConcatenationFixtureNegativeDim : ConcatenationFixture |
| 93 | { |
| 94 | ConcatenationFixtureNegativeDim() : ConcatenationFixture("[ 1, 1, 2, 2 ]", |
| 95 | "[ 1, 1, 2, 2 ]", |
| 96 | "[ 1, 2, 2, 2 ]", |
| 97 | "-3" ) {} |
| 98 | }; |
| 99 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame^] | 100 | TEST_CASE_FIXTURE(ConcatenationFixtureNegativeDim, "ParseConcatenationNegativeDim") |
Sadik Armagan | 479045b | 2018-10-01 11:51:37 +0100 | [diff] [blame] | 101 | { |
Derek Lamberti | f90c56d | 2020-01-10 17:14:08 +0000 | [diff] [blame] | 102 | RunTest<4, armnn::DataType::QAsymmU8>( |
Nattapat Chaimanowong | 649dd95 | 2019-01-22 16:10:44 +0000 | [diff] [blame] | 103 | 0, |
| 104 | {{"inputTensor1", { 0, 1, 2, 3 }}, |
| 105 | {"inputTensor2", { 4, 5, 6, 7 }}}, |
| 106 | {{"outputTensor", { 0, 1, 2, 3, 4, 5, 6, 7 }}}); |
Sadik Armagan | 479045b | 2018-10-01 11:51:37 +0100 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | struct ConcatenationFixtureNCHW : ConcatenationFixture |
| 110 | { |
| 111 | ConcatenationFixtureNCHW() : ConcatenationFixture("[ 1, 1, 2, 2 ]", "[ 1, 1, 2, 2 ]", "[ 1, 2, 2, 2 ]", "1" ) {} |
| 112 | }; |
| 113 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame^] | 114 | TEST_CASE_FIXTURE(ConcatenationFixtureNCHW, "ParseConcatenationNCHW") |
Sadik Armagan | 479045b | 2018-10-01 11:51:37 +0100 | [diff] [blame] | 115 | { |
Derek Lamberti | f90c56d | 2020-01-10 17:14:08 +0000 | [diff] [blame] | 116 | RunTest<4, armnn::DataType::QAsymmU8>( |
Nattapat Chaimanowong | 649dd95 | 2019-01-22 16:10:44 +0000 | [diff] [blame] | 117 | 0, |
| 118 | {{"inputTensor1", { 0, 1, 2, 3 }}, |
| 119 | {"inputTensor2", { 4, 5, 6, 7 }}}, |
| 120 | {{"outputTensor", { 0, 1, 2, 3, 4, 5, 6, 7 }}}); |
Sadik Armagan | 479045b | 2018-10-01 11:51:37 +0100 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | struct ConcatenationFixtureNHWC : ConcatenationFixture |
| 124 | { |
| 125 | ConcatenationFixtureNHWC() : ConcatenationFixture("[ 1, 1, 2, 2 ]", "[ 1, 1, 2, 2 ]", "[ 1, 1, 2, 4 ]", "3" ) {} |
| 126 | }; |
| 127 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame^] | 128 | TEST_CASE_FIXTURE(ConcatenationFixtureNHWC, "ParseConcatenationNHWC") |
Sadik Armagan | 479045b | 2018-10-01 11:51:37 +0100 | [diff] [blame] | 129 | { |
Derek Lamberti | f90c56d | 2020-01-10 17:14:08 +0000 | [diff] [blame] | 130 | RunTest<4, armnn::DataType::QAsymmU8>( |
Nattapat Chaimanowong | 649dd95 | 2019-01-22 16:10:44 +0000 | [diff] [blame] | 131 | 0, |
| 132 | {{"inputTensor1", { 0, 1, 2, 3 }}, |
| 133 | {"inputTensor2", { 4, 5, 6, 7 }}}, |
| 134 | {{"outputTensor", { 0, 1, 4, 5, 2, 3, 6, 7 }}}); |
Sadik Armagan | 479045b | 2018-10-01 11:51:37 +0100 | [diff] [blame] | 135 | } |
| 136 | |
| 137 | struct ConcatenationFixtureDim1 : ConcatenationFixture |
| 138 | { |
| 139 | ConcatenationFixtureDim1() : ConcatenationFixture("[ 1, 2, 3, 4 ]", "[ 1, 2, 3, 4 ]", "[ 1, 4, 3, 4 ]", "1" ) {} |
| 140 | }; |
| 141 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame^] | 142 | TEST_CASE_FIXTURE(ConcatenationFixtureDim1, "ParseConcatenationDim1") |
Sadik Armagan | 479045b | 2018-10-01 11:51:37 +0100 | [diff] [blame] | 143 | { |
Derek Lamberti | f90c56d | 2020-01-10 17:14:08 +0000 | [diff] [blame] | 144 | RunTest<4, armnn::DataType::QAsymmU8>( |
Nattapat Chaimanowong | 649dd95 | 2019-01-22 16:10:44 +0000 | [diff] [blame] | 145 | 0, |
| 146 | { { "inputTensor1", { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, |
| 147 | 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23 } }, |
| 148 | { "inputTensor2", { 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, |
| 149 | 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73 } } }, |
| 150 | { { "outputTensor", { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, |
| 151 | 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, |
| 152 | 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, |
| 153 | 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73 } } }); |
Sadik Armagan | 479045b | 2018-10-01 11:51:37 +0100 | [diff] [blame] | 154 | } |
| 155 | |
| 156 | struct ConcatenationFixtureDim3 : ConcatenationFixture |
| 157 | { |
| 158 | ConcatenationFixtureDim3() : ConcatenationFixture("[ 1, 2, 3, 4 ]", "[ 1, 2, 3, 4 ]", "[ 1, 2, 3, 8 ]", "3" ) {} |
| 159 | }; |
| 160 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame^] | 161 | TEST_CASE_FIXTURE(ConcatenationFixtureDim3, "ParseConcatenationDim3") |
Sadik Armagan | 479045b | 2018-10-01 11:51:37 +0100 | [diff] [blame] | 162 | { |
Derek Lamberti | f90c56d | 2020-01-10 17:14:08 +0000 | [diff] [blame] | 163 | RunTest<4, armnn::DataType::QAsymmU8>( |
Nattapat Chaimanowong | 649dd95 | 2019-01-22 16:10:44 +0000 | [diff] [blame] | 164 | 0, |
| 165 | { { "inputTensor1", { 0, 1, 2, 3, |
| 166 | 4, 5, 6, 7, |
| 167 | 8, 9, 10, 11, |
| 168 | 12, 13, 14, 15, |
| 169 | 16, 17, 18, 19, |
| 170 | 20, 21, 22, 23 } }, |
| 171 | { "inputTensor2", { 50, 51, 52, 53, |
| 172 | 54, 55, 56, 57, |
| 173 | 58, 59, 60, 61, |
| 174 | 62, 63, 64, 65, |
| 175 | 66, 67, 68, 69, |
| 176 | 70, 71, 72, 73 } } }, |
| 177 | { { "outputTensor", { 0, 1, 2, 3, |
| 178 | 50, 51, 52, 53, |
| 179 | 4, 5, 6, 7, |
| 180 | 54, 55, 56, 57, |
| 181 | 8, 9, 10, 11, |
| 182 | 58, 59, 60, 61, |
| 183 | 12, 13, 14, 15, |
| 184 | 62, 63, 64, 65, |
| 185 | 16, 17, 18, 19, |
| 186 | 66, 67, 68, 69, |
| 187 | 20, 21, 22, 23, |
| 188 | 70, 71, 72, 73 } } }); |
Sadik Armagan | 479045b | 2018-10-01 11:51:37 +0100 | [diff] [blame] | 189 | } |
| 190 | |
Nattapat Chaimanowong | 5e9d298 | 2019-01-25 13:20:39 +0000 | [diff] [blame] | 191 | struct ConcatenationFixture3DDim0 : ConcatenationFixture |
| 192 | { |
| 193 | ConcatenationFixture3DDim0() : ConcatenationFixture("[ 1, 2, 3]", "[ 2, 2, 3]", "[ 3, 2, 3]", "0" ) {} |
| 194 | }; |
| 195 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame^] | 196 | TEST_CASE_FIXTURE(ConcatenationFixture3DDim0, "ParseConcatenation3DDim0") |
Nattapat Chaimanowong | 5e9d298 | 2019-01-25 13:20:39 +0000 | [diff] [blame] | 197 | { |
Derek Lamberti | f90c56d | 2020-01-10 17:14:08 +0000 | [diff] [blame] | 198 | RunTest<3, armnn::DataType::QAsymmU8>( |
Nattapat Chaimanowong | 5e9d298 | 2019-01-25 13:20:39 +0000 | [diff] [blame] | 199 | 0, |
| 200 | { { "inputTensor1", { 0, 1, 2, 3, 4, 5 } }, |
| 201 | { "inputTensor2", { 6, 7, 8, 9, 10, 11, |
| 202 | 12, 13, 14, 15, 16, 17 } } }, |
| 203 | { { "outputTensor", { 0, 1, 2, 3, 4, 5, |
| 204 | 6, 7, 8, 9, 10, 11, |
| 205 | 12, 13, 14, 15, 16, 17 } } }); |
| 206 | } |
| 207 | |
| 208 | struct ConcatenationFixture3DDim1 : ConcatenationFixture |
| 209 | { |
| 210 | ConcatenationFixture3DDim1() : ConcatenationFixture("[ 1, 2, 3]", "[ 1, 4, 3]", "[ 1, 6, 3]", "1" ) {} |
| 211 | }; |
| 212 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame^] | 213 | TEST_CASE_FIXTURE(ConcatenationFixture3DDim1, "ParseConcatenation3DDim1") |
Nattapat Chaimanowong | 5e9d298 | 2019-01-25 13:20:39 +0000 | [diff] [blame] | 214 | { |
Derek Lamberti | f90c56d | 2020-01-10 17:14:08 +0000 | [diff] [blame] | 215 | RunTest<3, armnn::DataType::QAsymmU8>( |
Nattapat Chaimanowong | 5e9d298 | 2019-01-25 13:20:39 +0000 | [diff] [blame] | 216 | 0, |
| 217 | { { "inputTensor1", { 0, 1, 2, 3, 4, 5 } }, |
| 218 | { "inputTensor2", { 6, 7, 8, 9, 10, 11, |
| 219 | 12, 13, 14, 15, 16, 17 } } }, |
| 220 | { { "outputTensor", { 0, 1, 2, 3, 4, 5, |
| 221 | 6, 7, 8, 9, 10, 11, |
| 222 | 12, 13, 14, 15, 16, 17 } } }); |
| 223 | } |
| 224 | |
| 225 | struct ConcatenationFixture3DDim2 : ConcatenationFixture |
| 226 | { |
| 227 | ConcatenationFixture3DDim2() : ConcatenationFixture("[ 1, 2, 3]", "[ 1, 2, 6]", "[ 1, 2, 9]", "2" ) {} |
| 228 | }; |
| 229 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame^] | 230 | TEST_CASE_FIXTURE(ConcatenationFixture3DDim2, "ParseConcatenation3DDim2") |
Nattapat Chaimanowong | 5e9d298 | 2019-01-25 13:20:39 +0000 | [diff] [blame] | 231 | { |
Derek Lamberti | f90c56d | 2020-01-10 17:14:08 +0000 | [diff] [blame] | 232 | RunTest<3, armnn::DataType::QAsymmU8>( |
Nattapat Chaimanowong | 5e9d298 | 2019-01-25 13:20:39 +0000 | [diff] [blame] | 233 | 0, |
| 234 | { { "inputTensor1", { 0, 1, 2, |
| 235 | 3, 4, 5 } }, |
| 236 | { "inputTensor2", { 6, 7, 8, 9, 10, 11, |
| 237 | 12, 13, 14, 15, 16, 17 } } }, |
| 238 | { { "outputTensor", { 0, 1, 2, 6, 7, 8, 9, 10, 11, |
| 239 | 3, 4, 5, 12, 13, 14, 15, 16, 17 } } }); |
| 240 | } |
| 241 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame^] | 242 | } |