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