blob: aab1536628fc65f8d229709539041653b07257fc [file] [log] [blame]
Bruno Goncalves6c2355b2018-12-19 12:52:01 -02001//
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
10#include <string>
11#include <iostream>
12
13BOOST_AUTO_TEST_SUITE(TensorflowLiteParser)
14
15struct PadFixture : public ParserFlatbuffersFixture
16{
Narumol Prangnawarat8719d222020-11-27 16:57:56 +000017 explicit PadFixture(const std::string& inputShape,
18 const std::string& outputShape,
19 const std::string& padListShape,
20 const std::string& padListData,
21 const std::string& dataType = "FLOAT32",
22 const std::string& scale = "1.0",
23 const std::string& offset = "0")
Bruno Goncalves6c2355b2018-12-19 12:52:01 -020024 {
25 m_JsonString = R"(
26 {
27 "version": 3,
28 "operator_codes": [ { "builtin_code": "PAD" } ],
29 "subgraphs": [ {
30 "tensors": [
31 {
32 "shape": )" + inputShape + R"(,
Narumol Prangnawarat8719d222020-11-27 16:57:56 +000033 "type": )" + dataType + R"(,
Bruno Goncalves6c2355b2018-12-19 12:52:01 -020034 "buffer": 0,
35 "name": "inputTensor",
36 "quantization": {
37 "min": [ 0.0 ],
38 "max": [ 255.0 ],
Narumol Prangnawarat8719d222020-11-27 16:57:56 +000039 "scale": [ )" + scale + R"( ],
40 "zero_point": [ )" + offset + R"( ],
Bruno Goncalves6c2355b2018-12-19 12:52:01 -020041 }
42 },
43 {
44 "shape": )" + outputShape + R"(,
Narumol Prangnawarat8719d222020-11-27 16:57:56 +000045 "type": )" + dataType + R"(,
Bruno Goncalves6c2355b2018-12-19 12:52:01 -020046 "buffer": 1,
47 "name": "outputTensor",
48 "quantization": {
49 "min": [ 0.0 ],
50 "max": [ 255.0 ],
Narumol Prangnawarat8719d222020-11-27 16:57:56 +000051 "scale": [ )" + scale + R"( ],
52 "zero_point": [ )" + offset + R"( ],
Bruno Goncalves6c2355b2018-12-19 12:52:01 -020053 }
54 },
55 {
56 "shape": )" + padListShape + R"( ,
57 "type": "INT32",
58 "buffer": 2,
59 "name": "padList",
60 "quantization": {
61 "min": [ 0.0 ],
62 "max": [ 255.0 ],
63 "scale": [ 1.0 ],
64 "zero_point": [ 0 ],
65 }
66 }
67 ],
68 "inputs": [ 0 ],
69 "outputs": [ 1 ],
70 "operators": [
71 {
72 "opcode_index": 0,
73 "inputs": [ 0, 2 ],
74 "outputs": [ 1 ],
75 "custom_options_format": "FLEXBUFFERS"
76 }
77 ],
78 } ],
79 "buffers" : [
80 { },
81 { },
82 { "data": )" + padListData + R"(, },
83 ]
84 }
85 )";
86 SetupSingleInputSingleOutput("inputTensor", "outputTensor");
87 }
88};
89
90struct SimplePadFixture : public PadFixture
91{
92 SimplePadFixture() : PadFixture("[ 2, 3 ]", "[ 4, 7 ]", "[ 2, 2 ]",
93 "[ 1,0,0,0, 1,0,0,0, 2,0,0,0, 2,0,0,0 ]") {}
94};
95
96BOOST_FIXTURE_TEST_CASE(ParsePad, SimplePadFixture)
97{
Nattapat Chaimanowong649dd952019-01-22 16:10:44 +000098 RunTest<2, armnn::DataType::Float32>
99 (0,
100 {{ "inputTensor", { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f }}},
101 {{ "outputTensor", { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f,
102 0.0f, 0.0f, 1.0f, 2.0f, 3.0f, 0.0f, 0.0f,
103 0.0f, 0.0f, 4.0f, 5.0f, 6.0f, 0.0f, 0.0f,
104 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f }}});
Bruno Goncalves6c2355b2018-12-19 12:52:01 -0200105}
106
Narumol Prangnawarat8719d222020-11-27 16:57:56 +0000107struct Uint8PadFixture : public PadFixture
108{
109 Uint8PadFixture() : PadFixture("[ 2, 3 ]", "[ 4, 7 ]", "[ 2, 2 ]",
110 "[ 1,0,0,0, 1,0,0,0, 2,0,0,0, 2,0,0,0 ]",
111 "UINT8", "-2.0", "3") {}
112};
113
114BOOST_FIXTURE_TEST_CASE(ParsePadUint8, Uint8PadFixture)
115{
116 RunTest<2, armnn::DataType::QAsymmU8>
117 (0,
118 {{ "inputTensor", { 1, 2, 3, 4, 5, 6 }}},
119 {{ "outputTensor", { 3, 3, 3, 3, 3, 3, 3,
120 3, 3, 1, 2, 3, 3, 3,
121 3, 3, 4, 5, 6, 3, 3,
122 3, 3, 3, 3, 3, 3, 3 }}});
123}
124
125struct Int8PadFixture : public PadFixture
126{
127 Int8PadFixture() : PadFixture("[ 2, 3 ]", "[ 4, 7 ]", "[ 2, 2 ]",
128 "[ 1,0,0,0, 1,0,0,0, 2,0,0,0, 2,0,0,0 ]",
129 "INT8", "-2.0", "3") {}
130};
131
132BOOST_FIXTURE_TEST_CASE(ParsePadInt8, Int8PadFixture)
133{
134 RunTest<2, armnn::DataType::QAsymmS8>
135 (0,
136 {{ "inputTensor", { 1, -2, 3, 4, 5, -6 }}},
137 {{ "outputTensor", { 3, 3, 3, 3, 3, 3, 3,
138 3, 3, 1, -2, 3, 3, 3,
139 3, 3, 4, 5, -6, 3, 3,
140 3, 3, 3, 3, 3, 3, 3 }}});
141}
142
Bruno Goncalves6c2355b2018-12-19 12:52:01 -0200143BOOST_AUTO_TEST_SUITE_END()