blob: d9a512eafc250702d377eca84a453bc7b10a1ea9 [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
Ferran Balaguer0dcffec2019-06-18 16:25:06 +01006#include "ParserFlatbuffersSerializeFixture.hpp"
Finn Williams85d36712021-01-26 22:30:06 +00007#include <armnnDeserializer/IDeserializer.hpp>
Ferran Balaguer0dcffec2019-06-18 16:25:06 +01008
9#include <string>
Ferran Balaguer0dcffec2019-06-18 16:25:06 +010010
Sadik Armagan1625efc2021-06-10 18:24:34 +010011TEST_SUITE("Deserializer_L2Normalization")
12{
Ferran Balaguer0dcffec2019-06-18 16:25:06 +010013struct L2NormalizationFixture : public ParserFlatbuffersSerializeFixture
14{
15 explicit L2NormalizationFixture(const std::string &inputShape,
16 const std::string &outputShape,
17 const std::string &dataType,
18 const std::string &dataLayout,
19 const std::string epsilon)
20 {
21 m_JsonString = R"(
22 {
23 inputIds: [0],
24 outputIds: [2],
25 layers: [
26 {
27 layer_type: "InputLayer",
28 layer: {
29 base: {
30 layerBindingId: 0,
31 base: {
32 index: 0,
33 layerName: "InputLayer",
34 layerType: "Input",
35 inputSlots: [{
36 index: 0,
37 connection: {sourceLayerIndex:0, outputSlotIndex:0 },
38 }],
39 outputSlots: [{
40 index: 0,
41 tensorInfo: {
42 dimensions: )" + inputShape + R"(,
43 dataType: ")" + dataType + R"(",
44 quantizationScale: 0.5,
45 quantizationOffset: 0
46 },
47 }]
48 },
49 }
50 },
51 },
52 {
53 layer_type: "L2NormalizationLayer",
54 layer : {
55 base: {
56 index:1,
57 layerName: "L2NormalizationLayer",
58 layerType: "L2Normalization",
59 inputSlots: [{
60 index: 0,
61 connection: {sourceLayerIndex:0, outputSlotIndex:0 },
62 }],
63 outputSlots: [{
64 index: 0,
65 tensorInfo: {
66 dimensions: )" + outputShape + R"(,
67 dataType: ")" + dataType + R"("
68 },
69 }],
70 },
71 descriptor: {
72 dataLayout: ")" + dataLayout + R"(",
73 eps: )" + epsilon + R"(
74 },
75 },
76 },
77 {
78 layer_type: "OutputLayer",
79 layer: {
80 base:{
81 layerBindingId: 0,
82 base: {
83 index: 2,
84 layerName: "OutputLayer",
85 layerType: "Output",
86 inputSlots: [{
87 index: 0,
88 connection: {sourceLayerIndex:1, outputSlotIndex:0 },
89 }],
90 outputSlots: [ {
91 index: 0,
92 tensorInfo: {
93 dimensions: )" + outputShape + R"(,
94 dataType: ")" + dataType + R"("
95 },
96 }],
97 }
98 }},
99 }]
100 }
101)";
102 Setup();
103 }
104};
105
106struct L2NormFixture : L2NormalizationFixture
107{
108 // Using a non standard epsilon value of 1e-8
109 L2NormFixture():L2NormalizationFixture("[ 1, 3, 1, 1 ]",
110 "[ 1, 3, 1, 1 ]",
111 "Float32",
112 "NCHW",
113 "0.00000001"){}
114};
115
Sadik Armagan1625efc2021-06-10 18:24:34 +0100116TEST_CASE_FIXTURE(L2NormFixture, "L2NormalizationFloat32")
Ferran Balaguer0dcffec2019-06-18 16:25:06 +0100117{
118 // 1 / sqrt(1^2 + 2^2 + 3^2)
119 const float approxInvL2Norm = 0.267261f;
120
121 RunTest<4, armnn::DataType::Float32>(0,
122 {{"InputLayer", { 1.0f, 2.0f, 3.0f }}},
123 {{"OutputLayer",{ 1.0f * approxInvL2Norm,
124 2.0f * approxInvL2Norm,
125 3.0f * approxInvL2Norm }}});
126}
127
Sadik Armagan1625efc2021-06-10 18:24:34 +0100128TEST_CASE_FIXTURE(L2NormFixture, "L2NormalizationEpsilonLimitFloat32")
Ferran Balaguer0dcffec2019-06-18 16:25:06 +0100129{
130 // 1 / sqrt(1e-8)
131 const float approxInvL2Norm = 10000;
132
133 RunTest<4, armnn::DataType::Float32>(0,
134 {{"InputLayer", { 0.00000001f, 0.00000002f, 0.00000003f }}},
135 {{"OutputLayer",{ 0.00000001f * approxInvL2Norm,
136 0.00000002f * approxInvL2Norm,
137 0.00000003f * approxInvL2Norm }}});
138}
139
Sadik Armagan1625efc2021-06-10 18:24:34 +0100140}