blob: eb7e958c5b65c51b0ca0b80216b17db43647ec1e [file] [log] [blame]
Nina Drozd57728782019-02-27 10:53:27 +00001//
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"
8#include "../Deserializer.hpp"
9
10#include <string>
11#include <iostream>
12
13BOOST_AUTO_TEST_SUITE(Deserializer)
14
15struct NormalizationFixture : public ParserFlatbuffersSerializeFixture
16{
17 explicit NormalizationFixture(const std::string &inputShape,
18 const std::string & outputShape,
19 const std::string &dataType,
20 const std::string &normAlgorithmChannel,
21 const std::string &normAlgorithmMethod,
22 const std::string &dataLayout)
23 {
24 m_JsonString = R"(
25 {
26 inputIds: [0],
27 outputIds: [2],
28 layers: [{
29 layer_type: "InputLayer",
30 layer: {
31 base: {
32 layerBindingId: 0,
33 base: {
34 index: 0,
35 layerName: "InputLayer",
36 layerType: "Input",
37 inputSlots: [{
38 index: 0,
39 connection: {sourceLayerIndex:0, outputSlotIndex:0 },
40 }],
41 outputSlots: [{
42 index: 0,
43 tensorInfo: {
44 dimensions: )" + inputShape + R"(,
45 dataType: )" + dataType + R"(,
46 quantizationScale: 0.5,
47 quantizationOffset: 0
48 },
49 }]
50 },
51 }
52 },
53 },
54 {
55 layer_type: "NormalizationLayer",
56 layer : {
57 base: {
58 index:1,
59 layerName: "NormalizationLayer",
60 layerType: "Normalization",
61 inputSlots: [{
62 index: 0,
63 connection: {sourceLayerIndex:0, outputSlotIndex:0 },
64 }],
65 outputSlots: [{
66 index: 0,
67 tensorInfo: {
68 dimensions: )" + outputShape + R"(,
69 dataType: )" + dataType + R"(
70 },
71 }],
72 },
73 descriptor: {
74 normChannelType: )" + normAlgorithmChannel + R"(,
75 normMethodType: )" + normAlgorithmMethod + R"(,
76 normSize: 3,
77 alpha: 1,
78 beta: 1,
79 k: 1,
80 dataLayout: )" + dataLayout + R"(
81 }
82 },
83 },
84 {
85 layer_type: "OutputLayer",
86 layer: {
87 base:{
88 layerBindingId: 0,
89 base: {
90 index: 2,
91 layerName: "OutputLayer",
92 layerType: "Output",
93 inputSlots: [{
94 index: 0,
95 connection: {sourceLayerIndex:1, outputSlotIndex:0 },
96 }],
97 outputSlots: [ {
98 index: 0,
99 tensorInfo: {
100 dimensions: )" + outputShape + R"(,
101 dataType: )" + dataType + R"(
102 },
103 }],
104 }
105 }},
106 }]
107 }
108 )";
109 SetupSingleInputSingleOutput("InputLayer", "OutputLayer");
110 }
111};
112
113struct FloatNhwcLocalBrightnessAcrossNormalizationFixture : NormalizationFixture
114{
115 FloatNhwcLocalBrightnessAcrossNormalizationFixture() : NormalizationFixture("[ 2, 2, 2, 1 ]", "[ 2, 2, 2, 1 ]",
116 "Float32", "0", "0", "NHWC") {}
117};
118
119
120BOOST_FIXTURE_TEST_CASE(Float32NormalizationNhwcDataLayout, FloatNhwcLocalBrightnessAcrossNormalizationFixture)
121{
122 RunTest<4, armnn::DataType::Float32>(0, { 1.0f, 2.0f, 3.0f, 4.0f,
123 5.0f, 6.0f, 7.0f, 8.0f },
124 { 0.5f, 0.400000006f, 0.300000012f, 0.235294119f,
125 0.192307696f, 0.16216217f, 0.140000001f, 0.123076923f });
126}
127
128struct FloatNchwLocalBrightnessWithinNormalizationFixture : NormalizationFixture
129{
130 FloatNchwLocalBrightnessWithinNormalizationFixture() : NormalizationFixture("[ 2, 1, 2, 2 ]", "[ 2, 1, 2, 2 ]",
131 "Float32", "1", "0", "NCHW") {}
132};
133
134BOOST_FIXTURE_TEST_CASE(Float32NormalizationNchwDataLayout, FloatNchwLocalBrightnessWithinNormalizationFixture)
135{
136 RunTest<4, armnn::DataType::Float32>(0, { 1.0f, 2.0f, 3.0f, 4.0f,
137 5.0f, 6.0f, 7.0f, 8.0f },
138 { 0.0322581f, 0.0645161f, 0.0967742f, 0.1290323f,
139 0.0285714f, 0.0342857f, 0.04f, 0.0457143f });
140}
141
142
143BOOST_AUTO_TEST_SUITE_END()