blob: 1ac06277f8c4035aaae0778a096b7845035349f5 [file] [log] [blame]
Bruno Goncalves6c2355b2018-12-19 12:52:01 -02001//
2// Copyright © 2017 Arm Ltd. All rights reserved.
3// SPDX-License-Identifier: MIT
4//
5
Bruno Goncalves6c2355b2018-12-19 12:52:01 -02006#include "ParserFlatbuffersFixture.hpp"
7#include "../TfLiteParser.hpp"
8
9#include <string>
10#include <iostream>
11
Sadik Armagan1625efc2021-06-10 18:24:34 +010012TEST_SUITE("TensorflowLiteParser_Pad")
13{
Bruno Goncalves6c2355b2018-12-19 12:52:01 -020014struct PadFixture : public ParserFlatbuffersFixture
15{
Narumol Prangnawarat8719d222020-11-27 16:57:56 +000016 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 Goncalves6c2355b2018-12-19 12:52:01 -020023 {
24 m_JsonString = R"(
25 {
26 "version": 3,
27 "operator_codes": [ { "builtin_code": "PAD" } ],
28 "subgraphs": [ {
29 "tensors": [
30 {
31 "shape": )" + inputShape + R"(,
Narumol Prangnawarat8719d222020-11-27 16:57:56 +000032 "type": )" + dataType + R"(,
Bruno Goncalves6c2355b2018-12-19 12:52:01 -020033 "buffer": 0,
34 "name": "inputTensor",
35 "quantization": {
36 "min": [ 0.0 ],
37 "max": [ 255.0 ],
Narumol Prangnawarat8719d222020-11-27 16:57:56 +000038 "scale": [ )" + scale + R"( ],
39 "zero_point": [ )" + offset + R"( ],
Bruno Goncalves6c2355b2018-12-19 12:52:01 -020040 }
41 },
42 {
43 "shape": )" + outputShape + R"(,
Narumol Prangnawarat8719d222020-11-27 16:57:56 +000044 "type": )" + dataType + R"(,
Bruno Goncalves6c2355b2018-12-19 12:52:01 -020045 "buffer": 1,
46 "name": "outputTensor",
47 "quantization": {
48 "min": [ 0.0 ],
49 "max": [ 255.0 ],
Narumol Prangnawarat8719d222020-11-27 16:57:56 +000050 "scale": [ )" + scale + R"( ],
51 "zero_point": [ )" + offset + R"( ],
Bruno Goncalves6c2355b2018-12-19 12:52:01 -020052 }
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
89struct 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 Armagan1625efc2021-06-10 18:24:34 +010095TEST_CASE_FIXTURE(SimplePadFixture, "ParsePad")
Bruno Goncalves6c2355b2018-12-19 12:52:01 -020096{
Nattapat Chaimanowong649dd952019-01-22 16:10:44 +000097 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 Goncalves6c2355b2018-12-19 12:52:01 -0200104}
105
Narumol Prangnawarat8719d222020-11-27 16:57:56 +0000106struct 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 Armagan1625efc2021-06-10 18:24:34 +0100113TEST_CASE_FIXTURE(Uint8PadFixture, "ParsePadUint8")
Narumol Prangnawarat8719d222020-11-27 16:57:56 +0000114{
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
124struct 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 Armagan1625efc2021-06-10 18:24:34 +0100131TEST_CASE_FIXTURE(Int8PadFixture, "ParsePadInt8")
Narumol Prangnawarat8719d222020-11-27 16:57:56 +0000132{
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 Armagan1625efc2021-06-10 18:24:34 +0100142}