1 //
2 // Copyright © 2017 Arm Ltd. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5
6 #include <boost/test/unit_test.hpp>
7 #include "ParserFlatbuffersFixture.hpp"
8 #include "../TfLiteParser.hpp"
9
10 BOOST_AUTO_TEST_SUITE(TensorflowLiteParser)
11
12 struct ActivationFixture : ParserFlatbuffersFixture
13 {
14
ActivationFixtureActivationFixture15 explicit ActivationFixture(std::string activationFunction, std::string dataType)
16 {
17 m_JsonString = R"(
18 {
19 "version": 3,
20 "operator_codes": [ { "builtin_code": )" + activationFunction + R"( } ],
21 "subgraphs": [ {
22 "tensors": [
23 {
24 "shape": [ 1, 7 ],
25 "type": )" + dataType + R"(,
26 "buffer": 0,
27 "name": "inputTensor",
28 "quantization": {
29 "min": [ 0.0 ],
30 "max": [ 255.0 ],
31 "scale": [ 1.0 ],
32 "zero_point": [ 0 ],
33 }
34 },
35 {
36 "shape": [ 1, 7 ],
37 "type": )" + dataType + R"(,
38 "buffer": 1,
39 "name": "outputTensor",
40 "quantization": {
41 "min": [ 0.0 ],
42 "max": [ 255.0 ],
43 "scale": [ 1.0 ],
44 "zero_point": [ 0 ],
45 }
46 }
47 ],
48 "inputs": [ 0 ],
49 "outputs": [ 1 ],
50 "operators": [
51 {
52 "opcode_index": 0,
53 "inputs": [ 0 ],
54 "outputs": [ 1 ],
55 "custom_options_format": "FLEXBUFFERS"
56 }
57 ],
58 } ],
59 "buffers" : [ {}, {} ]
60 }
61 )";
62 SetupSingleInputSingleOutput("inputTensor", "outputTensor");
63 }
64
65 };
66
67 struct ReLuFixture : ActivationFixture
68 {
ReLuFixtureReLuFixture69 ReLuFixture() : ActivationFixture("RELU", "FLOAT32") {}
70 };
BOOST_FIXTURE_TEST_CASE(ParseReLu,ReLuFixture)71 BOOST_FIXTURE_TEST_CASE(ParseReLu, ReLuFixture)
72 {
73 RunTest<2, armnn::DataType::Float32>(0, { -1.0f, -0.5f, 1.25f, -3.0f, 0.0f, 0.5f, -0.75f },
74 { 0.0f, 0.0f, 1.25f, 0.0f, 0.0f, 0.5f, 0.0f });
75 }
76
77 struct ReLu6Fixture : ActivationFixture
78 {
ReLu6FixtureReLu6Fixture79 ReLu6Fixture() : ActivationFixture("RELU6", "FLOAT32") {}
80 };
BOOST_FIXTURE_TEST_CASE(ParseReLu6,ReLu6Fixture)81 BOOST_FIXTURE_TEST_CASE(ParseReLu6, ReLu6Fixture)
82 {
83 RunTest<2, armnn::DataType::Float32>(0, { -1.0f, -0.5f, 7.25f, -3.0f, 0.0f, 0.5f, -0.75f },
84 { 0.0f, 0.0f, 6.0f, 0.0f, 0.0f, 0.5f, 0.0f });
85 }
86
87 struct SigmoidFixture : ActivationFixture
88 {
SigmoidFixtureSigmoidFixture89 SigmoidFixture() : ActivationFixture("LOGISTIC", "FLOAT32") {}
90 };
BOOST_FIXTURE_TEST_CASE(ParseLogistic,SigmoidFixture)91 BOOST_FIXTURE_TEST_CASE(ParseLogistic, SigmoidFixture)
92 {
93 RunTest<2, armnn::DataType::Float32>(0, { -1.0f, -0.5f, 4.0f, -4.0f, 0.0f, 0.5f, -0.75f },
94 {0.268941f, 0.377541f, 0.982013f, 0.0179862f, 0.5f, 0.622459f, 0.320821f });
95 }
96
97 struct TanHFixture : ActivationFixture
98 {
TanHFixtureTanHFixture99 TanHFixture() : ActivationFixture("TANH", "FLOAT32") {}
100 };
101
BOOST_FIXTURE_TEST_CASE(ParseTanH,TanHFixture)102 BOOST_FIXTURE_TEST_CASE(ParseTanH, TanHFixture)
103 {
104 RunTest<2, armnn::DataType::Float32>(0,
105 { -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
109 struct HardSwishFixture : ActivationFixture
110 {
HardSwishFixtureHardSwishFixture111 HardSwishFixture() : ActivationFixture("HARD_SWISH", "FLOAT32") {}
112 };
113
BOOST_FIXTURE_TEST_CASE(ParseHardSwish,HardSwishFixture)114 BOOST_FIXTURE_TEST_CASE(ParseHardSwish, HardSwishFixture)
115 {
116 RunTest<2, armnn::DataType::Float32>(0,
117 { -4.0f, -3.0f, -2.9f, 1.2f, 2.2f, 3.0f, 4.0f },
118 { -0.0f, -0.0f, -0.04833334f, 0.84f, 1.90666667f, 3.0f, 4.0f });
119 }
120 BOOST_AUTO_TEST_SUITE_END()
121