blob: dac16ce2c6f282a5ae1ec9ea18003e7bbec708f3 [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
6#include <boost/test/unit_test.hpp>
7#include "ParserFlatbuffersFixture.hpp"
8#include "../TfLiteParser.hpp"
9
10BOOST_AUTO_TEST_SUITE(TensorflowLiteParser)
11
12struct 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};
71BOOST_FIXTURE_TEST_CASE(ParseReLu, ReLuFixture)
72{
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};
81BOOST_FIXTURE_TEST_CASE(ParseReLu6, ReLu6Fixture)
82{
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};
91BOOST_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}
Sadik Armagan58f39192018-09-17 14:14:39 +010096BOOST_AUTO_TEST_SUITE_END()