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