ArmNN
 20.02
Activations.cpp
Go to the documentation of this file.
1 //
2 // Copyright © 2017 Arm Ltd. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 
6 #include <boost/test/unit_test.hpp>
9 
10 BOOST_AUTO_TEST_SUITE(TensorflowParser)
11 
12 struct ActivationFixture : public armnnUtils::ParserPrototxtFixture<armnnTfParser::ITfParser>
13 {
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 
55 struct ReLuFixture : ActivationFixture
56 {
57  ReLuFixture() : ActivationFixture("Relu") {}
58 };
59 BOOST_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 
66 struct ReLu6Fixture : ActivationFixture
67 {
68  ReLu6Fixture() : ActivationFixture("Relu6") {}
69 };
70 BOOST_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 
77 struct SigmoidFixture : ActivationFixture
78 {
79  SigmoidFixture() : ActivationFixture("Sigmoid") {}
80 };
81 BOOST_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 
88 struct SoftplusFixture : ActivationFixture
89 {
90  SoftplusFixture() : ActivationFixture("Softplus") {}
91 };
92 BOOST_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 
99 struct TanhFixture : ActivationFixture
100 {
101  TanhFixture() : ActivationFixture("Tanh") {}
102 };
103 BOOST_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 
BOOST_AUTO_TEST_SUITE(TensorflowLiteParser)
BOOST_FIXTURE_TEST_CASE(ParseReLu, ReLuFixture)
Definition: Activations.cpp:71
BOOST_AUTO_TEST_SUITE_END()
void SetupSingleInputSingleOutput(const std::string &inputName, const std::string &outputName)
Parses and loads the network defined by the m_Prototext string.