ArmNN
 21.02
DepthToSpace.cpp
Go to the documentation of this file.
1 //
2 // Copyright © 2021 Arm Ltd and Contributors. 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 DepthToSpaceFixture : public ParserFlatbuffersFixture
16 {
17  explicit DepthToSpaceFixture(const std::string& inputShape,
18  const std::string& outputShape,
19  const std::string& dataType = "FLOAT32",
20  const std::string& scale = "1.0",
21  const std::string& offset = "0")
22  {
23  m_JsonString = R"(
24  {
25  "version": 3,
26  "operator_codes": [ { "builtin_code": "DEPTH_TO_SPACE" } ],
27  "subgraphs": [ {
28  "tensors": [
29  {
30  "shape": )" + inputShape + R"(,
31  "type": )" + dataType + R"(,
32  "buffer": 0,
33  "name": "inputTensor",
34  "quantization": {
35  "min": [ 0.0 ],
36  "max": [ 255.0 ],
37  "scale": [ )" + scale + R"( ],
38  "zero_point": [ )" + offset + R"( ],
39  }
40  },
41  {
42  "shape": )" + outputShape + R"(,
43  "type": )" + dataType + R"(,
44  "buffer": 1,
45  "name": "outputTensor",
46  "quantization": {
47  "min": [ 0.0 ],
48  "max": [ 255.0 ],
49  "scale": [ )" + scale + R"( ],
50  "zero_point": [ )" + offset + R"( ],
51  }
52  }
53  ],
54  "inputs": [ 0 ],
55  "outputs": [ 1 ],
56  "operators": [
57  {
58  "opcode_index": 0,
59  "inputs": [ 0 ],
60  "outputs": [ 1 ],
61  "builtin_options_type": "DepthToSpaceOptions",
62  "builtin_options": {
63  "block_size": 2
64  },
65  "custom_options_format": "FLEXBUFFERS"
66  }
67  ],
68  } ],
69  "buffers" : [
70  { },
71  { },
72  ]
73  }
74  )";
75  SetupSingleInputSingleOutput("inputTensor", "outputTensor");
76  }
77 };
78 
79 struct SimpleDepthToSpaceFixture : public DepthToSpaceFixture
80 {
81  SimpleDepthToSpaceFixture() : DepthToSpaceFixture("[ 1, 2, 2, 4 ]", "[ 1, 4, 4, 1 ]") {}
82 };
83 
84 BOOST_FIXTURE_TEST_CASE(ParseDepthToSpace, SimpleDepthToSpaceFixture)
85 {
86  RunTest<4, armnn::DataType::Float32>
87  (0,
88  {{ "inputTensor", { 1.f, 2.f, 3.f, 4.f,
89  5.f, 6.f, 7.f, 8.f,
90  9.f, 10.f, 11.f, 12.f,
91  13.f, 14.f, 15.f, 16.f }}},
92  {{ "outputTensor", { 1.f, 2.f, 5.f, 6.f,
93  3.f, 4.f, 7.f, 8.f,
94  9.f, 10.f, 13.f, 14.f,
95  11.f, 12.f, 15.f, 16.f }}});
96 }
97 
BOOST_AUTO_TEST_SUITE(TensorflowLiteParser)
BOOST_AUTO_TEST_SUITE_END()
void SetupSingleInputSingleOutput(const std::string &inputName, const std::string &outputName)
BOOST_FIXTURE_TEST_CASE(ParseDepthToSpace, SimpleDepthToSpaceFixture)