ArmNN
 21.02
BatchToSpaceND.cpp
Go to the documentation of this file.
1 //
2 // Copyright © 2017 Arm Ltd. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 
6 #include <boost/test/unit_test.hpp>
8 #include "../TfLiteParser.hpp"
9 
10 #include <string>
11 #include <iostream>
12 
13 BOOST_AUTO_TEST_SUITE(TensorflowLiteParser)
14 
15 struct BatchToSpaceNDFixture : public ParserFlatbuffersFixture
16 {
17  explicit BatchToSpaceNDFixture(const std::string & inputShape,
18  const std::string & outputShape,
19  const std::string & blockShapeData,
20  const std::string & cropsData)
21  {
22  m_JsonString = R"(
23  {
24  "version": 3,
25  "operator_codes": [ { "builtin_code": "BATCH_TO_SPACE_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": "cropsTensor",
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": )" + cropsData + R"(, },
93  ]
94  }
95  )";
96  Setup();
97  }
98 };
99 
100 struct BatchToSpaceNDFixtureTest1 : public BatchToSpaceNDFixture
101 {
102  BatchToSpaceNDFixtureTest1() : BatchToSpaceNDFixture("[ 4, 2, 2, 1 ]",
103  "[ 1, 4, 4, 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 
108 BOOST_FIXTURE_TEST_CASE(BatchToSpaceNDTest1, BatchToSpaceNDFixtureTest1)
109 {
110  RunTest<4, armnn::DataType::Float32>
111  (0,
112  {{ "inputTensor", { // Batch 0, Height 0, Width (2) x Channel (1)
113  1.0f, 3.0f,
114  // Batch 0, Height 1, Width (2) x Channel (1)
115  9.0f, 11.0f,
116 
117  // Batch 1, Height 0, Width (2) x Channel (1)
118  2.0f, 4.0f,
119  // Batch 1, Height 1, Width (2) x Channel (1)
120  10.0f, 12.0f,
121 
122  // Batch 2, Height 0, Width (2) x Channel (1)
123  5.0f, 7.0f,
124  // Batch 2, Height 1, Width (2) x Channel (1)
125  13.0f, 15.0f,
126 
127  // Batch 3, Height 0, Width (2) x Channel (3)
128  6.0f, 8.0f,
129  // Batch 3, Height 1, Width (2) x Channel (1)
130  14.0f, 16.0f }}},
131  {{ "outputTensor", { 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 }
136 
137 struct BatchToSpaceNDFixtureTest2 : public BatchToSpaceNDFixture
138 {
139  BatchToSpaceNDFixtureTest2() : BatchToSpaceNDFixture("[ 4, 1, 1, 1 ]",
140  "[ 1, 2, 2, 1 ]",
141  "[ 2,0,0,0, 2,0,0,0 ]",
142  "[ 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0 ]") {}
143 };
144 
145 BOOST_FIXTURE_TEST_CASE(ParseBatchToSpaceNDTest2, BatchToSpaceNDFixtureTest2)
146 {
147  RunTest<4, armnn::DataType::Float32>
148  (0,
149  {{ "inputTensor", { 1.0f, 2.0f, 3.0f, 4.0f }}},
150  {{ "outputTensor", { // Batch 0, Height 0, Width (2) x Channel (1)
151  1.0f, 2.0f, 3.0f, 4.0f }}});
152 }
153 
154 struct BatchToSpaceNDFixtureTest3 : public BatchToSpaceNDFixture
155 {
156  BatchToSpaceNDFixtureTest3() : BatchToSpaceNDFixture("[ 4, 1, 1, 3 ]",
157  "[ 1, 2, 2, 3 ]",
158  "[ 2,0,0,0, 2,0,0,0 ]",
159  "[ 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0 ]") {}
160 };
161 
162 BOOST_FIXTURE_TEST_CASE(ParseBatchToSpaceNDTest3, BatchToSpaceNDFixtureTest3)
163 {
164  RunTest<4, armnn::DataType::Float32>
165  (0,
166  {{ "inputTensor", { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f, 12.0f }}},
167  {{ "outputTensor", { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f, 12.0f }}});
168 }
169 
BOOST_AUTO_TEST_SUITE(TensorflowLiteParser)
BOOST_FIXTURE_TEST_CASE(BatchToSpaceNDTest1, BatchToSpaceNDFixtureTest1)
BOOST_AUTO_TEST_SUITE_END()