Bruno Goncalves | 6c2355b | 2018-12-19 12:52:01 -0200 | [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 | #include <string> |
| 11 | #include <iostream> |
| 12 | |
| 13 | BOOST_AUTO_TEST_SUITE(TensorflowLiteParser) |
| 14 | |
| 15 | struct PadFixture : public ParserFlatbuffersFixture |
| 16 | { |
Narumol Prangnawarat | 8719d22 | 2020-11-27 16:57:56 +0000 | [diff] [blame] | 17 | explicit PadFixture(const std::string& inputShape, |
| 18 | const std::string& outputShape, |
| 19 | const std::string& padListShape, |
| 20 | const std::string& padListData, |
| 21 | const std::string& dataType = "FLOAT32", |
| 22 | const std::string& scale = "1.0", |
| 23 | const std::string& offset = "0") |
Bruno Goncalves | 6c2355b | 2018-12-19 12:52:01 -0200 | [diff] [blame] | 24 | { |
| 25 | m_JsonString = R"( |
| 26 | { |
| 27 | "version": 3, |
| 28 | "operator_codes": [ { "builtin_code": "PAD" } ], |
| 29 | "subgraphs": [ { |
| 30 | "tensors": [ |
| 31 | { |
| 32 | "shape": )" + inputShape + R"(, |
Narumol Prangnawarat | 8719d22 | 2020-11-27 16:57:56 +0000 | [diff] [blame] | 33 | "type": )" + dataType + R"(, |
Bruno Goncalves | 6c2355b | 2018-12-19 12:52:01 -0200 | [diff] [blame] | 34 | "buffer": 0, |
| 35 | "name": "inputTensor", |
| 36 | "quantization": { |
| 37 | "min": [ 0.0 ], |
| 38 | "max": [ 255.0 ], |
Narumol Prangnawarat | 8719d22 | 2020-11-27 16:57:56 +0000 | [diff] [blame] | 39 | "scale": [ )" + scale + R"( ], |
| 40 | "zero_point": [ )" + offset + R"( ], |
Bruno Goncalves | 6c2355b | 2018-12-19 12:52:01 -0200 | [diff] [blame] | 41 | } |
| 42 | }, |
| 43 | { |
| 44 | "shape": )" + outputShape + R"(, |
Narumol Prangnawarat | 8719d22 | 2020-11-27 16:57:56 +0000 | [diff] [blame] | 45 | "type": )" + dataType + R"(, |
Bruno Goncalves | 6c2355b | 2018-12-19 12:52:01 -0200 | [diff] [blame] | 46 | "buffer": 1, |
| 47 | "name": "outputTensor", |
| 48 | "quantization": { |
| 49 | "min": [ 0.0 ], |
| 50 | "max": [ 255.0 ], |
Narumol Prangnawarat | 8719d22 | 2020-11-27 16:57:56 +0000 | [diff] [blame] | 51 | "scale": [ )" + scale + R"( ], |
| 52 | "zero_point": [ )" + offset + R"( ], |
Bruno Goncalves | 6c2355b | 2018-12-19 12:52:01 -0200 | [diff] [blame] | 53 | } |
| 54 | }, |
| 55 | { |
| 56 | "shape": )" + padListShape + R"( , |
| 57 | "type": "INT32", |
| 58 | "buffer": 2, |
| 59 | "name": "padList", |
| 60 | "quantization": { |
| 61 | "min": [ 0.0 ], |
| 62 | "max": [ 255.0 ], |
| 63 | "scale": [ 1.0 ], |
| 64 | "zero_point": [ 0 ], |
| 65 | } |
| 66 | } |
| 67 | ], |
| 68 | "inputs": [ 0 ], |
| 69 | "outputs": [ 1 ], |
| 70 | "operators": [ |
| 71 | { |
| 72 | "opcode_index": 0, |
| 73 | "inputs": [ 0, 2 ], |
| 74 | "outputs": [ 1 ], |
| 75 | "custom_options_format": "FLEXBUFFERS" |
| 76 | } |
| 77 | ], |
| 78 | } ], |
| 79 | "buffers" : [ |
| 80 | { }, |
| 81 | { }, |
| 82 | { "data": )" + padListData + R"(, }, |
| 83 | ] |
| 84 | } |
| 85 | )"; |
| 86 | SetupSingleInputSingleOutput("inputTensor", "outputTensor"); |
| 87 | } |
| 88 | }; |
| 89 | |
| 90 | struct SimplePadFixture : public PadFixture |
| 91 | { |
| 92 | SimplePadFixture() : PadFixture("[ 2, 3 ]", "[ 4, 7 ]", "[ 2, 2 ]", |
| 93 | "[ 1,0,0,0, 1,0,0,0, 2,0,0,0, 2,0,0,0 ]") {} |
| 94 | }; |
| 95 | |
| 96 | BOOST_FIXTURE_TEST_CASE(ParsePad, SimplePadFixture) |
| 97 | { |
Nattapat Chaimanowong | 649dd95 | 2019-01-22 16:10:44 +0000 | [diff] [blame] | 98 | RunTest<2, armnn::DataType::Float32> |
| 99 | (0, |
| 100 | {{ "inputTensor", { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f }}}, |
| 101 | {{ "outputTensor", { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, |
| 102 | 0.0f, 0.0f, 1.0f, 2.0f, 3.0f, 0.0f, 0.0f, |
| 103 | 0.0f, 0.0f, 4.0f, 5.0f, 6.0f, 0.0f, 0.0f, |
| 104 | 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f }}}); |
Bruno Goncalves | 6c2355b | 2018-12-19 12:52:01 -0200 | [diff] [blame] | 105 | } |
| 106 | |
Narumol Prangnawarat | 8719d22 | 2020-11-27 16:57:56 +0000 | [diff] [blame] | 107 | struct Uint8PadFixture : public PadFixture |
| 108 | { |
| 109 | Uint8PadFixture() : PadFixture("[ 2, 3 ]", "[ 4, 7 ]", "[ 2, 2 ]", |
| 110 | "[ 1,0,0,0, 1,0,0,0, 2,0,0,0, 2,0,0,0 ]", |
| 111 | "UINT8", "-2.0", "3") {} |
| 112 | }; |
| 113 | |
| 114 | BOOST_FIXTURE_TEST_CASE(ParsePadUint8, Uint8PadFixture) |
| 115 | { |
| 116 | RunTest<2, armnn::DataType::QAsymmU8> |
| 117 | (0, |
| 118 | {{ "inputTensor", { 1, 2, 3, 4, 5, 6 }}}, |
| 119 | {{ "outputTensor", { 3, 3, 3, 3, 3, 3, 3, |
| 120 | 3, 3, 1, 2, 3, 3, 3, |
| 121 | 3, 3, 4, 5, 6, 3, 3, |
| 122 | 3, 3, 3, 3, 3, 3, 3 }}}); |
| 123 | } |
| 124 | |
| 125 | struct Int8PadFixture : public PadFixture |
| 126 | { |
| 127 | Int8PadFixture() : PadFixture("[ 2, 3 ]", "[ 4, 7 ]", "[ 2, 2 ]", |
| 128 | "[ 1,0,0,0, 1,0,0,0, 2,0,0,0, 2,0,0,0 ]", |
| 129 | "INT8", "-2.0", "3") {} |
| 130 | }; |
| 131 | |
| 132 | BOOST_FIXTURE_TEST_CASE(ParsePadInt8, Int8PadFixture) |
| 133 | { |
| 134 | RunTest<2, armnn::DataType::QAsymmS8> |
| 135 | (0, |
| 136 | {{ "inputTensor", { 1, -2, 3, 4, 5, -6 }}}, |
| 137 | {{ "outputTensor", { 3, 3, 3, 3, 3, 3, 3, |
| 138 | 3, 3, 1, -2, 3, 3, 3, |
| 139 | 3, 3, 4, 5, -6, 3, 3, |
| 140 | 3, 3, 3, 3, 3, 3, 3 }}}); |
| 141 | } |
| 142 | |
Bruno Goncalves | 6c2355b | 2018-12-19 12:52:01 -0200 | [diff] [blame] | 143 | BOOST_AUTO_TEST_SUITE_END() |