blob: 9c85a4a5c59c34d988419e35c9923630d039458d [file] [log] [blame]
Bruno Goncalvesbaded142019-02-08 19:02:48 -02001//
Finn Williamsb49ed182021-06-29 15:50:08 +01002// Copyright © 2017 Arm Ltd and Contributors. All rights reserved.
Bruno Goncalvesbaded142019-02-08 19:02:48 -02003// SPDX-License-Identifier: MIT
4//
5
Bruno Goncalvesbaded142019-02-08 19:02:48 -02006#include "ParserFlatbuffersFixture.hpp"
Bruno Goncalvesbaded142019-02-08 19:02:48 -02007
Bruno Goncalvesbaded142019-02-08 19:02:48 -02008
Sadik Armagan1625efc2021-06-10 18:24:34 +01009TEST_SUITE("TensorflowLiteParser_SpaceToBatchND")
10{
Bruno Goncalvesbaded142019-02-08 19:02:48 -020011struct SpaceToBatchNDFixture : public ParserFlatbuffersFixture
12{
13 explicit SpaceToBatchNDFixture(const std::string & inputShape,
14 const std::string & outputShape,
15 const std::string & blockShapeData,
16 const std::string & padListData)
17 {
18 m_JsonString = R"(
19 {
20 "version": 3,
21 "operator_codes": [ { "builtin_code": "SPACE_TO_BATCH_ND" } ],
22 "subgraphs": [ {
23 "tensors": [
24 {
25 "shape": )" + inputShape + R"(,
26 "type": "FLOAT32",
27 "buffer": 0,
28 "name": "inputTensor",
29 "quantization": {
30 "min": [ 0.0 ],
31 "max": [ 255.0 ],
32 "scale": [ 1.0 ],
33 "zero_point": [ 0 ],
34 }
35 },
36 {
37 "shape": )" + outputShape + R"(,
38 "type": "FLOAT32",
39 "buffer": 1,
40 "name": "outputTensor",
41 "quantization": {
42 "min": [ 0.0 ],
43 "max": [ 255.0 ],
44 "scale": [ 1.0 ],
45 "zero_point": [ 0 ],
46 }
47 },
48 {
49 "shape": [ 2 ],
50 "type": "INT32",
51 "buffer": 2,
52 "name": "blockShapeTensor",
53 "quantization": {
54 "min": [ 0.0 ],
55 "max": [ 255.0 ],
56 "scale": [ 1.0 ],
57 "zero_point": [ 0 ],
58 }
59 },
60 {
61 "shape": [ 2, 2 ],
62 "type": "INT32",
63 "buffer": 3,
64 "name": "padListTensor",
65 "quantization": {
66 "min": [ 0.0 ],
67 "max": [ 255.0 ],
68 "scale": [ 1.0 ],
69 "zero_point": [ 0 ],
70 }
71 }
72 ],
73 "inputs": [ 0 ],
74 "outputs": [ 1 ],
75 "operators": [
76 {
77 "opcode_index": 0,
78 "inputs": [ 0, 2, 3 ],
79 "outputs": [ 1 ],
80 "custom_options_format": "FLEXBUFFERS"
81 }
82 ],
83 } ],
84 "buffers" : [
85 { },
86 { },
87 { "data": )" + blockShapeData + R"(, },
88 { "data": )" + padListData + R"(, },
89 ]
90 }
91 )";
92 Setup();
93 }
94};
95
96struct SpaceToBatchNDFixtureSimpleTest : public SpaceToBatchNDFixture
97{
98 SpaceToBatchNDFixtureSimpleTest() : SpaceToBatchNDFixture("[ 1, 4, 4, 1 ]",
99 "[ 4, 2, 2, 1 ]",
100 "[ 2,0,0,0, 2,0,0,0 ]",
101 "[ 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0 ]") {}
102};
103
Sadik Armagan1625efc2021-06-10 18:24:34 +0100104TEST_CASE_FIXTURE(SpaceToBatchNDFixtureSimpleTest, "SpaceToBatchNdSimpleTest")
Bruno Goncalvesbaded142019-02-08 19:02:48 -0200105{
106 RunTest<4, armnn::DataType::Float32>
107 (0,
108 {{ "inputTensor", { 1.0f, 2.0f, 3.0f, 4.0f,
109 5.0f, 6.0f, 7.0f, 8.0f,
110 9.0f, 10.0f, 11.0f, 12.0f,
111 13.0f, 14.0f, 15.0f, 16.0f }}},
112 {{ "outputTensor", { 1.0f, 3.0f, 9.0f, 11.0f,
113 2.0f, 4.0f, 10.0f, 12.0f,
114 5.0f, 7.0f, 13.0f, 15.0f,
115 6.0f, 8.0f, 14.0f, 16.0f }}});
116}
117
118
119struct SpaceToBatchNDFixtureMultipleInputBatchesTest : public SpaceToBatchNDFixture
120{
121 SpaceToBatchNDFixtureMultipleInputBatchesTest() : SpaceToBatchNDFixture("[ 2, 2, 4, 1 ]",
122 "[ 8, 1, 2, 1 ]",
123 "[ 2,0,0,0, 2,0,0,0 ]",
124 "[ 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0 ]") {}
125};
126
Sadik Armagan1625efc2021-06-10 18:24:34 +0100127TEST_CASE_FIXTURE(SpaceToBatchNDFixtureMultipleInputBatchesTest, "SpaceToBatchNdMultipleInputBatchesTest")
Bruno Goncalvesbaded142019-02-08 19:02:48 -0200128{
129 RunTest<4, armnn::DataType::Float32>
130 (0,
131 {{ "inputTensor", { 1.0f, 2.0f, 3.0f, 4.0f,
132 5.0f, 6.0f, 7.0f, 8.0f,
133 9.0f, 10.0f, 11.0f, 12.0f,
134 13.0f, 14.0f, 15.0f, 16.0f }}},
135 {{ "outputTensor", { 1.0f, 3.0f, 9.0f, 11.0f,
136 2.0f, 4.0f, 10.0f, 12.0f,
137 5.0f, 7.0f, 13.0f, 15.0f,
138 6.0f, 8.0f, 14.0f, 16.0f }}});
139}
140
141struct SpaceToBatchNDFixturePaddingTest : public SpaceToBatchNDFixture
142{
143 SpaceToBatchNDFixturePaddingTest() : SpaceToBatchNDFixture("[ 1, 5, 2, 1 ]",
144 "[ 6, 2, 2, 1 ]",
145 "[ 3,0,0,0, 2,0,0,0 ]",
146 "[ 1,0,0,0, 0,0,0,0, 2,0,0,0, 0,0,0,0 ]") {}
147};
148
Sadik Armagan1625efc2021-06-10 18:24:34 +0100149TEST_CASE_FIXTURE(SpaceToBatchNDFixturePaddingTest, "SpaceToBatchNdPaddingTest")
Bruno Goncalvesbaded142019-02-08 19:02:48 -0200150{
151 RunTest<4, armnn::DataType::Float32>
152 (0,
153 {{ "inputTensor", { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f,
154 6.0f, 7.0f, 8.0f, 9.0f, 10.0f }}},
155 {{ "outputTensor", { 0.0f, 0.0f,
156 0.0f, 5.0f,
157
158 0.0f, 0.0f,
159 0.0f, 6.0f,
160
161 0.0f, 1.0f,
162 0.0f, 7.0f,
163
164 0.0f, 2.0f,
165 0.0f, 8.0f,
166
167 0.0f, 3.0f,
168 0.0f, 9.0f,
169
170 0.0f, 4.0f,
171 0.0f, 10.0f, }}});
172}
173
Sadik Armagan1625efc2021-06-10 18:24:34 +0100174}