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