ArmNN
 21.05
DeserializePooling2d.cpp
Go to the documentation of this file.
1 //
2 // Copyright © 2017 Arm Ltd. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 
6 #include <boost/test/unit_test.hpp>
9 
10 #include <string>
11 
12 BOOST_AUTO_TEST_SUITE(Deserializer)
13 
14 struct Pooling2dFixture : public ParserFlatbuffersSerializeFixture
15 {
16  explicit Pooling2dFixture(const std::string &inputShape,
17  const std::string &outputShape,
18  const std::string &dataType,
19  const std::string &dataLayout,
20  const std::string &poolingAlgorithm)
21  {
22  m_JsonString = R"(
23  {
24  inputIds: [0],
25  outputIds: [2],
26  layers: [
27  {
28  layer_type: "InputLayer",
29  layer: {
30  base: {
31  layerBindingId: 0,
32  base: {
33  index: 0,
34  layerName: "InputLayer",
35  layerType: "Input",
36  inputSlots: [{
37  index: 0,
38  connection: {sourceLayerIndex:0, outputSlotIndex:0 },
39  }],
40  outputSlots: [ {
41  index: 0,
42  tensorInfo: {
43  dimensions: )" + inputShape + R"(,
44  dataType: )" + dataType + R"(
45  }}]
46  }
47  }}},
48  {
49  layer_type: "Pooling2dLayer",
50  layer: {
51  base: {
52  index: 1,
53  layerName: "Pooling2dLayer",
54  layerType: "Pooling2d",
55  inputSlots: [{
56  index: 0,
57  connection: {sourceLayerIndex:0, outputSlotIndex:0 },
58  }],
59  outputSlots: [ {
60  index: 0,
61  tensorInfo: {
62  dimensions: )" + outputShape + R"(,
63  dataType: )" + dataType + R"(
64 
65  }}]},
66  descriptor: {
67  poolType: )" + poolingAlgorithm + R"(,
68  outputShapeRounding: "Floor",
69  paddingMethod: Exclude,
70  dataLayout: )" + dataLayout + R"(,
71  padLeft: 0,
72  padRight: 0,
73  padTop: 0,
74  padBottom: 0,
75  poolWidth: 2,
76  poolHeight: 2,
77  strideX: 2,
78  strideY: 2
79  }
80  }},
81  {
82  layer_type: "OutputLayer",
83  layer: {
84  base:{
85  layerBindingId: 0,
86  base: {
87  index: 2,
88  layerName: "OutputLayer",
89  layerType: "Output",
90  inputSlots: [{
91  index: 0,
92  connection: {sourceLayerIndex:1, outputSlotIndex:0 },
93  }],
94  outputSlots: [ {
95  index: 0,
96  tensorInfo: {
97  dimensions: )" + outputShape + R"(,
98  dataType: )" + dataType + R"(
99  },
100  }],
101  }}},
102  }]
103  }
104  )";
105  SetupSingleInputSingleOutput("InputLayer", "OutputLayer");
106  }
107 };
108 
109 struct SimpleAvgPooling2dFixture : Pooling2dFixture
110 {
111  SimpleAvgPooling2dFixture() : Pooling2dFixture("[ 1, 2, 2, 1 ]",
112  "[ 1, 1, 1, 1 ]",
113  "Float32", "NHWC", "Average") {}
114 };
115 
116 struct SimpleAvgPooling2dFixture2 : Pooling2dFixture
117 {
118  SimpleAvgPooling2dFixture2() : Pooling2dFixture("[ 1, 2, 2, 1 ]",
119  "[ 1, 1, 1, 1 ]",
120  "QuantisedAsymm8", "NHWC", "Average") {}
121 };
122 
123 struct SimpleMaxPooling2dFixture : Pooling2dFixture
124 {
125  SimpleMaxPooling2dFixture() : Pooling2dFixture("[ 1, 1, 2, 2 ]",
126  "[ 1, 1, 1, 1 ]",
127  "Float32", "NCHW", "Max") {}
128 };
129 
130 struct SimpleMaxPooling2dFixture2 : Pooling2dFixture
131 {
132  SimpleMaxPooling2dFixture2() : Pooling2dFixture("[ 1, 1, 2, 2 ]",
133  "[ 1, 1, 1, 1 ]",
134  "QuantisedAsymm8", "NCHW", "Max") {}
135 };
136 
137 struct SimpleL2Pooling2dFixture : Pooling2dFixture
138 {
139  SimpleL2Pooling2dFixture() : Pooling2dFixture("[ 1, 2, 2, 1 ]",
140  "[ 1, 1, 1, 1 ]",
141  "Float32", "NHWC", "L2") {}
142 };
143 
144 BOOST_FIXTURE_TEST_CASE(Pooling2dFloat32Avg, SimpleAvgPooling2dFixture)
145 {
146  RunTest<4, armnn::DataType::Float32>(0, { 2, 3, 5, 2 }, { 3 });
147 }
148 
149 BOOST_FIXTURE_TEST_CASE(Pooling2dQuantisedAsymm8Avg, SimpleAvgPooling2dFixture2)
150 {
151  RunTest<4, armnn::DataType::QAsymmU8>(0,{ 20, 40, 60, 80 },{ 50 });
152 }
153 
154 BOOST_FIXTURE_TEST_CASE(Pooling2dFloat32Max, SimpleMaxPooling2dFixture)
155 {
156  RunTest<4, armnn::DataType::Float32>(0, { 2, 5, 5, 2 }, { 5 });
157 }
158 
159 BOOST_FIXTURE_TEST_CASE(Pooling2dQuantisedAsymm8Max, SimpleMaxPooling2dFixture2)
160 {
161  RunTest<4, armnn::DataType::QAsymmU8>(0,{ 20, 40, 60, 80 },{ 80 });
162 }
163 
164 BOOST_FIXTURE_TEST_CASE(Pooling2dFloat32L2, SimpleL2Pooling2dFixture)
165 {
166  RunTest<4, armnn::DataType::Float32>(0, { 2, 3, 5, 2 }, { 3.2403703f });
167 }
168 
170 
BOOST_AUTO_TEST_SUITE(TensorflowLiteParser)
void SetupSingleInputSingleOutput(const std::string &inputName, const std::string &outputName)
BOOST_FIXTURE_TEST_CASE(Pooling2dFloat32Avg, SimpleAvgPooling2dFixture)
BOOST_AUTO_TEST_SUITE_END()