ArmNN
 21.02
Pad.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 PadFixture : public ParserFlatbuffersFixture
16 {
17  explicit PadFixture(const std::string& inputShape,
18  const std::string& outputShape,
19  const std::string& padListShape,
20  const std::string& padListData,
21  const std::string& dataType = "FLOAT32",
22  const std::string& scale = "1.0",
23  const std::string& offset = "0")
24  {
25  m_JsonString = R"(
26  {
27  "version": 3,
28  "operator_codes": [ { "builtin_code": "PAD" } ],
29  "subgraphs": [ {
30  "tensors": [
31  {
32  "shape": )" + inputShape + R"(,
33  "type": )" + dataType + R"(,
34  "buffer": 0,
35  "name": "inputTensor",
36  "quantization": {
37  "min": [ 0.0 ],
38  "max": [ 255.0 ],
39  "scale": [ )" + scale + R"( ],
40  "zero_point": [ )" + offset + R"( ],
41  }
42  },
43  {
44  "shape": )" + outputShape + R"(,
45  "type": )" + dataType + R"(,
46  "buffer": 1,
47  "name": "outputTensor",
48  "quantization": {
49  "min": [ 0.0 ],
50  "max": [ 255.0 ],
51  "scale": [ )" + scale + R"( ],
52  "zero_point": [ )" + offset + R"( ],
53  }
54  },
55  {
56  "shape": )" + padListShape + R"( ,
57  "type": "INT32",
58  "buffer": 2,
59  "name": "padList",
60  "quantization": {
61  "min": [ 0.0 ],
62  "max": [ 255.0 ],
63  "scale": [ 1.0 ],
64  "zero_point": [ 0 ],
65  }
66  }
67  ],
68  "inputs": [ 0 ],
69  "outputs": [ 1 ],
70  "operators": [
71  {
72  "opcode_index": 0,
73  "inputs": [ 0, 2 ],
74  "outputs": [ 1 ],
75  "custom_options_format": "FLEXBUFFERS"
76  }
77  ],
78  } ],
79  "buffers" : [
80  { },
81  { },
82  { "data": )" + padListData + R"(, },
83  ]
84  }
85  )";
86  SetupSingleInputSingleOutput("inputTensor", "outputTensor");
87  }
88 };
89 
90 struct SimplePadFixture : public PadFixture
91 {
92  SimplePadFixture() : PadFixture("[ 2, 3 ]", "[ 4, 7 ]", "[ 2, 2 ]",
93  "[ 1,0,0,0, 1,0,0,0, 2,0,0,0, 2,0,0,0 ]") {}
94 };
95 
96 BOOST_FIXTURE_TEST_CASE(ParsePad, SimplePadFixture)
97 {
98  RunTest<2, armnn::DataType::Float32>
99  (0,
100  {{ "inputTensor", { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f }}},
101  {{ "outputTensor", { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f,
102  0.0f, 0.0f, 1.0f, 2.0f, 3.0f, 0.0f, 0.0f,
103  0.0f, 0.0f, 4.0f, 5.0f, 6.0f, 0.0f, 0.0f,
104  0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f }}});
105 }
106 
107 struct Uint8PadFixture : public PadFixture
108 {
109  Uint8PadFixture() : PadFixture("[ 2, 3 ]", "[ 4, 7 ]", "[ 2, 2 ]",
110  "[ 1,0,0,0, 1,0,0,0, 2,0,0,0, 2,0,0,0 ]",
111  "UINT8", "-2.0", "3") {}
112 };
113 
114 BOOST_FIXTURE_TEST_CASE(ParsePadUint8, Uint8PadFixture)
115 {
116  RunTest<2, armnn::DataType::QAsymmU8>
117  (0,
118  {{ "inputTensor", { 1, 2, 3, 4, 5, 6 }}},
119  {{ "outputTensor", { 3, 3, 3, 3, 3, 3, 3,
120  3, 3, 1, 2, 3, 3, 3,
121  3, 3, 4, 5, 6, 3, 3,
122  3, 3, 3, 3, 3, 3, 3 }}});
123 }
124 
125 struct Int8PadFixture : public PadFixture
126 {
127  Int8PadFixture() : PadFixture("[ 2, 3 ]", "[ 4, 7 ]", "[ 2, 2 ]",
128  "[ 1,0,0,0, 1,0,0,0, 2,0,0,0, 2,0,0,0 ]",
129  "INT8", "-2.0", "3") {}
130 };
131 
132 BOOST_FIXTURE_TEST_CASE(ParsePadInt8, Int8PadFixture)
133 {
134  RunTest<2, armnn::DataType::QAsymmS8>
135  (0,
136  {{ "inputTensor", { 1, -2, 3, 4, 5, -6 }}},
137  {{ "outputTensor", { 3, 3, 3, 3, 3, 3, 3,
138  3, 3, 1, -2, 3, 3, 3,
139  3, 3, 4, 5, -6, 3, 3,
140  3, 3, 3, 3, 3, 3, 3 }}});
141 }
142 
BOOST_AUTO_TEST_SUITE(TensorflowLiteParser)
BOOST_AUTO_TEST_SUITE_END()
void SetupSingleInputSingleOutput(const std::string &inputName, const std::string &outputName)
BOOST_FIXTURE_TEST_CASE(ParsePad, SimplePadFixture)
Definition: Pad.cpp:96