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