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 | |
| 6 | #include <boost/test/unit_test.hpp> |
| 7 | #include "ParserFlatbuffersSerializeFixture.hpp" |
Derek Lamberti | 0028d1b | 2019-02-20 13:57:42 +0000 | [diff] [blame] | 8 | #include "../Deserializer.hpp" |
Mike Kelly | a0766c3 | 2019-02-19 17:22:07 +0000 | [diff] [blame] | 9 | |
| 10 | #include <string> |
| 11 | #include <iostream> |
| 12 | |
Derek Lamberti | 0028d1b | 2019-02-20 13:57:42 +0000 | [diff] [blame] | 13 | BOOST_AUTO_TEST_SUITE(Deserializer) |
Mike Kelly | a0766c3 | 2019-02-19 17:22:07 +0000 | [diff] [blame] | 14 | |
| 15 | struct Convolution2dFixture : public ParserFlatbuffersSerializeFixture |
| 16 | { |
| 17 | explicit Convolution2dFixture(const std::string & inputShape1, |
| 18 | const std::string & outputShape, |
| 19 | const std::string & weightsShape, |
| 20 | const std::string & dataType) |
| 21 | { |
| 22 | m_JsonString = R"( |
| 23 | { |
| 24 | inputIds: [0], |
| 25 | outputIds: [2], |
| 26 | layers: [{ |
| 27 | layer_type: "InputLayer", |
| 28 | layer: { |
| 29 | base: { |
| 30 | layerBindingId: 0, |
| 31 | base: { |
| 32 | index: 0, |
| 33 | layerName: "InputLayer", |
| 34 | layerType: "Input", |
| 35 | inputSlots: [{ |
| 36 | index: 0, |
| 37 | connection: {sourceLayerIndex:0, outputSlotIndex:0 }, |
| 38 | }], |
| 39 | outputSlots: [{ |
| 40 | index: 0, |
| 41 | tensorInfo: { |
| 42 | dimensions: )" + inputShape1 + R"(, |
| 43 | dataType: )" + dataType + R"(, |
| 44 | quantizationScale: 0.5, |
| 45 | quantizationOffset: 0 |
| 46 | }, |
| 47 | }] |
| 48 | }, |
| 49 | } |
| 50 | }, |
| 51 | }, |
| 52 | { |
| 53 | layer_type: "Convolution2dLayer", |
| 54 | layer : { |
| 55 | base: { |
| 56 | index:1, |
| 57 | layerName: "Convolution2dLayer", |
| 58 | layerType: "Convolution2d", |
| 59 | inputSlots: [{ |
| 60 | index: 0, |
| 61 | connection: {sourceLayerIndex:0, outputSlotIndex:0 }, |
| 62 | }], |
| 63 | outputSlots: [{ |
| 64 | index: 0, |
| 65 | tensorInfo: { |
| 66 | dimensions: )" + outputShape + R"(, |
| 67 | dataType: )" + dataType + R"( |
| 68 | }, |
| 69 | }], |
| 70 | }, |
| 71 | descriptor: { |
| 72 | padLeft: 1, |
| 73 | padRight: 1, |
| 74 | padTop: 1, |
| 75 | padBottom: 1, |
| 76 | strideX: 2, |
| 77 | strideY: 2, |
| 78 | biasEnabled: false, |
| 79 | dataLayout: NHWC |
| 80 | }, |
| 81 | weights: { |
| 82 | info: { |
| 83 | dimensions: )" + weightsShape + R"(, |
| 84 | dataType: )" + dataType + R"( |
| 85 | }, |
| 86 | data_type: IntData, |
| 87 | data: { |
| 88 | data: [ |
| 89 | 1082130432, 1084227584, 1086324736, |
| 90 | 0 ,0 ,0 , |
| 91 | 1077936128, 1073741824, 1065353216 |
| 92 | ], |
| 93 | } |
| 94 | } |
| 95 | }, |
| 96 | }, |
| 97 | { |
| 98 | layer_type: "OutputLayer", |
| 99 | layer: { |
| 100 | base:{ |
| 101 | layerBindingId: 0, |
| 102 | base: { |
| 103 | index: 2, |
| 104 | layerName: "OutputLayer", |
| 105 | layerType: "Output", |
| 106 | inputSlots: [{ |
| 107 | index: 0, |
| 108 | connection: {sourceLayerIndex:1, outputSlotIndex:0 }, |
| 109 | }], |
| 110 | outputSlots: [ { |
| 111 | index: 0, |
| 112 | tensorInfo: { |
| 113 | dimensions: )" + outputShape + R"(, |
| 114 | dataType: )" + dataType + R"( |
| 115 | }, |
| 116 | }], |
| 117 | } |
| 118 | }}, |
| 119 | }] |
| 120 | } |
| 121 | )"; |
| 122 | Setup(); |
| 123 | } |
| 124 | }; |
| 125 | |
| 126 | struct SimpleConvolution2dFixture : Convolution2dFixture |
| 127 | { |
| 128 | SimpleConvolution2dFixture() : Convolution2dFixture("[ 1, 5, 5, 1 ]", |
| 129 | "[ 1, 3, 3, 1 ]", |
| 130 | "[ 1, 3, 3, 1 ]", |
| 131 | "Float32") {} |
| 132 | }; |
| 133 | |
| 134 | BOOST_FIXTURE_TEST_CASE(Convolution2dFloat32, SimpleConvolution2dFixture) |
| 135 | { |
| 136 | RunTest<4, armnn::DataType::Float32>( |
| 137 | 0, |
| 138 | {{"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}}}, |
| 139 | {{"OutputLayer", {23, 33, 24, 91, 99, 48, 26, 50, 19}}}); |
| 140 | } |
| 141 | |
| 142 | BOOST_AUTO_TEST_SUITE_END() |