Sadik Armagan | 58f3919 | 2018-09-17 14:14:39 +0100 | [diff] [blame] | 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 | |
| 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 | |
| 67 | struct ReLuFixture : ActivationFixture |
| 68 | { |
| 69 | ReLuFixture() : ActivationFixture("RELU", "FLOAT32") {} |
| 70 | }; |
| 71 | BOOST_FIXTURE_TEST_CASE(ParseReLu, ReLuFixture) |
| 72 | { |
Nattapat Chaimanowong | 649dd95 | 2019-01-22 16:10:44 +0000 | [diff] [blame] | 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 }); |
Sadik Armagan | 58f3919 | 2018-09-17 14:14:39 +0100 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | struct ReLu6Fixture : ActivationFixture |
| 78 | { |
| 79 | ReLu6Fixture() : ActivationFixture("RELU6", "FLOAT32") {} |
| 80 | }; |
| 81 | BOOST_FIXTURE_TEST_CASE(ParseReLu6, ReLu6Fixture) |
| 82 | { |
Nattapat Chaimanowong | 649dd95 | 2019-01-22 16:10:44 +0000 | [diff] [blame] | 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 }); |
Sadik Armagan | 58f3919 | 2018-09-17 14:14:39 +0100 | [diff] [blame] | 85 | } |
| 86 | |
Finn Williams | c42c384 | 2019-01-22 14:18:11 +0000 | [diff] [blame] | 87 | struct SigmoidFixture : ActivationFixture |
| 88 | { |
| 89 | SigmoidFixture() : ActivationFixture("LOGISTIC", "FLOAT32") {} |
| 90 | }; |
| 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 | } |
Nina Drozd | 9985176 | 2019-04-09 09:37:38 +0100 | [diff] [blame] | 96 | |
| 97 | struct TanHFixture : ActivationFixture |
| 98 | { |
| 99 | TanHFixture() : ActivationFixture("TANH", "FLOAT32") {} |
| 100 | }; |
| 101 | |
| 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 | } |
Jan Eilers | 2f746b3 | 2020-07-28 14:00:06 +0100 | [diff] [blame] | 108 | |
Matthew Sloyan | 7515d07 | 2020-12-16 12:50:01 +0000 | [diff] [blame] | 109 | struct EluFixture : ActivationFixture |
| 110 | { |
| 111 | EluFixture() : ActivationFixture("ELU", "FLOAT32") {} |
| 112 | }; |
| 113 | |
| 114 | BOOST_FIXTURE_TEST_CASE(ParseElu, EluFixture) |
| 115 | { |
| 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 Eilers | 2f746b3 | 2020-07-28 14:00:06 +0100 | [diff] [blame] | 121 | struct HardSwishFixture : ActivationFixture |
| 122 | { |
| 123 | HardSwishFixture() : ActivationFixture("HARD_SWISH", "FLOAT32") {} |
| 124 | }; |
| 125 | |
| 126 | BOOST_FIXTURE_TEST_CASE(ParseHardSwish, HardSwishFixture) |
| 127 | { |
| 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 Armagan | 58f3919 | 2018-09-17 14:14:39 +0100 | [diff] [blame] | 132 | BOOST_AUTO_TEST_SUITE_END() |