blob: 51b75faf07d02a7d0018a4852e4ebd495c73b0ef [file] [log] [blame]
Ryan OShea86704732020-05-26 11:41:04 +01001//
2// Copyright © 2020 Arm Ltd. All rights reserved.
3// SPDX-License-Identifier: MIT
4//
5
Ryan OShea86704732020-05-26 11:41:04 +01006#include "ParserFlatbuffersFixture.hpp"
7#include "../TfLiteParser.hpp"
8
9#include <string>
10#include <iostream>
11
Sadik Armagan1625efc2021-06-10 18:24:34 +010012TEST_SUITE("TensorflowLiteParser")
13{
Ryan OShea86704732020-05-26 11:41:04 +010014struct SplitVFixture : public ParserFlatbuffersFixture
15{
16 explicit SplitVFixture(const std::string& inputShape,
17 const std::string& splitValues,
18 const std::string& sizeSplitsShape,
19 const std::string& axisShape,
20 const std::string& numSplits,
21 const std::string& outputShape1,
22 const std::string& outputShape2,
23 const std::string& axisData,
24 const std::string& dataType)
25 {
26 m_JsonString = R"(
27 {
28 "version": 3,
29 "operator_codes": [ { "builtin_code": "SPLIT_V" } ],
30 "subgraphs": [ {
31 "tensors": [
32 {
33 "shape": )" + inputShape + R"(,
34 "type": )" + dataType + R"(,
35 "buffer": 0,
36 "name": "inputTensor",
37 "quantization": {
38 "min": [ 0.0 ],
39 "max": [ 255.0 ],
40 "scale": [ 1.0 ],
41 "zero_point": [ 0 ],
42 }
43 },
44 {
45 "shape": )" + sizeSplitsShape + R"(,
46 "type": "INT32",
47 "buffer": 1,
48 "name": "sizeSplits",
49 "quantization": {
50 "min": [ 0.0 ],
51 "max": [ 255.0 ],
52 "scale": [ 1.0 ],
53 "zero_point": [ 0 ],
54 }
55 },
56 {
57 "shape": )" + axisShape + R"(,
58 "type": "INT32",
59 "buffer": 2,
60 "name": "axis",
61 "quantization": {
62 "min": [ 0.0 ],
63 "max": [ 255.0 ],
64 "scale": [ 1.0 ],
65 "zero_point": [ 0 ],
66 }
67 },
68 {
69 "shape": )" + outputShape1 + R"( ,
70 "type":)" + dataType + R"(,
71 "buffer": 3,
72 "name": "outputTensor1",
73 "quantization": {
74 "min": [ 0.0 ],
75 "max": [ 255.0 ],
76 "scale": [ 1.0 ],
77 "zero_point": [ 0 ],
78 }
79 },
80 {
81 "shape": )" + outputShape2 + R"( ,
82 "type":)" + dataType + R"(,
83 "buffer": 4,
84 "name": "outputTensor2",
85 "quantization": {
86 "min": [ 0.0 ],
87 "max": [ 255.0 ],
88 "scale": [ 1.0 ],
89 "zero_point": [ 0 ],
90 }
91 }
92 ],
93 "inputs": [ 0, 1, 2 ],
94 "outputs": [ 3, 4 ],
95 "operators": [
96 {
97 "opcode_index": 0,
98 "inputs": [ 0, 1, 2 ],
99 "outputs": [ 3, 4 ],
100 "builtin_options_type": "SplitVOptions",
101 "builtin_options": {
102 "num_splits": )" + numSplits + R"(
103 },
104 "custom_options_format": "FLEXBUFFERS"
105 }
106 ],
107 } ],
108 "buffers" : [ {}, { "data": )" + splitValues + R"( }, { "data": )" + axisData + R"( }, {}, {}]
109 }
110 )";
111
112 Setup();
113 }
114};
115
116/*
117 * Tested inferred splitSizes with splitValues [-1, 1] locally.
118 */
119
120struct SimpleSplitVAxisOneFixture : SplitVFixture
121{
122 SimpleSplitVAxisOneFixture()
Jan Eilersc0761e92020-06-29 16:48:44 +0100123 : SplitVFixture( "[ 4, 2, 2, 2 ]", "[ 1, 0, 0, 0, 3, 0, 0, 0 ]", "[ 2 ]","[ ]", "2",
Ryan OShea86704732020-05-26 11:41:04 +0100124 "[ 1, 2, 2, 2 ]", "[ 3, 2, 2, 2 ]", "[ 0, 0, 0, 0 ]", "FLOAT32")
125 {}
126};
127
Sadik Armagan1625efc2021-06-10 18:24:34 +0100128TEST_CASE_FIXTURE(SimpleSplitVAxisOneFixture, "ParseAxisOneSplitVTwo")
Ryan OShea86704732020-05-26 11:41:04 +0100129{
130 RunTest<4, armnn::DataType::Float32>(
131 0,
132 { {"inputTensor", { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f,
133 9.0f, 10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 15.0f, 16.0f,
134 17.0f, 18.0f, 19.0f, 20.0f, 21.0f, 22.0f, 23.0f, 24.0f,
135 25.0f, 26.0f, 27.0f, 28.0f, 29.0f, 30.0f, 31.0f, 32.0f } } },
136 { {"outputTensor1", { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f } },
137 {"outputTensor2", { 9.0f, 10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 15.0f, 16.0f,
138 17.0f, 18.0f, 19.0f, 20.0f, 21.0f, 22.0f, 23.0f, 24.0f,
139 25.0f, 26.0f, 27.0f, 28.0f, 29.0f, 30.0f, 31.0f, 32.0f } } } );
140}
141
142struct SimpleSplitVAxisTwoFixture : SplitVFixture
143{
144 SimpleSplitVAxisTwoFixture()
Jan Eilersc0761e92020-06-29 16:48:44 +0100145 : SplitVFixture( "[ 2, 4, 2, 2 ]", "[ 3, 0, 0, 0, 1, 0, 0, 0 ]", "[ 2 ]","[ ]", "2",
Ryan OShea86704732020-05-26 11:41:04 +0100146 "[ 2, 3, 2, 2 ]", "[ 2, 1, 2, 2 ]", "[ 1, 0, 0, 0 ]", "FLOAT32")
147 {}
148};
149
Sadik Armagan1625efc2021-06-10 18:24:34 +0100150TEST_CASE_FIXTURE(SimpleSplitVAxisTwoFixture, "ParseAxisTwoSplitVTwo")
Ryan OShea86704732020-05-26 11:41:04 +0100151{
152 RunTest<4, armnn::DataType::Float32>(
153 0,
154 { {"inputTensor", { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f,
155 9.0f, 10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 15.0f, 16.0f,
156 17.0f, 18.0f, 19.0f, 20.0f, 21.0f, 22.0f, 23.0f, 24.0f,
157 25.0f, 26.0f, 27.0f, 28.0f, 29.0f, 30.0f, 31.0f, 32.0f } } },
158 { {"outputTensor1", { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f,
159 9.0f, 10.0f, 11.0f, 12.0f, 17.0f, 18.0f, 19.0f, 20.0f,
160 21.0f, 22.0f, 23.0f, 24.0f, 25.0f, 26.0f, 27.0f, 28.0f } },
161 {"outputTensor2", { 13.0f, 14.0f, 15.0f, 16.0f, 29.0f, 30.0f, 31.0f, 32.0f } } } );
162}
163
164struct SimpleSplitVAxisThreeFixture : SplitVFixture
165{
166 SimpleSplitVAxisThreeFixture()
Jan Eilersc0761e92020-06-29 16:48:44 +0100167 : SplitVFixture( "[ 2, 2, 4, 2 ]", "[ 1, 0, 0, 0, 3, 0, 0, 0 ]", "[ 2 ]","[ ]", "2",
Ryan OShea86704732020-05-26 11:41:04 +0100168 "[ 2, 2, 1, 2 ]", "[ 2, 2, 3, 2 ]", "[ 2, 0, 0, 0 ]", "FLOAT32")
169 {}
170};
171
Sadik Armagan1625efc2021-06-10 18:24:34 +0100172TEST_CASE_FIXTURE(SimpleSplitVAxisThreeFixture, "ParseAxisThreeSplitVTwo")
Ryan OShea86704732020-05-26 11:41:04 +0100173{
174 RunTest<4, armnn::DataType::Float32>(
175 0,
176 { {"inputTensor", { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f,
177 9.0f, 10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 15.0f, 16.0f,
178 17.0f, 18.0f, 19.0f, 20.0f, 21.0f, 22.0f, 23.0f, 24.0f,
179 25.0f, 26.0f, 27.0f, 28.0f, 29.0f, 30.0f, 31.0f, 32.0f } } },
180 { {"outputTensor1", { 1.0f, 2.0f, 9.0f, 10.0f, 17.0f, 18.0f, 25.0f, 26.0f } },
181 {"outputTensor2", { 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 11.0f, 12.0f,
182 13.0f, 14.0f, 15.0f, 16.0f, 19.0f, 20.0f, 21.0f, 22.0f,
183 23.0f, 24.0f, 27.0f, 28.0f, 29.0f, 30.0f, 31.0f, 32.0f } } } );
184}
185
186struct SimpleSplitVAxisFourFixture : SplitVFixture
187{
188 SimpleSplitVAxisFourFixture()
Jan Eilersc0761e92020-06-29 16:48:44 +0100189 : SplitVFixture( "[ 2, 2, 2, 4 ]", "[ 3, 0, 0, 0, 1, 0, 0, 0 ]", "[ 2 ]","[ ]", "2",
Ryan OShea86704732020-05-26 11:41:04 +0100190 "[ 2, 2, 2, 3 ]", "[ 2, 2, 2, 1 ]", "[ 3, 0, 0, 0 ]", "FLOAT32")
191 {}
192};
193
Sadik Armagan1625efc2021-06-10 18:24:34 +0100194TEST_CASE_FIXTURE(SimpleSplitVAxisFourFixture, "ParseAxisFourSplitVTwo")
Ryan OShea86704732020-05-26 11:41:04 +0100195{
196 RunTest<4, armnn::DataType::Float32>(
197 0,
198 { {"inputTensor", { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f,
199 9.0f, 10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 15.0f, 16.0f,
200 17.0f, 18.0f, 19.0f, 20.0f, 21.0f, 22.0f, 23.0f, 24.0f,
201 25.0f, 26.0f, 27.0f, 28.0f, 29.0f, 30.0f, 31.0f, 32.0f } } },
202 { {"outputTensor1", { 1.0f, 2.0f, 3.0f, 5.0f, 6.0f, 7.0f, 9.0f, 10.0f,
203 11.0f, 13.0f, 14.0f, 15.0f, 17.0f, 18.0f, 19.0f, 21.0f,
204 22.0f, 23.0f, 25.0f, 26.0f, 27.0f, 29.0f, 30.0f, 31.0f} },
205 {"outputTensor2", { 4.0f, 8.0f, 12.0f, 16.0f, 20.0f, 24.0f, 28.0f, 32.0f } } } );
206}
207
Sadik Armagan1625efc2021-06-10 18:24:34 +0100208}