ArmNN
 21.02
DeserializeNormalization.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 NormalizationFixture : public ParserFlatbuffersSerializeFixture
15 {
16  explicit NormalizationFixture(const std::string &inputShape,
17  const std::string & outputShape,
18  const std::string &dataType,
19  const std::string &normAlgorithmChannel,
20  const std::string &normAlgorithmMethod,
21  const std::string &dataLayout)
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  quantizationScale: 0.5,
46  quantizationOffset: 0
47  },
48  }]
49  },
50  }
51  },
52  },
53  {
54  layer_type: "NormalizationLayer",
55  layer : {
56  base: {
57  index:1,
58  layerName: "NormalizationLayer",
59  layerType: "Normalization",
60  inputSlots: [{
61  index: 0,
62  connection: {sourceLayerIndex:0, outputSlotIndex:0 },
63  }],
64  outputSlots: [{
65  index: 0,
66  tensorInfo: {
67  dimensions: )" + outputShape + R"(,
68  dataType: )" + dataType + R"(
69  },
70  }],
71  },
72  descriptor: {
73  normChannelType: )" + normAlgorithmChannel + R"(,
74  normMethodType: )" + normAlgorithmMethod + R"(,
75  normSize: 3,
76  alpha: 1,
77  beta: 1,
78  k: 1,
79  dataLayout: )" + dataLayout + R"(
80  }
81  },
82  },
83  {
84  layer_type: "OutputLayer",
85  layer: {
86  base:{
87  layerBindingId: 0,
88  base: {
89  index: 2,
90  layerName: "OutputLayer",
91  layerType: "Output",
92  inputSlots: [{
93  index: 0,
94  connection: {sourceLayerIndex:1, outputSlotIndex:0 },
95  }],
96  outputSlots: [ {
97  index: 0,
98  tensorInfo: {
99  dimensions: )" + outputShape + R"(,
100  dataType: )" + dataType + R"(
101  },
102  }],
103  }
104  }},
105  }]
106  }
107  )";
108  SetupSingleInputSingleOutput("InputLayer", "OutputLayer");
109  }
110 };
111 
112 struct FloatNhwcLocalBrightnessAcrossNormalizationFixture : NormalizationFixture
113 {
114  FloatNhwcLocalBrightnessAcrossNormalizationFixture() : NormalizationFixture("[ 2, 2, 2, 1 ]", "[ 2, 2, 2, 1 ]",
115  "Float32", "0", "0", "NHWC") {}
116 };
117 
118 
119 BOOST_FIXTURE_TEST_CASE(Float32NormalizationNhwcDataLayout, FloatNhwcLocalBrightnessAcrossNormalizationFixture)
120 {
121  RunTest<4, armnn::DataType::Float32>(0, { 1.0f, 2.0f, 3.0f, 4.0f,
122  5.0f, 6.0f, 7.0f, 8.0f },
123  { 0.5f, 0.400000006f, 0.300000012f, 0.235294119f,
124  0.192307696f, 0.16216217f, 0.140000001f, 0.123076923f });
125 }
126 
127 struct FloatNchwLocalBrightnessWithinNormalizationFixture : NormalizationFixture
128 {
129  FloatNchwLocalBrightnessWithinNormalizationFixture() : NormalizationFixture("[ 2, 1, 2, 2 ]", "[ 2, 1, 2, 2 ]",
130  "Float32", "1", "0", "NCHW") {}
131 };
132 
133 BOOST_FIXTURE_TEST_CASE(Float32NormalizationNchwDataLayout, FloatNchwLocalBrightnessWithinNormalizationFixture)
134 {
135  RunTest<4, armnn::DataType::Float32>(0, { 1.0f, 2.0f, 3.0f, 4.0f,
136  5.0f, 6.0f, 7.0f, 8.0f },
137  { 0.0322581f, 0.0645161f, 0.0967742f, 0.1290323f,
138  0.0285714f, 0.0342857f, 0.04f, 0.0457143f });
139 }
140 
141 
BOOST_AUTO_TEST_SUITE(TensorflowLiteParser)
void SetupSingleInputSingleOutput(const std::string &inputName, const std::string &outputName)
BOOST_FIXTURE_TEST_CASE(Float32NormalizationNhwcDataLayout, FloatNhwcLocalBrightnessAcrossNormalizationFixture)
BOOST_AUTO_TEST_SUITE_END()