blob: 0f53e73640daf3fbafe3c0ef8c2fe7d5d88d06ef [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
Matthew Jackson74bf7da2019-08-16 16:51:42 +01006#include "ParserFlatbuffersFixture.hpp"
7#include "../TfLiteParser.hpp"
8
Sadik Armagan1625efc2021-06-10 18:24:34 +01009TEST_SUITE("TensorflowLiteParser_TransposeConv")
10{
Matthew Jackson74bf7da2019-08-16 16:51:42 +010011struct TransposeConvFixture : public ParserFlatbuffersFixture
12{
13 explicit TransposeConvFixture(const std::string& inputShape,
14 const std::string& outputShape,
15 const std::string& filterShape,
16 const std::string& filterData,
Matthew Jackson74bf7da2019-08-16 16:51:42 +010017 const std::string& strideX,
18 const std::string& strideY,
19 const std::string& dataType)
20 {
Matthew Jackson74bf7da2019-08-16 16:51:42 +010021 m_JsonString = R"(
22 {
23 "version": 3,
24 "operator_codes": [ { "builtin_code": "TRANSPOSE_CONV" } ],
25 "subgraphs": [ {
26 "tensors": [
27 {
Matthew Jacksonccb25ea2019-08-20 17:18:33 +010028 "shape": [ 4 ],
29 "type": "UINT8",
Matthew Jackson74bf7da2019-08-16 16:51:42 +010030 "buffer": 0,
Matthew Jacksonccb25ea2019-08-20 17:18:33 +010031 "name": "outputShapeTensor",
Matthew Jackson74bf7da2019-08-16 16:51:42 +010032 "quantization": {
33 "min": [ 0.0 ],
34 "max": [ 255.0 ],
35 "scale": [ 1.0 ],
36 "zero_point": [ 0 ],
37 }
38 },
39 {
40 "shape": )" + filterShape + R"(,
41 "type": ")" + dataType + R"(",
42 "buffer": 1,
43 "name": "filterTensor",
44 "quantization": {
45 "min": [ 0.0 ],
46 "max": [ 255.0 ],
47 "scale": [ 1.0 ],
48 "zero_point": [ 0 ],
49 }
Matthew Jacksonccb25ea2019-08-20 17:18:33 +010050 },
51 {
52 "shape": )" + inputShape + R"(,
53 "type": ")" + dataType + R"(",
54 "buffer": 2,
55 "name": "inputTensor",
56 "quantization": {
57 "min": [ 0.0 ],
58 "max": [ 255.0 ],
59 "scale": [ 1.0 ],
60 "zero_point": [ 0 ],
61 }
62 },
Matthew Jackson74bf7da2019-08-16 16:51:42 +010063 {
64 "shape": )" + outputShape + R"(,
65 "type": ")" + dataType + R"(",
Matthew Jacksonccb25ea2019-08-20 17:18:33 +010066 "buffer": 3,
Matthew Jackson74bf7da2019-08-16 16:51:42 +010067 "name": "outputTensor",
68 "quantization": {
69 "min": [ 0.0 ],
70 "max": [ 255.0 ],
71 "scale": [ 1.0 ],
72 "zero_point": [ 0 ],
73 }
74 }
75 ],
Matthew Jacksonccb25ea2019-08-20 17:18:33 +010076 "inputs": [ 2 ],
77 "outputs": [ 3 ],
Matthew Jackson74bf7da2019-08-16 16:51:42 +010078 "operators": [
79 {
80 "opcode_index": 0,
Matthew Jacksonccb25ea2019-08-20 17:18:33 +010081 "inputs": [ 0, 1, 2 ],
82 "outputs": [ 3 ],
Matthew Jackson74bf7da2019-08-16 16:51:42 +010083 "builtin_options_type": "TransposeConvOptions",
84 "builtin_options": {
Aron Virginas-Tar44a01422019-09-17 12:58:22 +010085 "padding": "VALID",
Matthew Jackson74bf7da2019-08-16 16:51:42 +010086 "stride_w": )" + strideX + R"(,
87 "stride_h": )" + strideY + R"(
88 },
89 "custom_options_format": "FLEXBUFFERS"
90 }
91 ],
92 } ],
93 "buffers" : [
Matthew Jacksonccb25ea2019-08-20 17:18:33 +010094 { "data": )" + outputShape + R"( },
Matthew Jackson74bf7da2019-08-16 16:51:42 +010095 { "data": )" + filterData + R"( },
Matthew Jacksonccb25ea2019-08-20 17:18:33 +010096 { },
Matthew Jackson74bf7da2019-08-16 16:51:42 +010097 { }
98 ]
99 }
100 )";
101 SetupSingleInputSingleOutput("inputTensor", "outputTensor");
102 }
103};
104
105struct SimpleTransposeConvFixture : TransposeConvFixture
106{
107 SimpleTransposeConvFixture()
108 : TransposeConvFixture("[ 1, 2, 2, 1 ]", // inputShape
109 "[ 1, 3, 3, 1 ]", // outputShape
110 "[ 1, 2, 2, 1 ]", // filterShape
111 "[ 0, 1, 2, 4 ]", // filterData
Matthew Jackson74bf7da2019-08-16 16:51:42 +0100112 "1", // strideX
113 "1", // strideY
114 "UINT8") // dataType
115 {}
116};
117
Sadik Armagan1625efc2021-06-10 18:24:34 +0100118TEST_CASE_FIXTURE(SimpleTransposeConvFixture, "ParseSimpleTransposeConv")
Matthew Jackson74bf7da2019-08-16 16:51:42 +0100119{
Derek Lambertif90c56d2020-01-10 17:14:08 +0000120 RunTest<4, armnn::DataType::QAsymmU8>(
Matthew Jackson74bf7da2019-08-16 16:51:42 +0100121 0,
122 {
123 1, 2,
124 3, 4
125 },
126 {
127 0, 1, 2,
128 2, 11, 12,
129 6, 20, 16
130 });
131}
132
David Monahan61683802021-01-12 09:11:07 +0000133struct TransposeConvFixtureWithBias : public ParserFlatbuffersFixture
134{
135 explicit TransposeConvFixtureWithBias(const std::string& inputShape,
136 const std::string& outputShape,
137 const std::string& filterShape,
138 const std::string& filterData,
139 const std::string& strideX,
140 const std::string& strideY,
141 const std::string& dataType,
142 const std::string& biasShape,
143 const std::string& biasData)
144 {
145 m_JsonString = R"(
146 {
147 "version": 3,
148 "operator_codes": [ { "builtin_code": "TRANSPOSE_CONV" } ],
149 "subgraphs": [ {
150 "tensors": [
151 {
152 "shape": [ 4 ],
153 "type": "UINT8",
154 "buffer": 0,
155 "name": "outputShapeTensor",
156 "quantization": {
157 "min": [ 0.0 ],
158 "max": [ 255.0 ],
159 "scale": [ 1.0 ],
160 "zero_point": [ 0 ],
161 }
162 },
163 {
164 "shape": )" + filterShape + R"(,
165 "type": ")" + dataType + R"(",
166 "buffer": 1,
167 "name": "filterTensor",
168 "quantization": {
169 "min": [ 0.0 ],
170 "max": [ 255.0 ],
171 "scale": [ 1.0 ],
172 "zero_point": [ 0 ],
173 }
174 },
175 {
176 "shape": )" + inputShape + R"(,
177 "type": ")" + dataType + R"(",
178 "buffer": 2,
179 "name": "inputTensor",
180 "quantization": {
181 "min": [ 0.0 ],
182 "max": [ 255.0 ],
183 "scale": [ 1.0 ],
184 "zero_point": [ 0 ],
185 }
186 },
187 {
188 "shape": )" + biasShape + R"( ,
189 "type": "INT32",
190 "buffer": 3,
191 "name": "biasTensor",
192 "quantization": {
193 "min": [ 0.0 ],
194 "max": [ 255.0 ],
195 "scale": [ 1.0 ],
196 "zero_point": [ 0 ],
197 }
198 },
199 {
200 "shape": )" + outputShape + R"(,
201 "type": ")" + dataType + R"(",
202 "buffer": 4,
203 "name": "outputTensor",
204 "quantization": {
205 "min": [ 0.0 ],
206 "max": [ 255.0 ],
207 "scale": [ 1.0 ],
208 "zero_point": [ 0 ],
209 }
210 }
211 ],
212 "inputs": [ 2 ],
213 "outputs": [ 4 ],
214 "operators": [
215 {
216 "opcode_index": 0,
217 "inputs": [ 0, 1, 2, 3],
218 "outputs": [ 4 ],
219 "builtin_options_type": "TransposeConvOptions",
220 "builtin_options": {
221 "padding": "VALID",
222 "stride_w": )" + strideX + R"(,
223 "stride_h": )" + strideY + R"(
224 },
225 "custom_options_format": "FLEXBUFFERS"
226 }
227 ],
228 } ],
229 "buffers" : [
230 { "data": )" + outputShape + R"( },
231 { "data": )" + filterData + R"( },
232 { },
233 { "data": )" + biasData + R"( },
234 { }
235 ]
236 }
237 )";
238 SetupSingleInputSingleOutput("inputTensor", "outputTensor");
239 }
240};
241
242struct SimpleTransposeConvFixtureWithBias : TransposeConvFixtureWithBias
243{
244 SimpleTransposeConvFixtureWithBias()
245 : TransposeConvFixtureWithBias("[ 1, 2, 2, 1 ]", // inputShape
246 "[ 1, 3, 3, 1 ]", // outputShape
247 "[ 1, 2, 2, 1 ]", // filterShape
248 "[ 0, 1, 2, 4 ]", // filterData
249 "1", // strideX
250 "1", // strideY
251 "UINT8", // dataType
252 "[ 1 ]", // bias shape
253 "[ 10, 0, 0, 0 ]") // bias data
254 {}
255};
256
Sadik Armagan1625efc2021-06-10 18:24:34 +0100257TEST_CASE_FIXTURE(SimpleTransposeConvFixtureWithBias, "ParseSimpleTransposeConvWithBias")
David Monahan61683802021-01-12 09:11:07 +0000258{
259 RunTest<4, armnn::DataType::QAsymmU8>(
260 0,
261 {
262 1, 2,
263 3, 4
264 },
265 {
266 10, 11, 12,
267 12, 21, 22,
268 16, 30, 26
269 });
270}
271
Jan Eilersea835e72021-04-21 16:58:28 +0100272
273struct TransposeConvPerChannelFixture : public ParserFlatbuffersFixture
274{
275 explicit TransposeConvPerChannelFixture()
276 {
277 m_JsonString = R"(
278 {
279 "version": 3,
280 "operator_codes": [
281 {
282 "builtin_code": "TRANSPOSE_CONV",
283 "version": 2
284 }
285 ],
286 "subgraphs": [
287 {
288 "tensors": [
289 {
290 "shape": [
291 1,
292 4,
293 4,
294 2
295 ],
296 "type": "INT8",
297 "buffer": 1,
298 "name": "input",
299 "quantization": {
300 "min": [
301 -50.0
302 ],
303 "max": [
304 49.0
305 ],
306 "scale": [
307 0.388235
308 ],
309 "zero_point": [
310 1
311 ],
312 "details_type": "NONE",
313 "quantized_dimension": 0
314 },
315 "is_variable": false
316 },
317 {
318 "shape": [
319 4
320 ],
321 "type": "INT32",
322 "buffer": 2,
323 "name": "model/conv2d_transpose/stack",
324 "quantization": {
325 "details_type": "NONE",
326 "quantized_dimension": 0
327 },
328 "is_variable": false
329 },
330 {
331 "shape": [
332 8,
333 2,
334 2,
335 2
336 ],
337 "type": "INT8",
338 "buffer": 3,
339 "name": "model/conv2d_transpose/conv2d_transpose",
340 "quantization": {
341 "min": [
342 -0.081948,
343 -0.379918,
344 -0.223632,
345 -0.098629,
346 -0.386369,
347 -0.351057,
348 -0.348749,
349 -0.264848
350 ],
351 "max": [
352 0.35091,
353 0.229681,
354 0.368384,
355 0.176761,
356 0.353717,
357 0.377565,
358 0.373713,
359 0.30141
360 ],
361 "scale": [
362 0.002763,
363 0.002991,
364 0.002901,
365 0.001392,
366 0.003042,
367 0.002973,
368 0.002943,
369 0.002373
370 ],
371 "zero_point": [
372 0,
373 0,
374 0,
375 0,
376 0,
377 0,
378 0,
379 0
380 ],
381 "details_type": "NONE",
382 "quantized_dimension": 0
383 },
384 "is_variable": false
385 },
386 {
387 "shape": [
388 1,
389 4,
390 4,
391 8
392 ],
393 "type": "INT8",
394 "buffer": 4,
395 "name": "Identity",
396 "quantization": {
397 "min": [
398 -63.578175
399 ],
400 "max": [
401 69.305023
402 ],
403 "scale": [
404 0.521111
405 ],
406 "zero_point": [
407 -6
408 ],
409 "details_type": "NONE",
410 "quantized_dimension": 0
411 },
412 "is_variable": false
413 }
414 ],
415 "inputs": [
416 0
417 ],
418 "outputs": [
419 3
420 ],
421 "operators": [
422 {
423 "opcode_index": 0,
424 "inputs": [
425 1,
426 2,
427 0
428 ],
429 "outputs": [
430 3
431 ],
432 "builtin_options_type": "TransposeConvOptions",
433 "builtin_options": {
434 "padding": "SAME",
435 "stride_w": 1,
436 "stride_h": 1
437 },
438 "custom_options_format": "FLEXBUFFERS"
439 }
440 ],
441 "name": "main"
442 }
443 ],
444 "description": "MLIR Converted.",
445 "buffers": [
446 {
447 },
448 {
449 },
450 {
451 "data": [
452 1,
453 0,
454 0,
455 0,
456 4,
457 0,
458 0,
459 0,
460 4,
461 0,
462 0,
463 0,
464 8,
465 0,
466 0,
467 0
468 ]
469 },
470 {
471 "data": [
472 13,
473 239,
474 7,
475 125,
476 35,
477 127,
478 55,
479 226,
480 77,
481 150,
482 159,
483 192,
484 180,
485 129,
486 51,
487 48,
488 108,
489 9,
490 21,
491 179,
492 12,
493 39,
494 127,
495 107,
496 44,
497 206,
498 127,
499 185,
500 108,
501 82,
502 86,
503 218,
504 38,
505 149,
506 16,
507 1,
508 129,
509 163,
510 116,
511 136,
512 138,
513 43,
514 65,
515 186,
516 154,
517 138,
518 64,
519 127,
520 120,
521 127,
522 207,
523 70,
524 43,
525 33,
526 141,
527 137,
528 93,
529 215,
530 65,
531 92,
532 122,
533 144,
534 120,
535 127
536 ]
537 },
538 {
539 },
540 {
541 "data": [
542 49,
543 46,
544 57,
545 46,
546 48,
547 0,
548 0,
549 0,
550 0,
551 0,
552 0,
553 0,
554 0,
555 0,
556 0,
557 0
558 ]
559 }
560 ],
561 "metadata": [
562 {
563 "name": "min_runtime_version",
564 "buffer": 5
565 }
566 ]
567 }
568 )";
569 SetupSingleInputSingleOutput("input", "Identity");
570 }
571};
572
Sadik Armagan1625efc2021-06-10 18:24:34 +0100573TEST_CASE_FIXTURE(TransposeConvPerChannelFixture, "ParseTransposeConvPerChannel")
Jan Eilersea835e72021-04-21 16:58:28 +0100574{
575 RunTest<4, armnn::DataType::QAsymmS8>(
576 0,
577 {
578 -11, 40,-26, 11,-28, 8, 0, -8,
579 -10, 34, 47, 0,-33,-14, 28, 35,
580 6,-28,-26, 8, 13, 33,-31,-41,
581 31,-20,-31,-16, 8,-18,-44, 0
582 },
583 {
584 -8,-17, -8, -9,-16, 1, 2,-11,
585 3,-16,-19,-12,-11, -6, -3, -6,
586 -5, -8,-16,-12,-11, -3, -7,-13,
587 -4, 1, -9,-10, -5,-12, -5, -8,
588 2,-25, -5, -6,-20, -7, 2,-21,
589 1, 4, 5,-13,-10,-12, 3, 4,
590 -10,-17,-17, -6, -7, 12,-22,-17,
591 -17, 0, -5,-14,-21,-12, 17,-13,
592 3, -6, -3, -3, -2,-16,-11,-12,
593 -15,-14, -1, -2,-35, 5,-18, 0,
594 -6, 8, 5,-12, 12, 7, -6, -3,
595 11,-28,-28, -3,-18,-29, -5,-13,
596 -12, 11, -2, -5, 6, -9, -6, 7,
597 -9,-11,-14, -2, 12, 5,-21,-23,
598 -4, -4, -6, -6,-21,-25, 0,-18,
599 -26, 10, -7,-13, 3, 39,-39, -4
600 });
601}
602
Sadik Armagan1625efc2021-06-10 18:24:34 +0100603}