blob: 89a6640e41cef2853df09cc96ad027cdeb718e65 [file] [log] [blame]
Narumol Prangnawaratbbf71a62020-09-07 14:05:22 +01001//
2// Copyright © 2020 Arm Ltd and Contributors. All rights reserved.
3// SPDX-License-Identifier: MIT
4//
5
6#include "armnnTfLiteParser/ITfLiteParser.hpp"
7#include "ParserFlatbuffersFixture.hpp"
8
9#include <string>
10
11#include <boost/test/unit_test.hpp>
12
13BOOST_AUTO_TEST_SUITE(TensorflowLiteParser)
14
15struct LoadScopeDynamicTensorFixture : public ParserFlatbuffersFixture
16{
17 explicit LoadScopeDynamicTensorFixture(const std::string& shape0,
18 const std::string& shape1,
19 const std::string& shape2)
20 {
21 m_JsonString = R"(
22 {
23 "version": 3,
24 "operator_codes": [
25 {
26 "builtin_code": "AVERAGE_POOL_2D",
27 "version": 1
28 },
29 {
30 "builtin_code": "SOFTMAX",
31 "version": 1
32 }
33 ],
34 "subgraphs": [
35 {
36 "tensors": [
37 {
38 "shape": )" + shape0 + R"(,
39 "type": "FLOAT32",
40 "buffer": 1,
41 "name": "input0",
42 "quantization": {
43 "details_type": 0,
44 "quantized_dimension": 0
45 },
46 "is_variable": false
47 },
48 {
49 "shape": )" + shape1 + R"(,
50 "type": "FLOAT32",
51 "buffer": 3,
52 "name": "output",
53 "quantization": {
54 "details_type": 0,
55 "quantized_dimension": 0
56 },
57 "is_variable": false
58 },
59 {
60 "shape": )" + shape2 + R"(,
61 "type": "FLOAT32",
62 "buffer": 2,
63 "name": "model/average_pooling2d/AvgPool",
64 "quantization": {
65 "details_type": 0,
66 "quantized_dimension": 0
67 },
68 "is_variable": false
69 }
70 ],
71 "inputs": [
72 0
73 ],
74 "outputs": [
75 1
76 ],
77 "operators": [
78 {
79 "opcode_index": 1,
80 "inputs": [
81 2
82 ],
83 "outputs": [
84 1
85 ],
86 "builtin_options_type": "SoftmaxOptions",
87 "builtin_options": {
88 "beta": 1.0
89 },
90 "custom_options_format": "FLEXBUFFERS"
91 },
92 {
93 "opcode_index": 0,
94 "inputs": [
95 0
96 ],
97 "outputs": [
98 2
99 ],
100 "builtin_options_type": "Pool2DOptions",
101 "builtin_options": {
102 "padding": "VALID",
103 "stride_w": 2,
104 "stride_h": 2,
105 "filter_width": 2,
106 "filter_height": 2,
107 "fused_activation_function": "NONE"
108 },
109 "custom_options_format": "FLEXBUFFERS"
110 }
111 ],
112 "name": "main"
113 }
114 ],
115 "description": "MLIR Converted.",
116 "buffers": [
117 {
118 },
119 {
120 },
121 {
122 },
123 {
124 }
125 ]
126 }
127 )";
128 Setup();
129 }
130};
131
132struct LoadScopeDynamicTensor0Fixture : LoadScopeDynamicTensorFixture
133{
134 LoadScopeDynamicTensor0Fixture() : LoadScopeDynamicTensorFixture("[ 1, 2, 3, 2 ]", "[]", "[]") {}
135};
136
137struct LoadScopeDynamicTensor1Fixture : LoadScopeDynamicTensorFixture
138{
139 LoadScopeDynamicTensor1Fixture() : LoadScopeDynamicTensorFixture("[ 1, 2, 4, 1 ]", "[ 1, 1, 2, 1 ]", "[]") {}
140};
141
142struct LoadScopeDynamicTensor2Fixture : LoadScopeDynamicTensorFixture
143{
144 LoadScopeDynamicTensor2Fixture() : LoadScopeDynamicTensorFixture("[ 1, 3, 3, 2 ]", "[ ]", "[ 1, 1, 1, 2 ]") {}
145};
146
147BOOST_FIXTURE_TEST_CASE(LoadScopeDynamicTensor0, LoadScopeDynamicTensor0Fixture)
148{
149 RunTest<4, armnn::DataType::Float32, armnn::DataType::Float32>(
150 0,
151 { {"input0", { 0.f, 1.f, 2.f, 3.f, 4.f, 5.f, 6.f, 7.f, 8.f, 9.f, 10.f, 11.f }} },
152 { {"output", { 0.26894143f, 0.7310586f }} },
153 true);
154}
155
156BOOST_FIXTURE_TEST_CASE(LoadScopeDynamicTensor1, LoadScopeDynamicTensor1Fixture)
157{
158 RunTest<4, armnn::DataType::Float32, armnn::DataType::Float32>(
159 0,
160 { {"input0", { 0.f, 1.f, 2.f, 3.f, 4.f, 5.f, 6.f, 7.f }} },
161 { {"output", { 1.f, 1.f }} },
162 true);
163}
164
165BOOST_FIXTURE_TEST_CASE(LoadScopeDynamicTensor2, LoadScopeDynamicTensor2Fixture)
166{
167 RunTest<4, armnn::DataType::Float32, armnn::DataType::Float32>(
168 0,
169 { {"input0", { 0.f, 1.f, 2.f, 3.f, 4.f, 5.f, 6.f, 7.f, 8.f, 0.f, 1.f, 2.f, 3.f, 4.f, 5.f, 6.f, 7.f, 8.f }} },
170 { {"output", { 0.7772999f, 0.22270015f }} },
171 true);
172}
173
Narumol Prangnawarat16f82f92020-09-14 16:12:44 +0100174struct LoadScopeDynamicTensorBroadcastingFixture : public ParserFlatbuffersFixture
175{
176 explicit LoadScopeDynamicTensorBroadcastingFixture(const std::string& inputShape0,
177 const std::string& inputShape1,
178 const std::string& inputShape2,
179 const std::string& addShape,
180 const std::string& outputShape)
181 {
182 m_JsonString = R"(
183 {
184 "version": 3,
185 "operator_codes": [
186 {
187 "builtin_code": "ADD",
188 "version": 1
189 },
190 {
191 "builtin_code": "SUB",
192 "version": 1
193 }
194 ],
195 "subgraphs": [
196 {
197 "tensors": [
198 {
199 "shape": )" + inputShape0 + R"(,
200 "type": "FLOAT32",
201 "buffer": 1,
202 "name": "input0",
203 "quantization": {
204 "details_type": 0,
205 "quantized_dimension": 0
206 },
207 "is_variable": false
208 },
209 {
210 "shape": )" + inputShape1 + R"(,
211 "type": "FLOAT32",
212 "buffer": 2,
213 "name": "input1",
214 "quantization": {
215 "details_type": 0,
216 "quantized_dimension": 0
217 },
218 "is_variable": false
219 },
220 {
221 "shape": )" + outputShape + R"(,
222 "type": "FLOAT32",
223 "buffer": 5,
224 "name": "output",
225 "quantization": {
226 "details_type": 0,
227 "quantized_dimension": 0
228 },
229 "is_variable": false
230 },
231
232 {
233 "shape": )" + addShape + R"(,
234 "type": "FLOAT32",
235 "buffer": 4,
236 "name": "model/add/add",
237 "quantization": {
238 "details_type": 0,
239 "quantized_dimension": 0
240 },
241 "is_variable": false
242 },
243 {
244 "shape": )" + inputShape2 + R"(,
245 "type": "FLOAT32",
246 "buffer": 3,
247 "name": "input2",
248 "quantization": {
249 "details_type": 0,
250 "quantized_dimension": 0
251 },
252 "is_variable": false
253 },
254 ],
255 "inputs": [
256 0,
257 1,
258 4
259 ],
260 "outputs": [
261 2
262 ],
263 "operators": [
264 {
265 "opcode_index": 0,
266 "inputs": [
267 0,
268 1
269 ],
270 "outputs": [
271 3
272 ],
273 "builtin_options_type": "AddOptions",
274 "builtin_options": {
275 "fused_activation_function": "NONE"
276 },
277 "custom_options_format": "FLEXBUFFERS"
278 },
279 {
280 "opcode_index": 1,
281 "inputs": [
282 3,
283 4
284 ],
285 "outputs": [
286 2
287 ],
288 "builtin_options_type": "SubOptions",
289 "builtin_options": {
290 "fused_activation_function": "NONE"
291 },
292 "custom_options_format": "FLEXBUFFERS"
293 }
294 ],
295 "name": "main"
296 }
297 ],
298 "buffers": [
299 {
300 },
301 {
302 },
303 {
304 },
305 {
306 },
307 {
308 },
309 {
310 }
311 ]
312 }
313 )";
314 Setup();
315 }
316};
317
318struct LoadScopeDynamicTensorBroadcasting3DFixture : LoadScopeDynamicTensorBroadcastingFixture
319{
320 LoadScopeDynamicTensorBroadcasting3DFixture() : LoadScopeDynamicTensorBroadcastingFixture("[ 1, 2, 3, 2 ]",
321 "[ 2, 3, 2 ]",
322 "[ 2, 3, 2 ]",
323 "[ 1, 2, 3, 2 ]", "[]") {}
324};
325
326struct LoadScopeDynamicTensorBroadcasting2DFixture : LoadScopeDynamicTensorBroadcastingFixture
327{
328 LoadScopeDynamicTensorBroadcasting2DFixture() : LoadScopeDynamicTensorBroadcastingFixture("[ 1, 2, 3, 2 ]",
329 "[ 3, 2 ]",
330 "[ 3, 2 ]",
331 "[]", "[]") {}
332};
333
334struct LoadScopeDynamicTensorBroadcasting1DFixture : LoadScopeDynamicTensorBroadcastingFixture
335{
336 LoadScopeDynamicTensorBroadcasting1DFixture() : LoadScopeDynamicTensorBroadcastingFixture("[ 1, 2, 3, 2 ]",
337 "[ 1 ]",
338 "[ 1 ]",
339 "[]",
340 "[ 1, 2, 3, 2 ]") {}
341};
342
343BOOST_FIXTURE_TEST_CASE(LoadScopeDynamicTensorBroadcasting3D, LoadScopeDynamicTensorBroadcasting3DFixture)
344{
345 RunTest<4, armnn::DataType::Float32, armnn::DataType::Float32>(
346 0,
347 { {"input0", { 0.f, 1.f, 2.f, 3.f, 4.f, 5.f, 6.f, 7.f, 8.f, 9.f, 10.f, 11.f }},
348 {"input1", { 3.f, 4.f, 5.f, 6.f, 7.f, 8.f, 9.f, 10.f, 11.f, 12.f, 13.f, 14.f }},
349 {"input2", { 1.f, 2.f, 3.f, 4.f, 5.f, 6.f, 7.f, 8.f, 9.f, 10.f, 11.f, 12.f }}
350 },
351 { {"output", { 2.f, 3.f, 4.f, 5.f, 6.f, 7.f, 8.f, 9.f, 10.f, 11.f, 12.f, 13.f }} },
352 true);
353}
354
355BOOST_FIXTURE_TEST_CASE(LoadScopeDynamicTensorBroadcasting2D, LoadScopeDynamicTensorBroadcasting2DFixture)
356{
357 RunTest<4, armnn::DataType::Float32, armnn::DataType::Float32>(
358 0,
359 { {"input0", { 0.f, 1.f, 2.f, 3.f, 4.f, 5.f, 6.f, 7.f, 8.f, 9.f, 10.f, 11.f }},
360 {"input1", { 3.f, 4.f, 5.f, 6.f, 7.f, 8.f }},
361 {"input2", { -1.f, -2.f, 3.f, 4.f, 5.f, 6.f }}
362 },
363 { {"output", { 4.f, 7.f, 4.f, 5.f, 6.f, 7.f, 10.f, 13.f, 10.f, 11.f, 12.f, 13.f }} },
364 true);
365}
366
367BOOST_FIXTURE_TEST_CASE(LoadScopeDynamicTensorBroadcasting1D, LoadScopeDynamicTensorBroadcasting1DFixture)
368{
369 RunTest<4, armnn::DataType::Float32, armnn::DataType::Float32>(
370 0,
371 { {"input0", { 0.f, 1.f, 2.f, 3.f, 4.f, 5.f, 6.f, 7.f, 8.f, 9.f, 10.f, 11.f }},
372 {"input1", { 5.f }},
373 {"input2", { 1.f }}
374 },
375 { {"output", { 4.f, 5.f, 6.f, 7.f, 8.f, 9.f, 10.f, 11.f, 12.f, 13.f, 14.f, 15.f }} },
376 true);
377}
378
Narumol Prangnawaratbbf71a62020-09-07 14:05:22 +0100379BOOST_AUTO_TEST_SUITE_END()