blob: a3d75edab5fcad182a0abb3ba42cc091cd5181ef [file] [log] [blame]
Sadik Armagan58f39192018-09-17 14:14:39 +01001//
Finn Williamsb49ed182021-06-29 15:50:08 +01002// Copyright © 2017 Arm Ltd and Contributors. All rights reserved.
Sadik Armagan58f39192018-09-17 14:14:39 +01003// SPDX-License-Identifier: MIT
4//
5
Sadik Armagan58f39192018-09-17 14:14:39 +01006#include "ParserFlatbuffersFixture.hpp"
Sadik Armagan58f39192018-09-17 14:14:39 +01007
Sadik Armagan1625efc2021-06-10 18:24:34 +01008#include <doctest/doctest.h>
Sadik Armagan58f39192018-09-17 14:14:39 +01009
Sadik Armagan1625efc2021-06-10 18:24:34 +010010TEST_SUITE("TensorflowLiteParser_Activations")
11{
Sadik Armagan58f39192018-09-17 14:14:39 +010012struct ActivationFixture : ParserFlatbuffersFixture
13{
14
15 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
67struct ReLuFixture : ActivationFixture
68{
69 ReLuFixture() : ActivationFixture("RELU", "FLOAT32") {}
70};
Sadik Armagan1625efc2021-06-10 18:24:34 +010071TEST_CASE_FIXTURE(ReLuFixture, "ParseReLu")
Sadik Armagan58f39192018-09-17 14:14:39 +010072{
Nattapat Chaimanowong649dd952019-01-22 16:10:44 +000073 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 });
Sadik Armagan58f39192018-09-17 14:14:39 +010075}
76
77struct ReLu6Fixture : ActivationFixture
78{
79 ReLu6Fixture() : ActivationFixture("RELU6", "FLOAT32") {}
80};
Sadik Armagan1625efc2021-06-10 18:24:34 +010081TEST_CASE_FIXTURE(ReLu6Fixture, "ParseReLu6")
Sadik Armagan58f39192018-09-17 14:14:39 +010082{
Nattapat Chaimanowong649dd952019-01-22 16:10:44 +000083 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 });
Sadik Armagan58f39192018-09-17 14:14:39 +010085}
86
Finn Williamsc42c3842019-01-22 14:18:11 +000087struct SigmoidFixture : ActivationFixture
88{
89 SigmoidFixture() : ActivationFixture("LOGISTIC", "FLOAT32") {}
90};
Sadik Armagan1625efc2021-06-10 18:24:34 +010091TEST_CASE_FIXTURE(SigmoidFixture, "ParseLogistic")
Finn Williamsc42c3842019-01-22 14:18:11 +000092{
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}
Nina Drozd99851762019-04-09 09:37:38 +010096
97struct TanHFixture : ActivationFixture
98{
99 TanHFixture() : ActivationFixture("TANH", "FLOAT32") {}
100};
101
Sadik Armagan1625efc2021-06-10 18:24:34 +0100102TEST_CASE_FIXTURE(TanHFixture, "ParseTanH")
Nina Drozd99851762019-04-09 09:37:38 +0100103{
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}
Jan Eilers2f746b32020-07-28 14:00:06 +0100108
Matthew Sloyan7515d072020-12-16 12:50:01 +0000109struct EluFixture : ActivationFixture
110{
111 EluFixture() : ActivationFixture("ELU", "FLOAT32") {}
112};
113
Sadik Armagan1625efc2021-06-10 18:24:34 +0100114TEST_CASE_FIXTURE(EluFixture, "ParseElu")
Matthew Sloyan7515d072020-12-16 12:50:01 +0000115{
116 RunTest<2, armnn::DataType::Float32>(0,
117 { -2.0f, -1.0f, -0.0f, 0.0f, 1.0f, 2.0f, 3.0f },
118 { -0.86466471676f, -0.63212055882f, -0.0f, 0.0f, 1.0f, 2.0f, 3.0f });
119}
120
Jan Eilers2f746b32020-07-28 14:00:06 +0100121struct HardSwishFixture : ActivationFixture
122{
123 HardSwishFixture() : ActivationFixture("HARD_SWISH", "FLOAT32") {}
124};
125
Sadik Armagan1625efc2021-06-10 18:24:34 +0100126TEST_CASE_FIXTURE(HardSwishFixture, "ParseHardSwish")
Jan Eilers2f746b32020-07-28 14:00:06 +0100127{
128 RunTest<2, armnn::DataType::Float32>(0,
129 { -4.0f, -3.0f, -2.9f, 1.2f, 2.2f, 3.0f, 4.0f },
130 { -0.0f, -0.0f, -0.04833334f, 0.84f, 1.90666667f, 3.0f, 4.0f });
131}
Sadik Armagan1625efc2021-06-10 18:24:34 +0100132
133}