blob: 54d7bcb1dca51e4937a4ae041f4d4d31042ada36 [file] [log] [blame]
Sadik Armagan8853c1f2018-10-22 09:04:18 +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
10#include <string>
11#include <iostream>
12
13BOOST_AUTO_TEST_SUITE(TensorflowLiteParser)
14
15struct FullyConnectedFixture : public ParserFlatbuffersFixture
16{
17 explicit FullyConnectedFixture(const std::string& inputShape,
18 const std::string& outputShape,
19 const std::string& filterShape,
20 const std::string& filterData,
21 const std::string biasShape = "",
22 const std::string biasData = "")
23 {
24 std::string inputTensors = "[ 0, 2 ]";
25 std::string biasTensor = "";
26 std::string biasBuffer = "";
27 if (biasShape.size() > 0 && biasData.size() > 0)
28 {
29 inputTensors = "[ 0, 2, 3 ]";
30 biasTensor = R"(
31 {
32 "shape": )" + biasShape + R"( ,
33 "type": "INT32",
34 "buffer": 3,
35 "name": "biasTensor",
36 "quantization": {
37 "min": [ 0.0 ],
38 "max": [ 255.0 ],
39 "scale": [ 1.0 ],
40 "zero_point": [ 0 ],
41 }
42 } )";
43 biasBuffer = R"(
44 { "data": )" + biasData + R"(, }, )";
45 }
46 m_JsonString = R"(
47 {
48 "version": 3,
49 "operator_codes": [ { "builtin_code": "FULLY_CONNECTED" } ],
50 "subgraphs": [ {
51 "tensors": [
52 {
53 "shape": )" + inputShape + R"(,
54 "type": "UINT8",
55 "buffer": 0,
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": "UINT8",
67 "buffer": 1,
68 "name": "outputTensor",
69 "quantization": {
70 "min": [ 0.0 ],
71 "max": [ 511.0 ],
72 "scale": [ 2.0 ],
73 "zero_point": [ 0 ],
74 }
75 },
76 {
77 "shape": )" + filterShape + R"(,
78 "type": "UINT8",
79 "buffer": 2,
80 "name": "filterTensor",
81 "quantization": {
82 "min": [ 0.0 ],
83 "max": [ 255.0 ],
84 "scale": [ 1.0 ],
85 "zero_point": [ 0 ],
86 }
87 }, )" + biasTensor + R"(
88 ],
89 "inputs": [ 0 ],
90 "outputs": [ 1 ],
91 "operators": [
92 {
93 "opcode_index": 0,
94 "inputs": )" + inputTensors + R"(,
95 "outputs": [ 1 ],
96 "builtin_options_type": "FullyConnectedOptions",
97 "builtin_options": {
98 "fused_activation_function": "NONE"
99 },
100 "custom_options_format": "FLEXBUFFERS"
101 }
102 ],
103 } ],
104 "buffers" : [
105 { },
106 { },
107 { "data": )" + filterData + R"(, }, )"
108 + biasBuffer + R"(
109 ]
110 }
111 )";
112 SetupSingleInputSingleOutput("inputTensor", "outputTensor");
113 }
114};
115
116struct FullyConnectedWithNoBiasFixture : FullyConnectedFixture
117{
118 FullyConnectedWithNoBiasFixture()
119 : FullyConnectedFixture("[ 1, 4, 1, 1 ]", // inputShape
120 "[ 1, 1 ]", // outputShape
Nattapat Chaimanowongd8eee592018-10-26 10:24:14 +0100121 "[ 1, 4 ]", // filterShape
Sadik Armagan8853c1f2018-10-22 09:04:18 +0100122 "[ 2, 3, 4, 5 ]") // filterData
123 {}
124};
125
126BOOST_FIXTURE_TEST_CASE(FullyConnectedWithNoBias, FullyConnectedWithNoBiasFixture)
127{
Nattapat Chaimanowong649dd952019-01-22 16:10:44 +0000128 RunTest<2, armnn::DataType::QuantisedAsymm8>(
Sadik Armagan8853c1f2018-10-22 09:04:18 +0100129 0,
130 { 10, 20, 30, 40 },
131 { 400/2 });
132}
133
134struct FullyConnectedWithBiasFixture : FullyConnectedFixture
135{
136 FullyConnectedWithBiasFixture()
137 : FullyConnectedFixture("[ 1, 4, 1, 1 ]", // inputShape
138 "[ 1, 1 ]", // outputShape
Nattapat Chaimanowongd8eee592018-10-26 10:24:14 +0100139 "[ 1, 4 ]", // filterShape
Sadik Armagan8853c1f2018-10-22 09:04:18 +0100140 "[ 2, 3, 4, 5 ]", // filterData
141 "[ 1 ]", // biasShape
142 "[ 10, 0, 0, 0 ]" ) // biasData
143 {}
144};
145
146BOOST_FIXTURE_TEST_CASE(ParseFullyConnectedWithBias, FullyConnectedWithBiasFixture)
147{
Nattapat Chaimanowong649dd952019-01-22 16:10:44 +0000148 RunTest<2, armnn::DataType::QuantisedAsymm8>(
Sadik Armagan8853c1f2018-10-22 09:04:18 +0100149 0,
150 { 10, 20, 30, 40 },
151 { (400+10)/2 });
152}
153
Narumol Prangnawarat501f4d42019-04-24 15:52:20 +0100154struct FullyConnectedWithBiasMultipleOutputsFixture : FullyConnectedFixture
155{
156 FullyConnectedWithBiasMultipleOutputsFixture()
157 : FullyConnectedFixture("[ 1, 4, 2, 1 ]", // inputShape
158 "[ 2, 1 ]", // outputShape
159 "[ 1, 4 ]", // filterShape
160 "[ 2, 3, 4, 5 ]", // filterData
161 "[ 1 ]", // biasShape
162 "[ 10, 0, 0, 0 ]" ) // biasData
163 {}
164};
165
166BOOST_FIXTURE_TEST_CASE(FullyConnectedWithBiasMultipleOutputs, FullyConnectedWithBiasMultipleOutputsFixture)
167{
168 RunTest<2, armnn::DataType::QuantisedAsymm8>(
169 0,
170 { 1, 2, 3, 4, 10, 20, 30, 40 },
171 { (40+10)/2, (400+10)/2 });
172}
173
Sadik Armagan8853c1f2018-10-22 09:04:18 +0100174BOOST_AUTO_TEST_SUITE_END()