ArmNN
 21.05
DeserializeBatchNormalization.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(Deserializer)
13 
14 struct BatchNormalizationFixture : public ParserFlatbuffersSerializeFixture
15 {
16  explicit BatchNormalizationFixture(const std::string &inputShape,
17  const std::string &outputShape,
18  const std::string &meanShape,
19  const std::string &varianceShape,
20  const std::string &offsetShape,
21  const std::string &scaleShape,
22  const std::string &dataType,
23  const std::string &dataLayout)
24  {
25  m_JsonString = R"(
26  {
27  inputIds: [0],
28  outputIds: [2],
29  layers: [
30  {
31  layer_type: "InputLayer",
32  layer: {
33  base: {
34  layerBindingId: 0,
35  base: {
36  index: 0,
37  layerName: "InputLayer",
38  layerType: "Input",
39  inputSlots: [{
40  index: 0,
41  connection: {sourceLayerIndex:0, outputSlotIndex:0 },
42  }],
43  outputSlots: [{
44  index: 0,
45  tensorInfo: {
46  dimensions: )" + inputShape + R"(,
47  dataType: ")" + dataType + R"(",
48  quantizationScale: 0.5,
49  quantizationOffset: 0
50  },
51  }]
52  },
53  }
54  },
55  },
56  {
57  layer_type: "BatchNormalizationLayer",
58  layer : {
59  base: {
60  index:1,
61  layerName: "BatchNormalizationLayer",
62  layerType: "BatchNormalization",
63  inputSlots: [{
64  index: 0,
65  connection: {sourceLayerIndex:0, outputSlotIndex:0 },
66  }],
67  outputSlots: [{
68  index: 0,
69  tensorInfo: {
70  dimensions: )" + outputShape + R"(,
71  dataType: ")" + dataType + R"("
72  },
73  }],
74  },
75  descriptor: {
76  eps: 0.0010000000475,
77  dataLayout: ")" + dataLayout + R"("
78  },
79  mean: {
80  info: {
81  dimensions: )" + meanShape + R"(,
82  dataType: ")" + dataType + R"("
83  },
84  data_type: IntData,
85  data: {
86  data: [1084227584],
87  }
88  },
89  variance: {
90  info: {
91  dimensions: )" + varianceShape + R"(,
92  dataType: ")" + dataType + R"("
93  },
94  data_type: IntData,
95  data: {
96  data: [1073741824],
97  }
98  },
99  beta: {
100  info: {
101  dimensions: )" + offsetShape + R"(,
102  dataType: ")" + dataType + R"("
103  },
104  data_type: IntData,
105  data: {
106  data: [0],
107  }
108  },
109  gamma: {
110  info: {
111  dimensions: )" + scaleShape + R"(,
112  dataType: ")" + dataType + R"("
113  },
114  data_type: IntData,
115  data: {
116  data: [1065353216],
117  }
118  },
119  },
120  },
121  {
122  layer_type: "OutputLayer",
123  layer: {
124  base:{
125  layerBindingId: 0,
126  base: {
127  index: 2,
128  layerName: "OutputLayer",
129  layerType: "Output",
130  inputSlots: [{
131  index: 0,
132  connection: {sourceLayerIndex:1, outputSlotIndex:0 },
133  }],
134  outputSlots: [ {
135  index: 0,
136  tensorInfo: {
137  dimensions: )" + outputShape + R"(,
138  dataType: ")" + dataType + R"("
139  },
140  }],
141  }
142  }},
143  }]
144  }
145 )";
146  Setup();
147  }
148 };
149 
150 struct BatchNormFixture : BatchNormalizationFixture
151 {
152  BatchNormFixture():BatchNormalizationFixture("[ 1, 3, 3, 1 ]",
153  "[ 1, 3, 3, 1 ]",
154  "[ 1 ]",
155  "[ 1 ]",
156  "[ 1 ]",
157  "[ 1 ]",
158  "Float32",
159  "NHWC"){}
160 };
161 
162 BOOST_FIXTURE_TEST_CASE(BatchNormalizationFloat32, BatchNormFixture)
163 {
164  RunTest<4, armnn::DataType::Float32>(0,
165  {{"InputLayer", { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f }}},
166  {{"OutputLayer",{ -2.8277204f, -2.12079024f, -1.4138602f,
167  -0.7069301f, 0.0f, 0.7069301f,
168  1.4138602f, 2.12079024f, 2.8277204f }}});
169 }
170 
BOOST_AUTO_TEST_SUITE(TensorflowLiteParser)
BOOST_AUTO_TEST_SUITE_END()
BOOST_FIXTURE_TEST_CASE(BatchNormalizationFloat32, BatchNormFixture)