Narumol Prangnawarat | bfaee6b | 2021-05-24 18:50:24 +0100 | [diff] [blame^] | 1 | // |
| 2 | // Copyright © 2021 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 | #include <string> |
| 11 | |
| 12 | BOOST_AUTO_TEST_SUITE(TensorflowLiteParser) |
| 13 | |
| 14 | struct PreluFixture : public ParserFlatbuffersFixture |
| 15 | { |
| 16 | explicit PreluFixture(const std::string& inputShape, |
| 17 | const std::string& alphaShape, |
| 18 | const std::string& outputShape, |
| 19 | const std::string& inputIndex, |
| 20 | const std::string& alphaData) |
| 21 | { |
| 22 | m_JsonString = R"( |
| 23 | { |
| 24 | "version": 3, |
| 25 | "operator_codes": [ |
| 26 | { |
| 27 | "builtin_code": "PRELU", |
| 28 | "version": 1 |
| 29 | } |
| 30 | ], |
| 31 | "subgraphs": [ |
| 32 | { |
| 33 | "tensors": [ |
| 34 | { |
| 35 | "shape": )" + inputShape + R"(, |
| 36 | "type": "FLOAT32", |
| 37 | "buffer": 1, |
| 38 | "name": "input0", |
| 39 | "quantization": { |
| 40 | "details_type": "NONE", |
| 41 | "quantized_dimension": 0 |
| 42 | }, |
| 43 | "is_variable": false |
| 44 | }, |
| 45 | { |
| 46 | "shape": )" + alphaShape + R"(, |
| 47 | "type": "FLOAT32", |
| 48 | "buffer": 2, |
| 49 | "name": "input1", |
| 50 | "quantization": { |
| 51 | "details_type": "NONE", |
| 52 | "quantized_dimension": 0 |
| 53 | }, |
| 54 | "is_variable": false |
| 55 | }, |
| 56 | { |
| 57 | "shape": )" + outputShape + R"(, |
| 58 | "type": "FLOAT32", |
| 59 | "buffer": 3, |
| 60 | "name": "output", |
| 61 | "quantization": { |
| 62 | "details_type": "NONE", |
| 63 | "quantized_dimension": 0 |
| 64 | }, |
| 65 | "is_variable": false |
| 66 | } |
| 67 | ], |
| 68 | "inputs": )" + inputIndex + R"(, |
| 69 | "outputs": [ |
| 70 | 2 |
| 71 | ], |
| 72 | "operators": [ |
| 73 | { |
| 74 | "opcode_index": 0, |
| 75 | "inputs": [ |
| 76 | 0, |
| 77 | 1 |
| 78 | ], |
| 79 | "outputs": [ |
| 80 | 2 |
| 81 | ], |
| 82 | "builtin_options_type": "NONE", |
| 83 | "custom_options_format": "FLEXBUFFERS" |
| 84 | } |
| 85 | ], |
| 86 | "name": "main" |
| 87 | } |
| 88 | ], |
| 89 | "description": "MLIR Converted.", |
| 90 | "buffers": [ |
| 91 | { |
| 92 | }, |
| 93 | { |
| 94 | }, |
| 95 | { )" + alphaData + R"( |
| 96 | }, |
| 97 | { |
| 98 | } |
| 99 | ] |
| 100 | } |
| 101 | )"; |
| 102 | Setup(); |
| 103 | } |
| 104 | }; |
| 105 | |
| 106 | struct SimplePreluFixture : PreluFixture |
| 107 | { |
| 108 | SimplePreluFixture() : PreluFixture("[ 2, 3 ]", |
| 109 | "[ 1, 1 ]", |
| 110 | "[ 2, 3 ]", |
| 111 | "[ 0, 1 ]", |
| 112 | "") {} |
| 113 | }; |
| 114 | |
| 115 | struct PreluConstAlphaFixture : PreluFixture |
| 116 | { |
| 117 | PreluConstAlphaFixture() : PreluFixture( |
| 118 | "[ 2, 3 ]", |
| 119 | "[ 2, 3 ]", |
| 120 | "[ 2, 3 ]", |
| 121 | "[ 0 ]", |
| 122 | "\"data\": [ 0, 0, 128, 62, 0, 0, 128, 62, 0, 0, 128, 62, 0, 0, 128, 62, 0, 0, 128, 62, 0, 0, 128, 62 ]"){} |
| 123 | }; |
| 124 | |
| 125 | struct PreluDynamicTensorFixture : PreluFixture |
| 126 | { |
| 127 | PreluDynamicTensorFixture() : PreluFixture("[ 2, 3 ]", |
| 128 | "[ 1, 1 ]", |
| 129 | "[]", |
| 130 | "[ 0 ]", |
| 131 | "\"data\": [ 0, 0, 128, 62 ]") {} |
| 132 | }; |
| 133 | |
| 134 | BOOST_FIXTURE_TEST_CASE(SimplePrelu, SimplePreluFixture) |
| 135 | { |
| 136 | RunTest<2, armnn::DataType::Float32>( |
| 137 | 0, |
| 138 | {{"input0", { -14.f, 2.f, 0.f, 1.f, -5.f, 14.f }},{"input1", { 0.25f }}}, |
| 139 | {{"output", { -3.5f, 2.f, 0.f, 1.f, -1.25f, 14.f }}}); |
| 140 | } |
| 141 | |
| 142 | BOOST_FIXTURE_TEST_CASE(PreluConstAlpha, PreluConstAlphaFixture) |
| 143 | { |
| 144 | RunTest<2, armnn::DataType::Float32>( |
| 145 | 0, |
| 146 | {{"input0", { -14.f, 2.f, 0.f, 1.f, -5.f, 14.f }}}, |
| 147 | {{"output", { -3.5f, 2.f, 0.f, 1.f, -1.25f, 14.f }}}); |
| 148 | } |
| 149 | |
| 150 | BOOST_FIXTURE_TEST_CASE(PreluDynamicTensor, PreluDynamicTensorFixture) |
| 151 | { |
| 152 | RunTest<2, armnn::DataType::Float32, armnn::DataType::Float32>( |
| 153 | 0, |
| 154 | {{"input0", { -14.f, 2.f, 0.f, 1.f, -5.f, 14.f }}}, |
| 155 | {{"output", { -3.5f, 2.f, 0.f, 1.f, -1.25f, 14.f }}}, |
| 156 | true); |
| 157 | } |
| 158 | |
| 159 | BOOST_AUTO_TEST_SUITE_END() |