blob: b94a9832b743813ad08d6f8a488c386dab4d9993 [file] [log] [blame]
josh minorba424d22019-11-13 10:55:17 -06001//
2// Copyright © 2019 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
10BOOST_AUTO_TEST_SUITE(TensorflowLiteParser)
11
12struct SliceFixture : public ParserFlatbuffersFixture
13{
14 explicit SliceFixture(const std::string & inputShape,
15 const std::string & outputShape,
16 const std::string & beginData,
17 const std::string & sizeData)
18 {
19 m_JsonString = R"(
20 {
21 "version": 3,
22 "operator_codes": [
23 {
24 "builtin_code": "SLICE",
25 "version": 1
26 }
27 ],
28 "subgraphs": [
29 {
30 "tensors": [
31 {
32 "shape": )" + inputShape + R"(,
33 "type": "FLOAT32",
34 "buffer": 0,
35 "name": "inputTensor",
36 "quantization": {
37 "min": [
38 0.0
39 ],
40 "max": [
41 255.0
42 ],
43 "details_type": 0,
44 "quantized_dimension": 0
45 },
46 "is_variable": false
47 },
48 {
49 "shape": )" + outputShape + R"(,
50 "type": "FLOAT32",
51 "buffer": 1,
52 "name": "outputTensor",
53 "quantization": {
54 "details_type": 0,
55 "quantized_dimension": 0
56 },
57 "is_variable": false
58 })";
59 m_JsonString += R"(,
60 {
61 "shape": [
62 3
63 ],
64 "type": "INT32",
65 "buffer": 2,
66 "name": "beginTensor",
67 "quantization": {
68 }
69 })";
70 m_JsonString += R"(,
71 {
72 "shape": [
73 3
74 ],
75 "type": "INT32",
76 "buffer": 3,
77 "name": "sizeTensor",
78 "quantization": {
79 }
80 })";
81 m_JsonString += R"(],
82 "inputs": [
83 0
84 ],
85 "outputs": [
86 1
87 ],
88 "operators": [
89 {
90 "opcode_index": 0,
91 "inputs": [
92 0,
93 2,
94 3)";
95 m_JsonString += R"(],
96 "outputs": [
97 1
98 ],
99 mutating_variable_inputs: [
100 ]
101 }
102 ]
103 }
104 ],
105 "description": "TOCO Converted.",
106 "buffers": [
107 { },
108 { })";
109 m_JsonString += R"(,{"data": )" + beginData + R"( })";
110 m_JsonString += R"(,{"data": )" + sizeData + R"( })";
111 m_JsonString += R"(
112 ]
113 }
114 )";
115 SetupSingleInputSingleOutput("inputTensor", "outputTensor");
116 }
117};
118
119struct SliceFixtureSingleDim : SliceFixture
120{
121 SliceFixtureSingleDim() : SliceFixture("[ 3, 2, 3 ]",
122 "[ 1, 1, 3 ]",
123 "[ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]",
124 "[ 1, 0, 0, 0, 1, 0, 0, 0, 3, 0, 0, 0 ]") {}
125};
126
127BOOST_FIXTURE_TEST_CASE(SliceSingleDim, SliceFixtureSingleDim)
128{
129 RunTest<3, armnn::DataType::Float32>(
130 0,
131 {{"inputTensor", { 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6 }}},
132 {{"outputTensor", { 3, 3, 3 }}});
133
134 BOOST_TEST((m_Parser->GetNetworkOutputBindingInfo(0, "outputTensor").second.GetShape()
135 == armnn::TensorShape({1,1,3})));
136}
137
138struct SliceFixtureD123 : SliceFixture
139{
140 SliceFixtureD123() : SliceFixture("[ 3, 2, 3 ]",
141 "[ 1, 2, 3 ]",
142 "[ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]",
143 "[ 1, 0, 0, 0, 2, 0, 0, 0, 3, 0, 0, 0 ]") {}
144};
145
146BOOST_FIXTURE_TEST_CASE(SliceD123, SliceFixtureD123)
147{
148 RunTest<3, armnn::DataType::Float32>(
149 0,
150 {{"inputTensor", { 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6 }}},
151 {{"outputTensor", { 3, 3, 3, 4, 4, 4 }}});
152
153 BOOST_TEST((m_Parser->GetNetworkOutputBindingInfo(0, "outputTensor").second.GetShape()
154 == armnn::TensorShape({1,2,3})));
155}
156
157struct SliceFixtureD213 : SliceFixture
158{
159 SliceFixtureD213() : SliceFixture("[ 3, 2, 3 ]",
160 "[ 2, 1, 3 ]",
161 "[ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]",
162 "[ 2, 0, 0, 0, 1, 0, 0, 0, 3, 0, 0, 0 ]") {}
163};
164
165BOOST_FIXTURE_TEST_CASE(SliceD213, SliceFixtureD213)
166{
167 RunTest<3, armnn::DataType::Float32>(
168 0,
169 {{"inputTensor", { 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6 }}},
170 {{"outputTensor", { 3, 3, 3, 5, 5, 5 }}});
171
172 BOOST_TEST((m_Parser->GetNetworkOutputBindingInfo(0, "outputTensor").second.GetShape()
173 == armnn::TensorShape({2,1,3})));
174}
175
Sadik Armagand109a4d2020-07-28 10:42:13 +0100176struct DynamicSliceFixtureD213 : SliceFixture
177{
178 DynamicSliceFixtureD213() : SliceFixture("[ 3, 2, 3 ]",
179 "[ ]",
180 "[ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]",
181 "[ 2, 0, 0, 0, 1, 0, 0, 0, 3, 0, 0, 0 ]") {}
182};
183
184BOOST_FIXTURE_TEST_CASE(DynamicSliceD213, DynamicSliceFixtureD213)
185{
186 RunTest<3, armnn::DataType::Float32, armnn::DataType::Float32>(
187 0,
188 {{"inputTensor", { 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6 }}},
189 {{"outputTensor", { 3, 3, 3, 5, 5, 5 }}},
190 true);
191}
192
josh minorba424d22019-11-13 10:55:17 -0600193BOOST_AUTO_TEST_SUITE_END()