blob: 94e42438e191543a59590c8878fcaf0c9ca36ef1 [file] [log] [blame]
Matthew Jackson74bf7da2019-08-16 16:51:42 +01001//
2// Copyright © 2017 Arm Ltd. All rights reserved.
3// SPDX-License-Identifier: MIT
4//
5
6#include <boost/test/unit_test.hpp>
7#include "ParserFlatbuffersFixture.hpp"
8#include "../TfLiteParser.hpp"
9
10BOOST_AUTO_TEST_SUITE(TensorflowLiteParser)
11
12struct 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,
Matthew Jackson74bf7da2019-08-16 16:51:42 +010018 const std::string& strideX,
19 const std::string& strideY,
20 const std::string& dataType)
21 {
Matthew Jackson74bf7da2019-08-16 16:51:42 +010022 m_JsonString = R"(
23 {
24 "version": 3,
25 "operator_codes": [ { "builtin_code": "TRANSPOSE_CONV" } ],
26 "subgraphs": [ {
27 "tensors": [
28 {
Matthew Jacksonccb25ea2019-08-20 17:18:33 +010029 "shape": [ 4 ],
30 "type": "UINT8",
Matthew Jackson74bf7da2019-08-16 16:51:42 +010031 "buffer": 0,
Matthew Jacksonccb25ea2019-08-20 17:18:33 +010032 "name": "outputShapeTensor",
Matthew Jackson74bf7da2019-08-16 16:51:42 +010033 "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 }
Matthew Jacksonccb25ea2019-08-20 17:18:33 +010051 },
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 },
Matthew Jackson74bf7da2019-08-16 16:51:42 +010064 {
65 "shape": )" + outputShape + R"(,
66 "type": ")" + dataType + R"(",
Matthew Jacksonccb25ea2019-08-20 17:18:33 +010067 "buffer": 3,
Matthew Jackson74bf7da2019-08-16 16:51:42 +010068 "name": "outputTensor",
69 "quantization": {
70 "min": [ 0.0 ],
71 "max": [ 255.0 ],
72 "scale": [ 1.0 ],
73 "zero_point": [ 0 ],
74 }
75 }
76 ],
Matthew Jacksonccb25ea2019-08-20 17:18:33 +010077 "inputs": [ 2 ],
78 "outputs": [ 3 ],
Matthew Jackson74bf7da2019-08-16 16:51:42 +010079 "operators": [
80 {
81 "opcode_index": 0,
Matthew Jacksonccb25ea2019-08-20 17:18:33 +010082 "inputs": [ 0, 1, 2 ],
83 "outputs": [ 3 ],
Matthew Jackson74bf7da2019-08-16 16:51:42 +010084 "builtin_options_type": "TransposeConvOptions",
85 "builtin_options": {
Aron Virginas-Tar44a01422019-09-17 12:58:22 +010086 "padding": "VALID",
Matthew Jackson74bf7da2019-08-16 16:51:42 +010087 "stride_w": )" + strideX + R"(,
88 "stride_h": )" + strideY + R"(
89 },
90 "custom_options_format": "FLEXBUFFERS"
91 }
92 ],
93 } ],
94 "buffers" : [
Matthew Jacksonccb25ea2019-08-20 17:18:33 +010095 { "data": )" + outputShape + R"( },
Matthew Jackson74bf7da2019-08-16 16:51:42 +010096 { "data": )" + filterData + R"( },
Matthew Jacksonccb25ea2019-08-20 17:18:33 +010097 { },
Matthew Jackson74bf7da2019-08-16 16:51:42 +010098 { }
99 ]
100 }
101 )";
102 SetupSingleInputSingleOutput("inputTensor", "outputTensor");
103 }
104};
105
106struct 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
Matthew Jackson74bf7da2019-08-16 16:51:42 +0100113 "1", // strideX
114 "1", // strideY
115 "UINT8") // dataType
116 {}
117};
118
119BOOST_FIXTURE_TEST_CASE( ParseSimpleTransposeConv, SimpleTransposeConvFixture )
120{
Derek Lambertif90c56d2020-01-10 17:14:08 +0000121 RunTest<4, armnn::DataType::QAsymmU8>(
Matthew Jackson74bf7da2019-08-16 16:51:42 +0100122 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
David Monahan61683802021-01-12 09:11:07 +0000134struct 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
243struct 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
258BOOST_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
Matthew Jackson74bf7da2019-08-16 16:51:42 +0100273BOOST_AUTO_TEST_SUITE_END()