blob: c32343f08eaf1edd47004ae6440ad45dc1eb9c7a [file] [log] [blame]
Ferran Balaguer0dcffec2019-06-18 16:25:06 +01001//
2// Copyright © 2017 Arm Ltd. All rights reserved.
3// SPDX-License-Identifier: MIT
4//
5
6#include <boost/test/unit_test.hpp>
7#include "ParserFlatbuffersSerializeFixture.hpp"
Finn Williams85d36712021-01-26 22:30:06 +00008#include <armnnDeserializer/IDeserializer.hpp>
Ferran Balaguer0dcffec2019-06-18 16:25:06 +01009
10#include <string>
Ferran Balaguer0dcffec2019-06-18 16:25:06 +010011
12BOOST_AUTO_TEST_SUITE(Deserializer)
13
14struct L2NormalizationFixture : public ParserFlatbuffersSerializeFixture
15{
16 explicit L2NormalizationFixture(const std::string &inputShape,
17 const std::string &outputShape,
18 const std::string &dataType,
19 const std::string &dataLayout,
20 const std::string epsilon)
21 {
22 m_JsonString = R"(
23 {
24 inputIds: [0],
25 outputIds: [2],
26 layers: [
27 {
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: "L2NormalizationLayer",
55 layer : {
56 base: {
57 index:1,
58 layerName: "L2NormalizationLayer",
59 layerType: "L2Normalization",
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 dataLayout: ")" + dataLayout + R"(",
74 eps: )" + epsilon + R"(
75 },
76 },
77 },
78 {
79 layer_type: "OutputLayer",
80 layer: {
81 base:{
82 layerBindingId: 0,
83 base: {
84 index: 2,
85 layerName: "OutputLayer",
86 layerType: "Output",
87 inputSlots: [{
88 index: 0,
89 connection: {sourceLayerIndex:1, outputSlotIndex:0 },
90 }],
91 outputSlots: [ {
92 index: 0,
93 tensorInfo: {
94 dimensions: )" + outputShape + R"(,
95 dataType: ")" + dataType + R"("
96 },
97 }],
98 }
99 }},
100 }]
101 }
102)";
103 Setup();
104 }
105};
106
107struct L2NormFixture : L2NormalizationFixture
108{
109 // Using a non standard epsilon value of 1e-8
110 L2NormFixture():L2NormalizationFixture("[ 1, 3, 1, 1 ]",
111 "[ 1, 3, 1, 1 ]",
112 "Float32",
113 "NCHW",
114 "0.00000001"){}
115};
116
117BOOST_FIXTURE_TEST_CASE(L2NormalizationFloat32, L2NormFixture)
118{
119 // 1 / sqrt(1^2 + 2^2 + 3^2)
120 const float approxInvL2Norm = 0.267261f;
121
122 RunTest<4, armnn::DataType::Float32>(0,
123 {{"InputLayer", { 1.0f, 2.0f, 3.0f }}},
124 {{"OutputLayer",{ 1.0f * approxInvL2Norm,
125 2.0f * approxInvL2Norm,
126 3.0f * approxInvL2Norm }}});
127}
128
129BOOST_FIXTURE_TEST_CASE(L2NormalizationEpsilonLimitFloat32, L2NormFixture)
130{
131 // 1 / sqrt(1e-8)
132 const float approxInvL2Norm = 10000;
133
134 RunTest<4, armnn::DataType::Float32>(0,
135 {{"InputLayer", { 0.00000001f, 0.00000002f, 0.00000003f }}},
136 {{"OutputLayer",{ 0.00000001f * approxInvL2Norm,
137 0.00000002f * approxInvL2Norm,
138 0.00000003f * approxInvL2Norm }}});
139}
140
141BOOST_AUTO_TEST_SUITE_END()