ArmNN
 21.02
TransposeConv.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>
8 #include "../TfLiteParser.hpp"
9 
10 BOOST_AUTO_TEST_SUITE(TensorflowLiteParser)
11 
12 struct TransposeConvFixture : public ParserFlatbuffersFixture
13 {
14  explicit TransposeConvFixture(const std::string& inputShape,
15  const std::string& outputShape,
16  const std::string& filterShape,
17  const std::string& filterData,
18  const std::string& strideX,
19  const std::string& strideY,
20  const std::string& dataType)
21  {
22  m_JsonString = R"(
23  {
24  "version": 3,
25  "operator_codes": [ { "builtin_code": "TRANSPOSE_CONV" } ],
26  "subgraphs": [ {
27  "tensors": [
28  {
29  "shape": [ 4 ],
30  "type": "UINT8",
31  "buffer": 0,
32  "name": "outputShapeTensor",
33  "quantization": {
34  "min": [ 0.0 ],
35  "max": [ 255.0 ],
36  "scale": [ 1.0 ],
37  "zero_point": [ 0 ],
38  }
39  },
40  {
41  "shape": )" + filterShape + R"(,
42  "type": ")" + dataType + R"(",
43  "buffer": 1,
44  "name": "filterTensor",
45  "quantization": {
46  "min": [ 0.0 ],
47  "max": [ 255.0 ],
48  "scale": [ 1.0 ],
49  "zero_point": [ 0 ],
50  }
51  },
52  {
53  "shape": )" + inputShape + R"(,
54  "type": ")" + dataType + R"(",
55  "buffer": 2,
56  "name": "inputTensor",
57  "quantization": {
58  "min": [ 0.0 ],
59  "max": [ 255.0 ],
60  "scale": [ 1.0 ],
61  "zero_point": [ 0 ],
62  }
63  },
64  {
65  "shape": )" + outputShape + R"(,
66  "type": ")" + dataType + R"(",
67  "buffer": 3,
68  "name": "outputTensor",
69  "quantization": {
70  "min": [ 0.0 ],
71  "max": [ 255.0 ],
72  "scale": [ 1.0 ],
73  "zero_point": [ 0 ],
74  }
75  }
76  ],
77  "inputs": [ 2 ],
78  "outputs": [ 3 ],
79  "operators": [
80  {
81  "opcode_index": 0,
82  "inputs": [ 0, 1, 2 ],
83  "outputs": [ 3 ],
84  "builtin_options_type": "TransposeConvOptions",
85  "builtin_options": {
86  "padding": "VALID",
87  "stride_w": )" + strideX + R"(,
88  "stride_h": )" + strideY + R"(
89  },
90  "custom_options_format": "FLEXBUFFERS"
91  }
92  ],
93  } ],
94  "buffers" : [
95  { "data": )" + outputShape + R"( },
96  { "data": )" + filterData + R"( },
97  { },
98  { }
99  ]
100  }
101  )";
102  SetupSingleInputSingleOutput("inputTensor", "outputTensor");
103  }
104 };
105 
106 struct SimpleTransposeConvFixture : TransposeConvFixture
107 {
108  SimpleTransposeConvFixture()
109  : TransposeConvFixture("[ 1, 2, 2, 1 ]", // inputShape
110  "[ 1, 3, 3, 1 ]", // outputShape
111  "[ 1, 2, 2, 1 ]", // filterShape
112  "[ 0, 1, 2, 4 ]", // filterData
113  "1", // strideX
114  "1", // strideY
115  "UINT8") // dataType
116  {}
117 };
118 
119 BOOST_FIXTURE_TEST_CASE( ParseSimpleTransposeConv, SimpleTransposeConvFixture )
120 {
121  RunTest<4, armnn::DataType::QAsymmU8>(
122  0,
123  {
124  1, 2,
125  3, 4
126  },
127  {
128  0, 1, 2,
129  2, 11, 12,
130  6, 20, 16
131  });
132 }
133 
134 struct TransposeConvFixtureWithBias : public ParserFlatbuffersFixture
135 {
136  explicit TransposeConvFixtureWithBias(const std::string& inputShape,
137  const std::string& outputShape,
138  const std::string& filterShape,
139  const std::string& filterData,
140  const std::string& strideX,
141  const std::string& strideY,
142  const std::string& dataType,
143  const std::string& biasShape,
144  const std::string& biasData)
145  {
146  m_JsonString = R"(
147  {
148  "version": 3,
149  "operator_codes": [ { "builtin_code": "TRANSPOSE_CONV" } ],
150  "subgraphs": [ {
151  "tensors": [
152  {
153  "shape": [ 4 ],
154  "type": "UINT8",
155  "buffer": 0,
156  "name": "outputShapeTensor",
157  "quantization": {
158  "min": [ 0.0 ],
159  "max": [ 255.0 ],
160  "scale": [ 1.0 ],
161  "zero_point": [ 0 ],
162  }
163  },
164  {
165  "shape": )" + filterShape + R"(,
166  "type": ")" + dataType + R"(",
167  "buffer": 1,
168  "name": "filterTensor",
169  "quantization": {
170  "min": [ 0.0 ],
171  "max": [ 255.0 ],
172  "scale": [ 1.0 ],
173  "zero_point": [ 0 ],
174  }
175  },
176  {
177  "shape": )" + inputShape + R"(,
178  "type": ")" + dataType + R"(",
179  "buffer": 2,
180  "name": "inputTensor",
181  "quantization": {
182  "min": [ 0.0 ],
183  "max": [ 255.0 ],
184  "scale": [ 1.0 ],
185  "zero_point": [ 0 ],
186  }
187  },
188  {
189  "shape": )" + biasShape + R"( ,
190  "type": "INT32",
191  "buffer": 3,
192  "name": "biasTensor",
193  "quantization": {
194  "min": [ 0.0 ],
195  "max": [ 255.0 ],
196  "scale": [ 1.0 ],
197  "zero_point": [ 0 ],
198  }
199  },
200  {
201  "shape": )" + outputShape + R"(,
202  "type": ")" + dataType + R"(",
203  "buffer": 4,
204  "name": "outputTensor",
205  "quantization": {
206  "min": [ 0.0 ],
207  "max": [ 255.0 ],
208  "scale": [ 1.0 ],
209  "zero_point": [ 0 ],
210  }
211  }
212  ],
213  "inputs": [ 2 ],
214  "outputs": [ 4 ],
215  "operators": [
216  {
217  "opcode_index": 0,
218  "inputs": [ 0, 1, 2, 3],
219  "outputs": [ 4 ],
220  "builtin_options_type": "TransposeConvOptions",
221  "builtin_options": {
222  "padding": "VALID",
223  "stride_w": )" + strideX + R"(,
224  "stride_h": )" + strideY + R"(
225  },
226  "custom_options_format": "FLEXBUFFERS"
227  }
228  ],
229  } ],
230  "buffers" : [
231  { "data": )" + outputShape + R"( },
232  { "data": )" + filterData + R"( },
233  { },
234  { "data": )" + biasData + R"( },
235  { }
236  ]
237  }
238  )";
239  SetupSingleInputSingleOutput("inputTensor", "outputTensor");
240  }
241 };
242 
243 struct SimpleTransposeConvFixtureWithBias : TransposeConvFixtureWithBias
244 {
245  SimpleTransposeConvFixtureWithBias()
246  : TransposeConvFixtureWithBias("[ 1, 2, 2, 1 ]", // inputShape
247  "[ 1, 3, 3, 1 ]", // outputShape
248  "[ 1, 2, 2, 1 ]", // filterShape
249  "[ 0, 1, 2, 4 ]", // filterData
250  "1", // strideX
251  "1", // strideY
252  "UINT8", // dataType
253  "[ 1 ]", // bias shape
254  "[ 10, 0, 0, 0 ]") // bias data
255  {}
256 };
257 
258 BOOST_FIXTURE_TEST_CASE( ParseSimpleTransposeConvWithBias, SimpleTransposeConvFixtureWithBias )
259 {
260  RunTest<4, armnn::DataType::QAsymmU8>(
261  0,
262  {
263  1, 2,
264  3, 4
265  },
266  {
267  10, 11, 12,
268  12, 21, 22,
269  16, 30, 26
270  });
271 }
272 
BOOST_AUTO_TEST_SUITE(TensorflowLiteParser)
BOOST_AUTO_TEST_SUITE_END()
void SetupSingleInputSingleOutput(const std::string &inputName, const std::string &outputName)
BOOST_FIXTURE_TEST_CASE(ParseSimpleTransposeConv, SimpleTransposeConvFixture)