2 // Copyright © 2017 Arm Ltd. All rights reserved.
3 // SPDX-License-Identifier: MIT
6 #include <boost/test/unit_test.hpp>
7 #include "ParserFlatbuffersSerializeFixture.hpp"
8 #include <armnnDeserializer/IDeserializer.hpp>
12 BOOST_AUTO_TEST_SUITE(Deserializer)
14 struct L2NormalizationFixture : public ParserFlatbuffersSerializeFixture
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)
28 layer_type: "InputLayer",
34 layerName: "InputLayer",
38 connection: {sourceLayerIndex:0, outputSlotIndex:0 },
43 dimensions: )" + inputShape + R"(,
44 dataType: ")" + dataType + R"(",
45 quantizationScale: 0.5,
54 layer_type: "L2NormalizationLayer",
58 layerName: "L2NormalizationLayer",
59 layerType: "L2Normalization",
62 connection: {sourceLayerIndex:0, outputSlotIndex:0 },
67 dimensions: )" + outputShape + R"(,
68 dataType: ")" + dataType + R"("
73 dataLayout: ")" + dataLayout + R"(",
74 eps: )" + epsilon + R"(
79 layer_type: "OutputLayer",
85 layerName: "OutputLayer",
89 connection: {sourceLayerIndex:1, outputSlotIndex:0 },
94 dimensions: )" + outputShape + R"(,
95 dataType: ")" + dataType + R"("
107 struct L2NormFixture : L2NormalizationFixture
109 // Using a non standard epsilon value of 1e-8
110 L2NormFixture():L2NormalizationFixture("[ 1, 3, 1, 1 ]",
117 BOOST_FIXTURE_TEST_CASE(L2NormalizationFloat32, L2NormFixture)
119 // 1 / sqrt(1^2 + 2^2 + 3^2)
120 const float approxInvL2Norm = 0.267261f;
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 }}});
129 BOOST_FIXTURE_TEST_CASE(L2NormalizationEpsilonLimitFloat32, L2NormFixture)
132 const float approxInvL2Norm = 10000;
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 }}});
141 BOOST_AUTO_TEST_SUITE_END()