Mike Kelly | a0766c3 | 2019-02-19 17:22:07 +0000 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2017 Arm Ltd. All rights reserved. |
| 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
Mike Kelly | a0766c3 | 2019-02-19 17:22:07 +0000 | [diff] [blame] | 6 | #include "ParserFlatbuffersSerializeFixture.hpp" |
Finn Williams | 85d3671 | 2021-01-26 22:30:06 +0000 | [diff] [blame] | 7 | #include <armnnDeserializer/IDeserializer.hpp> |
Mike Kelly | a0766c3 | 2019-02-19 17:22:07 +0000 | [diff] [blame] | 8 | |
| 9 | #include <string> |
Mike Kelly | a0766c3 | 2019-02-19 17:22:07 +0000 | [diff] [blame] | 10 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 11 | TEST_SUITE("Deserializer_Convolution2D") |
| 12 | { |
Mike Kelly | a0766c3 | 2019-02-19 17:22:07 +0000 | [diff] [blame] | 13 | struct Convolution2dFixture : public ParserFlatbuffersSerializeFixture |
| 14 | { |
| 15 | explicit Convolution2dFixture(const std::string & inputShape1, |
| 16 | const std::string & outputShape, |
| 17 | const std::string & weightsShape, |
| 18 | const std::string & dataType) |
| 19 | { |
| 20 | m_JsonString = R"( |
| 21 | { |
| 22 | inputIds: [0], |
| 23 | outputIds: [2], |
| 24 | layers: [{ |
| 25 | layer_type: "InputLayer", |
| 26 | layer: { |
| 27 | base: { |
| 28 | layerBindingId: 0, |
| 29 | base: { |
| 30 | index: 0, |
| 31 | layerName: "InputLayer", |
| 32 | layerType: "Input", |
| 33 | inputSlots: [{ |
| 34 | index: 0, |
| 35 | connection: {sourceLayerIndex:0, outputSlotIndex:0 }, |
| 36 | }], |
| 37 | outputSlots: [{ |
| 38 | index: 0, |
| 39 | tensorInfo: { |
| 40 | dimensions: )" + inputShape1 + R"(, |
| 41 | dataType: )" + dataType + R"(, |
| 42 | quantizationScale: 0.5, |
| 43 | quantizationOffset: 0 |
| 44 | }, |
| 45 | }] |
| 46 | }, |
| 47 | } |
| 48 | }, |
| 49 | }, |
| 50 | { |
| 51 | layer_type: "Convolution2dLayer", |
| 52 | layer : { |
| 53 | base: { |
| 54 | index:1, |
| 55 | layerName: "Convolution2dLayer", |
| 56 | layerType: "Convolution2d", |
| 57 | inputSlots: [{ |
| 58 | index: 0, |
| 59 | connection: {sourceLayerIndex:0, outputSlotIndex:0 }, |
| 60 | }], |
| 61 | outputSlots: [{ |
| 62 | index: 0, |
| 63 | tensorInfo: { |
| 64 | dimensions: )" + outputShape + R"(, |
| 65 | dataType: )" + dataType + R"( |
| 66 | }, |
| 67 | }], |
| 68 | }, |
| 69 | descriptor: { |
| 70 | padLeft: 1, |
| 71 | padRight: 1, |
| 72 | padTop: 1, |
| 73 | padBottom: 1, |
| 74 | strideX: 2, |
| 75 | strideY: 2, |
| 76 | biasEnabled: false, |
| 77 | dataLayout: NHWC |
| 78 | }, |
| 79 | weights: { |
| 80 | info: { |
| 81 | dimensions: )" + weightsShape + R"(, |
| 82 | dataType: )" + dataType + R"( |
| 83 | }, |
| 84 | data_type: IntData, |
| 85 | data: { |
| 86 | data: [ |
| 87 | 1082130432, 1084227584, 1086324736, |
| 88 | 0 ,0 ,0 , |
| 89 | 1077936128, 1073741824, 1065353216 |
| 90 | ], |
| 91 | } |
| 92 | } |
| 93 | }, |
| 94 | }, |
| 95 | { |
| 96 | layer_type: "OutputLayer", |
| 97 | layer: { |
| 98 | base:{ |
| 99 | layerBindingId: 0, |
| 100 | base: { |
| 101 | index: 2, |
| 102 | layerName: "OutputLayer", |
| 103 | layerType: "Output", |
| 104 | inputSlots: [{ |
| 105 | index: 0, |
| 106 | connection: {sourceLayerIndex:1, outputSlotIndex:0 }, |
| 107 | }], |
| 108 | outputSlots: [ { |
| 109 | index: 0, |
| 110 | tensorInfo: { |
| 111 | dimensions: )" + outputShape + R"(, |
| 112 | dataType: )" + dataType + R"( |
| 113 | }, |
| 114 | }], |
| 115 | } |
| 116 | }}, |
| 117 | }] |
| 118 | } |
| 119 | )"; |
| 120 | Setup(); |
| 121 | } |
| 122 | }; |
| 123 | |
Keith Davis | b4dd5cc | 2022-04-07 11:32:00 +0100 | [diff] [blame] | 124 | struct Convolution2dFixtureConstantAsInput : public ParserFlatbuffersSerializeFixture |
| 125 | { |
| 126 | explicit Convolution2dFixtureConstantAsInput(const std::string & inputShape1, |
| 127 | const std::string & outputShape, |
| 128 | const std::string & weightsShape, |
| 129 | const std::string & dataType) |
| 130 | { |
| 131 | m_JsonString = R"( |
| 132 | { |
| 133 | inputIds: [0], |
| 134 | outputIds: [3], |
| 135 | layers: [{ |
| 136 | layer_type: "InputLayer", |
| 137 | layer: { |
| 138 | base: { |
| 139 | layerBindingId: 0, |
| 140 | base: { |
| 141 | index: 0, |
| 142 | layerName: "InputLayer", |
| 143 | layerType: "Input", |
| 144 | inputSlots: [{ |
| 145 | index: 0, |
| 146 | connection: {sourceLayerIndex:0, outputSlotIndex:0 }, |
| 147 | }], |
| 148 | outputSlots: [{ |
| 149 | index: 0, |
| 150 | tensorInfo: { |
| 151 | dimensions: )" + inputShape1 + R"(, |
| 152 | dataType: )" + dataType + R"(, |
| 153 | quantizationScale: 0.5, |
| 154 | quantizationOffset: 0 |
| 155 | }, |
| 156 | }] |
| 157 | }, |
| 158 | } |
| 159 | }, |
| 160 | }, |
| 161 | { |
| 162 | layer_type: "Convolution2dLayer", |
| 163 | layer : { |
| 164 | base: { |
| 165 | index:1, |
| 166 | layerName: "Convolution2dLayer", |
| 167 | layerType: "Convolution2d", |
| 168 | inputSlots: [ |
| 169 | { |
| 170 | index: 0, |
| 171 | connection: {sourceLayerIndex:0, outputSlotIndex:0 }, |
| 172 | }, |
| 173 | { |
| 174 | index: 1, |
| 175 | connection: { |
| 176 | sourceLayerIndex: 2, |
| 177 | outputSlotIndex: 0 |
| 178 | } |
| 179 | } |
| 180 | ], |
| 181 | outputSlots: [ |
| 182 | { |
| 183 | index: 0, |
| 184 | tensorInfo: { |
| 185 | dimensions: )" + outputShape + R"(, |
| 186 | dataType: )" + dataType + R"( |
| 187 | }, |
| 188 | } |
| 189 | ], |
| 190 | }, |
| 191 | descriptor: { |
| 192 | padLeft: 1, |
| 193 | padRight: 1, |
| 194 | padTop: 1, |
| 195 | padBottom: 1, |
| 196 | strideX: 2, |
| 197 | strideY: 2, |
| 198 | biasEnabled: false, |
| 199 | dataLayout: NHWC |
| 200 | } |
| 201 | } |
| 202 | }, |
| 203 | { |
| 204 | layer_type: "ConstantLayer", |
| 205 | layer: { |
| 206 | base: { |
| 207 | index: 2, |
| 208 | layerName: "Weights", |
| 209 | layerType: "Constant", |
| 210 | inputSlots: [ |
| 211 | |
| 212 | ], |
| 213 | outputSlots: [ |
| 214 | { |
| 215 | index: 0, |
| 216 | tensorInfo: { |
| 217 | dimensions: )" + weightsShape + R"(, |
| 218 | dataType: )" + dataType + R"(, |
| 219 | quantizationScale: 0.1, |
| 220 | dimensionSpecificity: [ |
| 221 | true, |
| 222 | true, |
| 223 | true, |
| 224 | true |
| 225 | ] |
| 226 | } |
| 227 | } |
| 228 | ] |
| 229 | }, |
| 230 | input: { |
| 231 | info: { |
| 232 | dimensions: )" + weightsShape + R"(, |
| 233 | dataType: )" + dataType + R"(, |
| 234 | quantizationScale: 0.1, |
| 235 | dimensionSpecificity: [ |
| 236 | true, |
| 237 | true, |
| 238 | true, |
| 239 | true |
| 240 | ] |
| 241 | }, |
| 242 | data_type: "IntData", |
| 243 | data: { |
| 244 | data: [ |
| 245 | 1082130432, 1084227584, 1086324736, |
| 246 | 0 ,0 ,0 , |
| 247 | 1077936128, 1073741824, 1065353216 |
| 248 | ] |
| 249 | } |
| 250 | } |
| 251 | } |
| 252 | }, |
| 253 | { |
| 254 | layer_type: "OutputLayer", |
| 255 | layer: { |
| 256 | base:{ |
| 257 | layerBindingId: 0, |
| 258 | base: { |
| 259 | index: 3, |
| 260 | layerName: "OutputLayer", |
| 261 | layerType: "Output", |
| 262 | inputSlots: [{ |
| 263 | index: 0, |
| 264 | "connection": { |
| 265 | "sourceLayerIndex": 1, |
| 266 | "outputSlotIndex": 0 |
| 267 | } |
| 268 | }], |
| 269 | outputSlots: [ { |
| 270 | index: 0, |
| 271 | tensorInfo: { |
| 272 | dimensions: )" + outputShape + R"(, |
| 273 | dataType: )" + dataType + R"( |
| 274 | }, |
| 275 | }], |
| 276 | } |
| 277 | }}, |
| 278 | }], |
| 279 | "featureVersions": { |
| 280 | "constantTensorsAsInputs": 1, |
| 281 | "weightsLayoutScheme": 1 |
| 282 | } |
| 283 | } |
| 284 | )"; |
| 285 | Setup(); |
| 286 | } |
| 287 | }; |
| 288 | |
Mike Kelly | a0766c3 | 2019-02-19 17:22:07 +0000 | [diff] [blame] | 289 | struct SimpleConvolution2dFixture : Convolution2dFixture |
| 290 | { |
| 291 | SimpleConvolution2dFixture() : Convolution2dFixture("[ 1, 5, 5, 1 ]", |
| 292 | "[ 1, 3, 3, 1 ]", |
| 293 | "[ 1, 3, 3, 1 ]", |
| 294 | "Float32") {} |
| 295 | }; |
| 296 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 297 | TEST_CASE_FIXTURE(SimpleConvolution2dFixture, "Convolution2dFloat32") |
Mike Kelly | a0766c3 | 2019-02-19 17:22:07 +0000 | [diff] [blame] | 298 | { |
| 299 | RunTest<4, armnn::DataType::Float32>( |
| 300 | 0, |
| 301 | {{"InputLayer", {1, 5, 2, 3, 5, 8, 7, 3, 6, 3, 3, 3, 9, 1, 9, 4, 1, 8, 1, 3, 6, 8, 1, 9, 2}}}, |
| 302 | {{"OutputLayer", {23, 33, 24, 91, 99, 48, 26, 50, 19}}}); |
| 303 | } |
| 304 | |
Keith Davis | b4dd5cc | 2022-04-07 11:32:00 +0100 | [diff] [blame] | 305 | |
| 306 | struct SimpleConvolution2dFixtureConstantAsInput : Convolution2dFixtureConstantAsInput |
| 307 | { |
| 308 | SimpleConvolution2dFixtureConstantAsInput() : Convolution2dFixtureConstantAsInput("[ 1, 5, 5, 1 ]", |
| 309 | "[ 1, 3, 3, 1 ]", |
| 310 | "[ 1, 3, 3, 1 ]", |
| 311 | "Float32") {} |
| 312 | }; |
| 313 | |
| 314 | TEST_CASE_FIXTURE(SimpleConvolution2dFixtureConstantAsInput, "Convolution2dFloat32ConstAsInput") |
| 315 | { |
| 316 | RunTest<4, armnn::DataType::Float32>( |
| 317 | 0, |
| 318 | {{"InputLayer", {1, 5, 2, 3, 5, 8, 7, 3, 6, 3, 3, 3, 9, 1, 9, 4, 1, 8, 1, 3, 6, 8, 1, 9, 2}}}, |
| 319 | {{"OutputLayer", {23, 33, 24, 91, 99, 48, 26, 50, 19}}}); |
| 320 | } |
| 321 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 322 | } |