blob: 83c4088377a3ce7dfbf18e911177e60fb2b06ab5 [file] [log] [blame]
Narumol Prangnawaratbfaee6b2021-05-24 18:50:24 +01001//
2// Copyright © 2021 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
12BOOST_AUTO_TEST_SUITE(TensorflowLiteParser)
13
14struct PreluFixture : public ParserFlatbuffersFixture
15{
16 explicit PreluFixture(const std::string& inputShape,
17 const std::string& alphaShape,
18 const std::string& outputShape,
19 const std::string& inputIndex,
20 const std::string& alphaData)
21 {
22 m_JsonString = R"(
23 {
24 "version": 3,
25 "operator_codes": [
26 {
27 "builtin_code": "PRELU",
28 "version": 1
29 }
30 ],
31 "subgraphs": [
32 {
33 "tensors": [
34 {
35 "shape": )" + inputShape + R"(,
36 "type": "FLOAT32",
37 "buffer": 1,
38 "name": "input0",
39 "quantization": {
40 "details_type": "NONE",
41 "quantized_dimension": 0
42 },
43 "is_variable": false
44 },
45 {
46 "shape": )" + alphaShape + R"(,
47 "type": "FLOAT32",
48 "buffer": 2,
49 "name": "input1",
50 "quantization": {
51 "details_type": "NONE",
52 "quantized_dimension": 0
53 },
54 "is_variable": false
55 },
56 {
57 "shape": )" + outputShape + R"(,
58 "type": "FLOAT32",
59 "buffer": 3,
60 "name": "output",
61 "quantization": {
62 "details_type": "NONE",
63 "quantized_dimension": 0
64 },
65 "is_variable": false
66 }
67 ],
68 "inputs": )" + inputIndex + R"(,
69 "outputs": [
70 2
71 ],
72 "operators": [
73 {
74 "opcode_index": 0,
75 "inputs": [
76 0,
77 1
78 ],
79 "outputs": [
80 2
81 ],
82 "builtin_options_type": "NONE",
83 "custom_options_format": "FLEXBUFFERS"
84 }
85 ],
86 "name": "main"
87 }
88 ],
89 "description": "MLIR Converted.",
90 "buffers": [
91 {
92 },
93 {
94 },
95 { )" + alphaData + R"(
96 },
97 {
98 }
99 ]
100 }
101 )";
102 Setup();
103 }
104};
105
Narumol Prangnawaratbf99b5f2021-05-27 09:55:43 +0100106struct PreluNetworkFixture : public ParserFlatbuffersFixture
107{
108 explicit PreluNetworkFixture()
109 {
110 m_JsonString = R"(
111 {
112 "version": 3,
113 "operator_codes": [
114 {
115 "builtin_code": "PRELU",
116 "version": 1
117 },
118 {
119 "builtin_code": "MUL",
120 "version": 1
121 },
122 {
123 "builtin_code": "ADD",
124 "version": 1
125 }
126 ],
127 "subgraphs": [
128 {
129 "tensors": [
130 {
131 "shape": [
132 1,
133 2,
134 3
135 ],
136 "type": "FLOAT32",
137 "buffer": 6,
138 "name": "output",
139 "quantization": {
140 "details_type": "NONE",
141 "quantized_dimension": 0
142 },
143 },
144 {
145 "shape": [
146 1,
147 2,
148 3
149 ],
150 "type": "FLOAT32",
151 "buffer": 5,
152 "name": "mul",
153 "quantization": {
154 "details_type": "NONE",
155 "quantized_dimension": 0
156 }
157 },
158 {
159 "shape": [
160 1,
161 2,
162 3
163 ],
164 "type": "FLOAT32",
165 "buffer": 1,
166 "name": "input0",
167 "quantization": {
168 "details_type": "NONE",
169 "quantized_dimension": 0
170 }
171 },
172 {
173 "shape": [
174 2,
175 3
176 ],
177 "type": "FLOAT32",
178 "buffer": 2,
179 "name": "alpha",
180 "quantization": {
181 "details_type": "NONE",
182 "quantized_dimension": 0
183 }
184 },
185 {
186 "shape": [
187 1
188 ],
189 "type": "FLOAT32",
190 "buffer": 3,
191 "name": "const0",
192 "quantization": {
193 "details_type": "NONE",
194 "quantized_dimension": 0
195 }
196 },
197 {
198 "shape": [
199 1,
200 2,
201 3
202 ],
203 "type": "FLOAT32",
204 "buffer": 4,
205 "name": "prelumul",
206 "quantization": {
207 "details_type": "NONE",
208 "quantized_dimension": 0
209 }
210 }
211 ],
212 "inputs": [
213 2
214 ],
215 "outputs": [
216 0
217 ],
218 "operators": [
219 {
220 "opcode_index": 0,
221 "inputs": [
222 2,
223 3
224 ],
225 "outputs": [
226 5
227 ],
228 "builtin_options_type": "NONE",
229 "custom_options_format": "FLEXBUFFERS"
230 },
231 {
232 "opcode_index": 1,
233 "inputs": [
234 5,
235 4
236 ],
237 "outputs": [
238 1
239 ],
240 "builtin_options_type": "MulOptions",
241 "builtin_options": {
242 "fused_activation_function": "NONE"
243 },
244 "custom_options_format": "FLEXBUFFERS"
245 },
246 {
247 "opcode_index": 2,
248 "inputs": [
249 5,
250 1
251 ],
252 "outputs": [
253 0
254 ],
255 "builtin_options_type": "AddOptions",
256 "builtin_options": {
257 "fused_activation_function": "NONE"
258 },
259 "custom_options_format": "FLEXBUFFERS"
260 }
261 ],
262 "name": "main"
263 }
264 ],
265 "buffers": [
266 {
267 },
268 {
269 },
270 {
271 "data": [
272 0,
273 0,
274 128,
275 62,
276 0,
277 0,
278 128,
279 62,
280 0,
281 0,
282 128,
283 62,
284 0,
285 0,
286 128,
287 62,
288 0,
289 0,
290 128,
291 62,
292 0,
293 0,
294 128,
295 62
296 ]
297 },
298 {
299 "data": [
300 0,
301 0,
302 160,
303 64
304 ]
305 },
306 {
307 },
308 {
309 },
310 {
311 },
312 {
313 }
314 ],
315 }
316 )";
317 Setup();
318 }
319};
320
Narumol Prangnawaratbfaee6b2021-05-24 18:50:24 +0100321struct SimplePreluFixture : PreluFixture
322{
323 SimplePreluFixture() : PreluFixture("[ 2, 3 ]",
Narumol Prangnawarat4a4af112021-05-25 14:26:24 +0100324 "[ 1 ]",
Narumol Prangnawaratbfaee6b2021-05-24 18:50:24 +0100325 "[ 2, 3 ]",
326 "[ 0, 1 ]",
327 "") {}
328};
329
330struct PreluConstAlphaFixture : PreluFixture
331{
332 PreluConstAlphaFixture() : PreluFixture(
Narumol Prangnawarat4a4af112021-05-25 14:26:24 +0100333 "[ 1, 2, 3 ]",
334 "[ 1, 2, 3 ]",
335 "[ 1, 2, 3 ]",
Narumol Prangnawaratbfaee6b2021-05-24 18:50:24 +0100336 "[ 0 ]",
337 "\"data\": [ 0, 0, 128, 62, 0, 0, 128, 62, 0, 0, 128, 62, 0, 0, 128, 62, 0, 0, 128, 62, 0, 0, 128, 62 ]"){}
338};
339
Narumol Prangnawarat4a4af112021-05-25 14:26:24 +0100340struct PreluBroadcastAlphaFixture : PreluFixture
341{
342 PreluBroadcastAlphaFixture() : PreluFixture(
343 "[ 1, 1, 2, 3 ]",
344 "[ 1, 3 ]",
345 "[ 1, 1, 2, 3 ]",
346 "[ 0 ]",
347 "\"data\": [ 0, 0, 128, 62, 0, 0, 128, 62, 0, 0, 128, 62 ]"){}
348};
349
Narumol Prangnawaratbfaee6b2021-05-24 18:50:24 +0100350struct PreluDynamicTensorFixture : PreluFixture
351{
352 PreluDynamicTensorFixture() : PreluFixture("[ 2, 3 ]",
353 "[ 1, 1 ]",
354 "[]",
355 "[ 0 ]",
356 "\"data\": [ 0, 0, 128, 62 ]") {}
357};
358
359BOOST_FIXTURE_TEST_CASE(SimplePrelu, SimplePreluFixture)
360{
361 RunTest<2, armnn::DataType::Float32>(
362 0,
363 {{"input0", { -14.f, 2.f, 0.f, 1.f, -5.f, 14.f }},{"input1", { 0.25f }}},
364 {{"output", { -3.5f, 2.f, 0.f, 1.f, -1.25f, 14.f }}});
365}
366
367BOOST_FIXTURE_TEST_CASE(PreluConstAlpha, PreluConstAlphaFixture)
368{
Narumol Prangnawarat4a4af112021-05-25 14:26:24 +0100369 RunTest<3, armnn::DataType::Float32>(
370 0,
371 {{"input0", { -14.f, 2.f, 0.f, 1.f, -5.f, 14.f }}},
372 {{"output", { -3.5f, 2.f, 0.f, 1.f, -1.25f, 14.f }}});
373}
374
375BOOST_FIXTURE_TEST_CASE(PreluBroadcastAlpha, PreluBroadcastAlphaFixture)
376{
377 RunTest<4, armnn::DataType::Float32>(
Narumol Prangnawaratbfaee6b2021-05-24 18:50:24 +0100378 0,
379 {{"input0", { -14.f, 2.f, 0.f, 1.f, -5.f, 14.f }}},
380 {{"output", { -3.5f, 2.f, 0.f, 1.f, -1.25f, 14.f }}});
381}
382
383BOOST_FIXTURE_TEST_CASE(PreluDynamicTensor, PreluDynamicTensorFixture)
384{
385 RunTest<2, armnn::DataType::Float32, armnn::DataType::Float32>(
386 0,
387 {{"input0", { -14.f, 2.f, 0.f, 1.f, -5.f, 14.f }}},
388 {{"output", { -3.5f, 2.f, 0.f, 1.f, -1.25f, 14.f }}},
389 true);
390}
391
Narumol Prangnawaratbf99b5f2021-05-27 09:55:43 +0100392BOOST_FIXTURE_TEST_CASE(PreluNetwork, PreluNetworkFixture)
393{
394 RunTest<3, armnn::DataType::Float32>(
395 0,
396 {{"input0", { -14.f, 2.f, 0.f, 1.f, -5.f, 14.f }}},
397 {{"output", { -21.f, 12.f, 0.f, 6.f, -7.5f, 84.f }}});
398}
399
Narumol Prangnawaratbfaee6b2021-05-24 18:50:24 +0100400BOOST_AUTO_TEST_SUITE_END()