blob: 31df50d6b9ee9d19accf9ceac88ba1d37ffb3409 [file] [log] [blame]
Bruno Goncalves6c2355b2018-12-19 12:52:01 -02001//
Finn Williamsb49ed182021-06-29 15:50:08 +01002// Copyright © 2017 Arm Ltd and Contributors. All rights reserved.
Bruno Goncalves6c2355b2018-12-19 12:52:01 -02003// SPDX-License-Identifier: MIT
4//
5
Bruno Goncalves6c2355b2018-12-19 12:52:01 -02006#include "ParserFlatbuffersFixture.hpp"
Bruno Goncalves6c2355b2018-12-19 12:52:01 -02007
Bruno Goncalves6c2355b2018-12-19 12:52:01 -02008
Sadik Armagan1625efc2021-06-10 18:24:34 +01009TEST_SUITE("TensorflowLiteParser_Pad")
10{
Bruno Goncalves6c2355b2018-12-19 12:52:01 -020011struct PadFixture : public ParserFlatbuffersFixture
12{
Narumol Prangnawarat8719d222020-11-27 16:57:56 +000013 explicit PadFixture(const std::string& inputShape,
14 const std::string& outputShape,
15 const std::string& padListShape,
16 const std::string& padListData,
17 const std::string& dataType = "FLOAT32",
18 const std::string& scale = "1.0",
19 const std::string& offset = "0")
Bruno Goncalves6c2355b2018-12-19 12:52:01 -020020 {
21 m_JsonString = R"(
22 {
23 "version": 3,
24 "operator_codes": [ { "builtin_code": "PAD" } ],
25 "subgraphs": [ {
26 "tensors": [
27 {
28 "shape": )" + inputShape + R"(,
Narumol Prangnawarat8719d222020-11-27 16:57:56 +000029 "type": )" + dataType + R"(,
Bruno Goncalves6c2355b2018-12-19 12:52:01 -020030 "buffer": 0,
31 "name": "inputTensor",
32 "quantization": {
33 "min": [ 0.0 ],
34 "max": [ 255.0 ],
Narumol Prangnawarat8719d222020-11-27 16:57:56 +000035 "scale": [ )" + scale + R"( ],
36 "zero_point": [ )" + offset + R"( ],
Bruno Goncalves6c2355b2018-12-19 12:52:01 -020037 }
38 },
39 {
40 "shape": )" + outputShape + R"(,
Narumol Prangnawarat8719d222020-11-27 16:57:56 +000041 "type": )" + dataType + R"(,
Bruno Goncalves6c2355b2018-12-19 12:52:01 -020042 "buffer": 1,
43 "name": "outputTensor",
44 "quantization": {
45 "min": [ 0.0 ],
46 "max": [ 255.0 ],
Narumol Prangnawarat8719d222020-11-27 16:57:56 +000047 "scale": [ )" + scale + R"( ],
48 "zero_point": [ )" + offset + R"( ],
Bruno Goncalves6c2355b2018-12-19 12:52:01 -020049 }
50 },
51 {
52 "shape": )" + padListShape + R"( ,
53 "type": "INT32",
54 "buffer": 2,
55 "name": "padList",
56 "quantization": {
57 "min": [ 0.0 ],
58 "max": [ 255.0 ],
59 "scale": [ 1.0 ],
60 "zero_point": [ 0 ],
61 }
62 }
63 ],
64 "inputs": [ 0 ],
65 "outputs": [ 1 ],
66 "operators": [
67 {
68 "opcode_index": 0,
69 "inputs": [ 0, 2 ],
70 "outputs": [ 1 ],
71 "custom_options_format": "FLEXBUFFERS"
72 }
73 ],
74 } ],
75 "buffers" : [
76 { },
77 { },
78 { "data": )" + padListData + R"(, },
79 ]
80 }
81 )";
82 SetupSingleInputSingleOutput("inputTensor", "outputTensor");
83 }
84};
85
86struct SimplePadFixture : public PadFixture
87{
88 SimplePadFixture() : PadFixture("[ 2, 3 ]", "[ 4, 7 ]", "[ 2, 2 ]",
89 "[ 1,0,0,0, 1,0,0,0, 2,0,0,0, 2,0,0,0 ]") {}
90};
91
Sadik Armagan1625efc2021-06-10 18:24:34 +010092TEST_CASE_FIXTURE(SimplePadFixture, "ParsePad")
Bruno Goncalves6c2355b2018-12-19 12:52:01 -020093{
Nattapat Chaimanowong649dd952019-01-22 16:10:44 +000094 RunTest<2, armnn::DataType::Float32>
95 (0,
96 {{ "inputTensor", { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f }}},
97 {{ "outputTensor", { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f,
98 0.0f, 0.0f, 1.0f, 2.0f, 3.0f, 0.0f, 0.0f,
99 0.0f, 0.0f, 4.0f, 5.0f, 6.0f, 0.0f, 0.0f,
100 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f }}});
Bruno Goncalves6c2355b2018-12-19 12:52:01 -0200101}
102
Narumol Prangnawarat8719d222020-11-27 16:57:56 +0000103struct Uint8PadFixture : public PadFixture
104{
105 Uint8PadFixture() : PadFixture("[ 2, 3 ]", "[ 4, 7 ]", "[ 2, 2 ]",
106 "[ 1,0,0,0, 1,0,0,0, 2,0,0,0, 2,0,0,0 ]",
107 "UINT8", "-2.0", "3") {}
108};
109
Sadik Armagan1625efc2021-06-10 18:24:34 +0100110TEST_CASE_FIXTURE(Uint8PadFixture, "ParsePadUint8")
Narumol Prangnawarat8719d222020-11-27 16:57:56 +0000111{
112 RunTest<2, armnn::DataType::QAsymmU8>
113 (0,
114 {{ "inputTensor", { 1, 2, 3, 4, 5, 6 }}},
115 {{ "outputTensor", { 3, 3, 3, 3, 3, 3, 3,
116 3, 3, 1, 2, 3, 3, 3,
117 3, 3, 4, 5, 6, 3, 3,
118 3, 3, 3, 3, 3, 3, 3 }}});
119}
120
121struct Int8PadFixture : public PadFixture
122{
123 Int8PadFixture() : PadFixture("[ 2, 3 ]", "[ 4, 7 ]", "[ 2, 2 ]",
124 "[ 1,0,0,0, 1,0,0,0, 2,0,0,0, 2,0,0,0 ]",
125 "INT8", "-2.0", "3") {}
126};
127
Sadik Armagan1625efc2021-06-10 18:24:34 +0100128TEST_CASE_FIXTURE(Int8PadFixture, "ParsePadInt8")
Narumol Prangnawarat8719d222020-11-27 16:57:56 +0000129{
130 RunTest<2, armnn::DataType::QAsymmS8>
131 (0,
132 {{ "inputTensor", { 1, -2, 3, 4, 5, -6 }}},
133 {{ "outputTensor", { 3, 3, 3, 3, 3, 3, 3,
134 3, 3, 1, -2, 3, 3, 3,
135 3, 3, 4, 5, -6, 3, 3,
136 3, 3, 3, 3, 3, 3, 3 }}});
137}
138
Sadik Armagan1625efc2021-06-10 18:24:34 +0100139}