blob: 595fce768e00a8251ad3acb97750980c60b561ff [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 ActivationFixture : public armnnUtils::ParserPrototxtFixture<armnnTfParser::ITfParser>
surmeh01bceff2f2018-03-29 16:29:27 +010013{
14 explicit ActivationFixture(const char* activationFunction)
15 {
16 m_Prototext = "node {\n"
17 " name: \"Placeholder\"\n"
18 " op: \"Placeholder\"\n"
19 " attr {\n"
20 " key: \"dtype\"\n"
21 " value {\n"
22 " type: DT_FLOAT\n"
23 " }\n"
24 " }\n"
25 " attr {\n"
26 " key: \"shape\"\n"
27 " value {\n"
28 " shape {\n"
29 " unknown_rank: true\n"
30 " }\n"
31 " }\n"
32 " }\n"
33 "}\n"
34 "node {\n"
35 " name: \"";
36 m_Prototext.append(activationFunction);
37 m_Prototext.append("\"\n"
38 " op: \"");
39 m_Prototext.append(activationFunction);
40 m_Prototext.append("\"\n"
41 " input: \"Placeholder\"\n"
42 " attr {\n"
43 " key: \"T\"\n"
44 " value {\n"
45 " type: DT_FLOAT\n"
46 " }\n"
47 " }\n"
48 "}\n");
49
50 SetupSingleInputSingleOutput({ 1, 7 }, "Placeholder", activationFunction);
51 }
52};
53
54
55struct ReLuFixture : ActivationFixture
56{
57 ReLuFixture() : ActivationFixture("Relu") {}
58};
59BOOST_FIXTURE_TEST_CASE(ParseReLu, ReLuFixture)
60{
61 RunTest<2>({ -1.0f, -0.5f, 1.25f, -3.0f, 0.0f, 0.5f, -0.75f },
62 { 0.0f, 0.0f, 1.25f, 0.0f, 0.0f, 0.5f, 0.0f });
63}
64
65
66struct ReLu6Fixture : ActivationFixture
67{
68 ReLu6Fixture() : ActivationFixture("Relu6") {}
69};
70BOOST_FIXTURE_TEST_CASE(ParseReLu6, ReLu6Fixture)
71{
72 RunTest<2>({ -1.0f, -0.5f, 7.25f, -3.0f, 0.0f, 0.5f, -0.75f },
73 { 0.0f, 0.0f, 6.0f, 0.0f, 0.0f, 0.5f, 0.0f });
74}
75
76
77struct SigmoidFixture : ActivationFixture
78{
79 SigmoidFixture() : ActivationFixture("Sigmoid") {}
80};
81BOOST_FIXTURE_TEST_CASE(ParseSigmoid, SigmoidFixture)
82{
83 RunTest<2>({ -0.1f, -0.2f, -0.3f, -0.4f, 0.1f, 0.2f, 0.3f },
84 { 0.4750208f, 0.45016602f, 0.42555749f, 0.40131235f, 0.52497917f, 0.54983395f, 0.57444251f });
85}
86
87
88struct SoftplusFixture : ActivationFixture
89{
90 SoftplusFixture() : ActivationFixture("Softplus") {}
91};
92BOOST_FIXTURE_TEST_CASE(ParseSoftplus, SoftplusFixture)
93{
94 RunTest<2>({ -0.1f, -0.2f, -0.3f, -0.4f, 0.1f, 0.2f, 0.3f },
95 { 0.64439666f, 0.59813893f, 0.55435526f, 0.51301527f, 0.74439669f, 0.7981388f, 0.85435522f });
96}
97
98
99struct TanhFixture : ActivationFixture
100{
101 TanhFixture() : ActivationFixture("Tanh") {}
102};
103BOOST_FIXTURE_TEST_CASE(ParseTanh, TanhFixture)
104{
105 RunTest<2>({ -0.1f, -0.2f, -0.3f, -0.4f, 0.1f, 0.2f, 0.3f },
106 { -0.09966799f, -0.19737528f, -0.29131261f, -0.379949f, 0.09966799f, 0.19737528f, 0.29131261f });
107}
108
surmeh01bceff2f2018-03-29 16:29:27 +0100109BOOST_AUTO_TEST_SUITE_END()