ArmNN
 21.02
DeserializeActivation.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>
9 
10 #include <string>
11 
12 BOOST_AUTO_TEST_SUITE(DeserializeParser)
13 
14 struct ActivationFixture : public ParserFlatbuffersSerializeFixture
15 {
16  explicit ActivationFixture(const std::string& inputShape,
17  const std::string& outputShape,
18  const std::string& dataType,
19  const std::string& activationType="Sigmoid",
20  const std::string& a = "0.0",
21  const std::string& b = "0.0")
22  {
23  m_JsonString = R"(
24  {
25  inputIds: [0],
26  outputIds: [2],
27  layers: [{
28  layer_type: "InputLayer",
29  layer: {
30  base: {
31  layerBindingId: 0,
32  base: {
33  index: 0,
34  layerName: "InputLayer",
35  layerType: "Input",
36  inputSlots: [{
37  index: 0,
38  connection: {sourceLayerIndex:0, outputSlotIndex:0 },
39  }],
40  outputSlots: [{
41  index: 0,
42  tensorInfo: {
43  dimensions: )" + inputShape + R"(,
44  dataType: )" + dataType + R"(
45  },
46  }],
47  },
48  }
49  },
50  },
51  {
52  layer_type: "ActivationLayer",
53  layer : {
54  base: {
55  index:1,
56  layerName: "ActivationLayer",
57  layerType: "Activation",
58  inputSlots: [{
59  index: 0,
60  connection: {sourceLayerIndex:0, outputSlotIndex:0 },
61  }],
62  outputSlots: [{
63  index: 0,
64  tensorInfo: {
65  dimensions: )" + outputShape + R"(,
66  dataType: )" + dataType + R"(
67  },
68  }],
69  },
70  descriptor: {
71  a: )" + a + R"(,
72  b: )" + b + R"(,
73  activationFunction: )" + activationType + R"(
74  },
75  },
76  },
77  {
78  layer_type: "OutputLayer",
79  layer: {
80  base:{
81  layerBindingId: 2,
82  base: {
83  index: 2,
84  layerName: "OutputLayer",
85  layerType: "Output",
86  inputSlots: [{
87  index: 0,
88  connection: {sourceLayerIndex:1, outputSlotIndex:0 },
89  }],
90  outputSlots: [{
91  index: 0,
92  tensorInfo: {
93  dimensions: )" + outputShape + R"(,
94  dataType: )" + dataType + R"(
95  },
96  }],
97  }
98  }
99  },
100  }]
101  }
102  )";
103  Setup();
104  }
105 };
106 
107 struct SimpleActivationFixture : ActivationFixture
108 {
109  SimpleActivationFixture() : ActivationFixture("[1, 2, 2, 1]",
110  "[1, 2, 2, 1]",
111  "QuantisedAsymm8",
112  "ReLu") {}
113 };
114 
115 struct SimpleActivationFixture2 : ActivationFixture
116 {
117  SimpleActivationFixture2() : ActivationFixture("[1, 2, 2, 1]",
118  "[1, 2, 2, 1]",
119  "Float32",
120  "ReLu") {}
121 };
122 
123 struct SimpleActivationFixture3 : ActivationFixture
124 {
125  SimpleActivationFixture3() : ActivationFixture("[1, 2, 2, 1]",
126  "[1, 2, 2, 1]",
127  "QuantisedAsymm8",
128  "BoundedReLu",
129  "5.0",
130  "0.0") {}
131 };
132 
133 struct SimpleActivationFixture4 : ActivationFixture
134 {
135  SimpleActivationFixture4() : ActivationFixture("[1, 2, 2, 1]",
136  "[1, 2, 2, 1]",
137  "Float32",
138  "BoundedReLu",
139  "5.0",
140  "0.0") {}
141 };
142 
143 
144 BOOST_FIXTURE_TEST_CASE(ActivationReluQuantisedAsymm8, SimpleActivationFixture)
145 {
146  RunTest<4, armnn::DataType::QAsymmU8>(
147  0,
148  {{"InputLayer", {10, 0, 2, 0}}},
149  {{"OutputLayer", {10, 0, 2, 0}}});
150 }
151 
152 BOOST_FIXTURE_TEST_CASE(ActivationReluFloat32, SimpleActivationFixture2)
153 {
154  RunTest<4, armnn::DataType::Float32>(
155  0,
156  {{"InputLayer", {111, -85, 226, 3}}},
157  {{"OutputLayer", {111, 0, 226, 3}}});
158 }
159 
160 
161 BOOST_FIXTURE_TEST_CASE(ActivationBoundedReluQuantisedAsymm8, SimpleActivationFixture3)
162 {
163  RunTest<4, armnn::DataType::QAsymmU8>(
164  0,
165  {{"InputLayer", {10, 0, 2, 0}}},
166  {{"OutputLayer", {5, 0, 2, 0}}});
167 }
168 
169 BOOST_FIXTURE_TEST_CASE(ActivationBoundedReluFloat32, SimpleActivationFixture4)
170 {
171  RunTest<4, armnn::DataType::Float32>(
172  0,
173  {{"InputLayer", {111, -85, 226, 3}}},
174  {{"OutputLayer", {5, 0, 5, 3}}});
175 }
176 
BOOST_AUTO_TEST_SUITE(TensorflowLiteParser)
BOOST_FIXTURE_TEST_CASE(ActivationReluQuantisedAsymm8, SimpleActivationFixture)
BOOST_AUTO_TEST_SUITE_END()