blob: 6ff4f53bfc8517750cfea5d2288612a6d9158007 [file] [log] [blame]
Bruno Goncalvesbaded142019-02-08 19:02:48 -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 SpaceToBatchNDFixture : public ParserFlatbuffersFixture
16{
17 explicit SpaceToBatchNDFixture(const std::string & inputShape,
18 const std::string & outputShape,
19 const std::string & blockShapeData,
20 const std::string & padListData)
21 {
22 m_JsonString = R"(
23 {
24 "version": 3,
25 "operator_codes": [ { "builtin_code": "SPACE_TO_BATCH_ND" } ],
26 "subgraphs": [ {
27 "tensors": [
28 {
29 "shape": )" + inputShape + R"(,
30 "type": "FLOAT32",
31 "buffer": 0,
32 "name": "inputTensor",
33 "quantization": {
34 "min": [ 0.0 ],
35 "max": [ 255.0 ],
36 "scale": [ 1.0 ],
37 "zero_point": [ 0 ],
38 }
39 },
40 {
41 "shape": )" + outputShape + R"(,
42 "type": "FLOAT32",
43 "buffer": 1,
44 "name": "outputTensor",
45 "quantization": {
46 "min": [ 0.0 ],
47 "max": [ 255.0 ],
48 "scale": [ 1.0 ],
49 "zero_point": [ 0 ],
50 }
51 },
52 {
53 "shape": [ 2 ],
54 "type": "INT32",
55 "buffer": 2,
56 "name": "blockShapeTensor",
57 "quantization": {
58 "min": [ 0.0 ],
59 "max": [ 255.0 ],
60 "scale": [ 1.0 ],
61 "zero_point": [ 0 ],
62 }
63 },
64 {
65 "shape": [ 2, 2 ],
66 "type": "INT32",
67 "buffer": 3,
68 "name": "padListTensor",
69 "quantization": {
70 "min": [ 0.0 ],
71 "max": [ 255.0 ],
72 "scale": [ 1.0 ],
73 "zero_point": [ 0 ],
74 }
75 }
76 ],
77 "inputs": [ 0 ],
78 "outputs": [ 1 ],
79 "operators": [
80 {
81 "opcode_index": 0,
82 "inputs": [ 0, 2, 3 ],
83 "outputs": [ 1 ],
84 "custom_options_format": "FLEXBUFFERS"
85 }
86 ],
87 } ],
88 "buffers" : [
89 { },
90 { },
91 { "data": )" + blockShapeData + R"(, },
92 { "data": )" + padListData + R"(, },
93 ]
94 }
95 )";
96 Setup();
97 }
98};
99
100struct SpaceToBatchNDFixtureSimpleTest : public SpaceToBatchNDFixture
101{
102 SpaceToBatchNDFixtureSimpleTest() : SpaceToBatchNDFixture("[ 1, 4, 4, 1 ]",
103 "[ 4, 2, 2, 1 ]",
104 "[ 2,0,0,0, 2,0,0,0 ]",
105 "[ 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0 ]") {}
106};
107
108BOOST_FIXTURE_TEST_CASE(SpaceToBatchNdSimpleTest, SpaceToBatchNDFixtureSimpleTest)
109{
110 RunTest<4, armnn::DataType::Float32>
111 (0,
112 {{ "inputTensor", { 1.0f, 2.0f, 3.0f, 4.0f,
113 5.0f, 6.0f, 7.0f, 8.0f,
114 9.0f, 10.0f, 11.0f, 12.0f,
115 13.0f, 14.0f, 15.0f, 16.0f }}},
116 {{ "outputTensor", { 1.0f, 3.0f, 9.0f, 11.0f,
117 2.0f, 4.0f, 10.0f, 12.0f,
118 5.0f, 7.0f, 13.0f, 15.0f,
119 6.0f, 8.0f, 14.0f, 16.0f }}});
120}
121
122
123struct SpaceToBatchNDFixtureMultipleInputBatchesTest : public SpaceToBatchNDFixture
124{
125 SpaceToBatchNDFixtureMultipleInputBatchesTest() : SpaceToBatchNDFixture("[ 2, 2, 4, 1 ]",
126 "[ 8, 1, 2, 1 ]",
127 "[ 2,0,0,0, 2,0,0,0 ]",
128 "[ 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0 ]") {}
129};
130
131BOOST_FIXTURE_TEST_CASE(SpaceToBatchNdMultipleInputBatchesTest, SpaceToBatchNDFixtureMultipleInputBatchesTest)
132{
133 RunTest<4, armnn::DataType::Float32>
134 (0,
135 {{ "inputTensor", { 1.0f, 2.0f, 3.0f, 4.0f,
136 5.0f, 6.0f, 7.0f, 8.0f,
137 9.0f, 10.0f, 11.0f, 12.0f,
138 13.0f, 14.0f, 15.0f, 16.0f }}},
139 {{ "outputTensor", { 1.0f, 3.0f, 9.0f, 11.0f,
140 2.0f, 4.0f, 10.0f, 12.0f,
141 5.0f, 7.0f, 13.0f, 15.0f,
142 6.0f, 8.0f, 14.0f, 16.0f }}});
143}
144
145struct SpaceToBatchNDFixturePaddingTest : public SpaceToBatchNDFixture
146{
147 SpaceToBatchNDFixturePaddingTest() : SpaceToBatchNDFixture("[ 1, 5, 2, 1 ]",
148 "[ 6, 2, 2, 1 ]",
149 "[ 3,0,0,0, 2,0,0,0 ]",
150 "[ 1,0,0,0, 0,0,0,0, 2,0,0,0, 0,0,0,0 ]") {}
151};
152
153BOOST_FIXTURE_TEST_CASE(SpaceToBatchNdPaddingTest, SpaceToBatchNDFixturePaddingTest)
154{
155 RunTest<4, armnn::DataType::Float32>
156 (0,
157 {{ "inputTensor", { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f,
158 6.0f, 7.0f, 8.0f, 9.0f, 10.0f }}},
159 {{ "outputTensor", { 0.0f, 0.0f,
160 0.0f, 5.0f,
161
162 0.0f, 0.0f,
163 0.0f, 6.0f,
164
165 0.0f, 1.0f,
166 0.0f, 7.0f,
167
168 0.0f, 2.0f,
169 0.0f, 8.0f,
170
171 0.0f, 3.0f,
172 0.0f, 9.0f,
173
174 0.0f, 4.0f,
175 0.0f, 10.0f, }}});
176}
177
178BOOST_AUTO_TEST_SUITE_END()