blob: dcfbbb6918fe836812fda0d6922e20259822a120 [file] [log] [blame]
surmeh01bceff2f2018-03-29 16:29:27 +01001//
2// Copyright © 2017 Arm Ltd. All rights reserved.
3// See LICENSE file in the project root for full license information.
4//
5
6#include <boost/test/unit_test.hpp>
7#include "armnnTfParser/ITfParser.hpp"
8#include "ParserPrototxtFixture.hpp"
9
10BOOST_AUTO_TEST_SUITE(TensorflowParser)
11
telsoa01c577f2c2018-08-31 09:22:23 +010012struct LocalResponseNormalizationBaseFixture : public armnnUtils::ParserPrototxtFixture<armnnTfParser::ITfParser>
surmeh01bceff2f2018-03-29 16:29:27 +010013{
14 explicit LocalResponseNormalizationBaseFixture(float alpha, float beta, float bias)
15 {
16 std::string alphaString = std::to_string(alpha);
17 std::string betaString = std::to_string(beta);
18 std::string biasString = std::to_string(bias);
19
20 m_Prototext = "node {"
21 " name: \"Placeholder\""
22 " op: \"Placeholder\""
23 " attr {"
24 " key: \"dtype\""
25 " value {"
26 " type: DT_FLOAT"
27 " }"
28 " }"
29 " attr {"
30 " key: \"shape\""
31 " value {"
32 " shape {"
33 " unknown_rank: true"
34 " }"
35 " }"
36 " }"
37 "}"
38 "node {"
39 " name: \"LRN\""
40 " op: \"LRN\""
41 " input: \"Placeholder\""
42 " attr {"
43 " key: \"T\""
44 " value {"
45 " type: DT_FLOAT"
46 " }"
47 " }"
48 " attr {"
49 " key: \"alpha\""
50 " value {"
51 " f: ";
52 m_Prototext.append(alphaString);
53 m_Prototext.append("\n"
54 " }"
55 " }"
56 " attr {"
57 " key: \"beta\""
58 " value {"
59 " f: ");
60 m_Prototext.append(betaString);
61 m_Prototext.append("\n"
62 " }"
63 " }"
64 " attr {"
65 " key: \"bias\""
66 " value {"
67 " f: ");
68 m_Prototext.append(biasString);
69 m_Prototext.append("\n"
70 " }"
71 " }"
72 " attr {"
73 " key: \"depth_radius\""
74 " value {"
75 " i: 1"
76 " }"
77 " }"
78 "}");
79 }
80};
81
82
83struct LocalResponseNormalizationFixtureSimple : public LocalResponseNormalizationBaseFixture
84{
85 explicit LocalResponseNormalizationFixtureSimple()
86 : LocalResponseNormalizationBaseFixture(1.0f, 1.0f, 1.0f)
87 {
88 SetupSingleInputSingleOutput({ 2, 2, 2, 1 }, "Placeholder", "LRN");
89 }
90};
91BOOST_FIXTURE_TEST_CASE(ParseSimpleLocalResponseNormalization, LocalResponseNormalizationFixtureSimple)
92{
93 RunTest<4>({ 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f },
94 { 0.5f, 0.4f, 0.3f, 0.23529412f, 0.1923077f, 0.16216217f, 0.14f, 0.12307692f });
95}
96
97
98struct LocalResponseNormalizationFixture : public LocalResponseNormalizationBaseFixture
99{
100 explicit LocalResponseNormalizationFixture()
101 : LocalResponseNormalizationBaseFixture(0.5f, 1.0f, 0.5f)
102 {
103 SetupSingleInputSingleOutput({1, 3, 3, 2}, "Placeholder", "LRN");
104 }
105};
106BOOST_FIXTURE_TEST_CASE(ParseLocalResponseNormalization, LocalResponseNormalizationFixture)
107{
108 RunTest<4>({ 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f,
109 7.0f, 8.0f, 9.0f, 10.0f, 11.0f, 12.0f,
110 13.0f, 14.0f, 15.0f, 16.0f, 17.0f, 18.0f},
111
112 {0.333333340f, 0.66666670f, 0.230769250f, 0.307692320f, 0.161290320f, 0.19354838f,
113 0.122807020f, 0.14035088f, 0.098901100f, 0.109890110f, 0.082706770f, 0.09022556f,
114 0.071038246f, 0.07650273f, 0.062240668f, 0.066390045f, 0.055374593f, 0.05863192f});
115}
116
117
118
119
120BOOST_AUTO_TEST_SUITE_END()