blob: 980edc4c5d7460138cfd4779dc1c7ab0eb11d028 [file] [log] [blame]
Sadik Armagan58f39192018-09-17 14:14:39 +01001//
2// Copyright © 2017 Arm Ltd. All rights reserved.
3// SPDX-License-Identifier: MIT
4//
5
Sadik Armagan58f39192018-09-17 14:14:39 +01006#include "ParserFlatbuffersFixture.hpp"
7#include "../TfLiteParser.hpp"
8
Sadik Armagan1625efc2021-06-10 18:24:34 +01009#include <doctest/doctest.h>
Sadik Armagan58f39192018-09-17 14:14:39 +010010
Sadik Armagan1625efc2021-06-10 18:24:34 +010011TEST_SUITE("TensorflowLiteParser_Activations")
12{
Sadik Armagan58f39192018-09-17 14:14:39 +010013struct ActivationFixture : ParserFlatbuffersFixture
14{
15
16 explicit ActivationFixture(std::string activationFunction, std::string dataType)
17 {
18 m_JsonString = R"(
19 {
20 "version": 3,
21 "operator_codes": [ { "builtin_code": )" + activationFunction + R"( } ],
22 "subgraphs": [ {
23 "tensors": [
24 {
25 "shape": [ 1, 7 ],
26 "type": )" + dataType + R"(,
27 "buffer": 0,
28 "name": "inputTensor",
29 "quantization": {
30 "min": [ 0.0 ],
31 "max": [ 255.0 ],
32 "scale": [ 1.0 ],
33 "zero_point": [ 0 ],
34 }
35 },
36 {
37 "shape": [ 1, 7 ],
38 "type": )" + dataType + R"(,
39 "buffer": 1,
40 "name": "outputTensor",
41 "quantization": {
42 "min": [ 0.0 ],
43 "max": [ 255.0 ],
44 "scale": [ 1.0 ],
45 "zero_point": [ 0 ],
46 }
47 }
48 ],
49 "inputs": [ 0 ],
50 "outputs": [ 1 ],
51 "operators": [
52 {
53 "opcode_index": 0,
54 "inputs": [ 0 ],
55 "outputs": [ 1 ],
56 "custom_options_format": "FLEXBUFFERS"
57 }
58 ],
59 } ],
60 "buffers" : [ {}, {} ]
61 }
62 )";
63 SetupSingleInputSingleOutput("inputTensor", "outputTensor");
64 }
65
66};
67
68struct ReLuFixture : ActivationFixture
69{
70 ReLuFixture() : ActivationFixture("RELU", "FLOAT32") {}
71};
Sadik Armagan1625efc2021-06-10 18:24:34 +010072TEST_CASE_FIXTURE(ReLuFixture, "ParseReLu")
Sadik Armagan58f39192018-09-17 14:14:39 +010073{
Nattapat Chaimanowong649dd952019-01-22 16:10:44 +000074 RunTest<2, armnn::DataType::Float32>(0, { -1.0f, -0.5f, 1.25f, -3.0f, 0.0f, 0.5f, -0.75f },
75 { 0.0f, 0.0f, 1.25f, 0.0f, 0.0f, 0.5f, 0.0f });
Sadik Armagan58f39192018-09-17 14:14:39 +010076}
77
78struct ReLu6Fixture : ActivationFixture
79{
80 ReLu6Fixture() : ActivationFixture("RELU6", "FLOAT32") {}
81};
Sadik Armagan1625efc2021-06-10 18:24:34 +010082TEST_CASE_FIXTURE(ReLu6Fixture, "ParseReLu6")
Sadik Armagan58f39192018-09-17 14:14:39 +010083{
Nattapat Chaimanowong649dd952019-01-22 16:10:44 +000084 RunTest<2, armnn::DataType::Float32>(0, { -1.0f, -0.5f, 7.25f, -3.0f, 0.0f, 0.5f, -0.75f },
85 { 0.0f, 0.0f, 6.0f, 0.0f, 0.0f, 0.5f, 0.0f });
Sadik Armagan58f39192018-09-17 14:14:39 +010086}
87
Finn Williamsc42c3842019-01-22 14:18:11 +000088struct SigmoidFixture : ActivationFixture
89{
90 SigmoidFixture() : ActivationFixture("LOGISTIC", "FLOAT32") {}
91};
Sadik Armagan1625efc2021-06-10 18:24:34 +010092TEST_CASE_FIXTURE(SigmoidFixture, "ParseLogistic")
Finn Williamsc42c3842019-01-22 14:18:11 +000093{
94 RunTest<2, armnn::DataType::Float32>(0, { -1.0f, -0.5f, 4.0f, -4.0f, 0.0f, 0.5f, -0.75f },
95 {0.268941f, 0.377541f, 0.982013f, 0.0179862f, 0.5f, 0.622459f, 0.320821f });
96}
Nina Drozd99851762019-04-09 09:37:38 +010097
98struct TanHFixture : ActivationFixture
99{
100 TanHFixture() : ActivationFixture("TANH", "FLOAT32") {}
101};
102
Sadik Armagan1625efc2021-06-10 18:24:34 +0100103TEST_CASE_FIXTURE(TanHFixture, "ParseTanH")
Nina Drozd99851762019-04-09 09:37:38 +0100104{
105 RunTest<2, armnn::DataType::Float32>(0,
106 { -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}
Jan Eilers2f746b32020-07-28 14:00:06 +0100109
Matthew Sloyan7515d072020-12-16 12:50:01 +0000110struct EluFixture : ActivationFixture
111{
112 EluFixture() : ActivationFixture("ELU", "FLOAT32") {}
113};
114
Sadik Armagan1625efc2021-06-10 18:24:34 +0100115TEST_CASE_FIXTURE(EluFixture, "ParseElu")
Matthew Sloyan7515d072020-12-16 12:50:01 +0000116{
117 RunTest<2, armnn::DataType::Float32>(0,
118 { -2.0f, -1.0f, -0.0f, 0.0f, 1.0f, 2.0f, 3.0f },
119 { -0.86466471676f, -0.63212055882f, -0.0f, 0.0f, 1.0f, 2.0f, 3.0f });
120}
121
Jan Eilers2f746b32020-07-28 14:00:06 +0100122struct HardSwishFixture : ActivationFixture
123{
124 HardSwishFixture() : ActivationFixture("HARD_SWISH", "FLOAT32") {}
125};
126
Sadik Armagan1625efc2021-06-10 18:24:34 +0100127TEST_CASE_FIXTURE(HardSwishFixture, "ParseHardSwish")
Jan Eilers2f746b32020-07-28 14:00:06 +0100128{
129 RunTest<2, armnn::DataType::Float32>(0,
130 { -4.0f, -3.0f, -2.9f, 1.2f, 2.2f, 3.0f, 4.0f },
131 { -0.0f, -0.0f, -0.04833334f, 0.84f, 1.90666667f, 3.0f, 4.0f });
132}
Sadik Armagan1625efc2021-06-10 18:24:34 +0100133
134}