blob: 06bf7806cc0968a0f476932a36f17a80938a5cf0 [file] [log] [blame]
Nattapat Chaimanowongb66504b2018-10-17 15:19:14 +01001//
2// Copyright © 2017 Arm Ltd. All rights reserved.
3// SPDX-License-Identifier: MIT
4//
5#include <boost/test/unit_test.hpp>
6#include "armnnTfLiteParser/ITfLiteParser.hpp"
7#include "ParserFlatbuffersFixture.hpp"
8
9BOOST_AUTO_TEST_SUITE(TensorflowLiteParser)
10
11struct MaxPool2DFixture : public ParserFlatbuffersFixture
12{
13 explicit MaxPool2DFixture(std::string inputdim, std::string outputdim, std::string dataType)
14 {
15 m_JsonString = R"(
16 {
17 "version": 3,
18 "operator_codes": [ { "builtin_code": "MAX_POOL_2D" } ],
19 "subgraphs": [
20 {
21 "tensors": [
22 {
23 "shape": )"
24 + outputdim
25 + R"(,
26 "type": )"
27 + dataType
28 + R"(,
29 "buffer": 0,
30 "name": "OutputTensor",
31 "quantization": {
32 "min": [ 0.0 ],
33 "max": [ 255.0 ],
34 "scale": [ 1.0 ],
35 "zero_point": [ 0 ]
36 }
37 },
38 {
39 "shape": )"
40 + inputdim
41 + R"(,
42 "type": )"
43 + dataType
44 + R"(,
45 "buffer": 1,
46 "name": "InputTensor",
47 "quantization": {
48 "min": [ 0.0 ],
49 "max": [ 255.0 ],
50 "scale": [ 1.0 ],
51 "zero_point": [ 0 ]
52 }
53 }
54 ],
55 "inputs": [ 1 ],
56 "outputs": [ 0 ],
57 "operators": [ {
58 "opcode_index": 0,
59 "inputs": [ 1 ],
60 "outputs": [ 0 ],
61 "builtin_options_type": "Pool2DOptions",
62 "builtin_options":
63 {
64 "padding": "VALID",
65 "stride_w": 2,
66 "stride_h": 2,
67 "filter_width": 2,
68 "filter_height": 2,
69 "fused_activation_function": "NONE"
70 },
71 "custom_options_format": "FLEXBUFFERS"
72 } ]
73 }
74 ],
75 "description": "MaxPool2D test.",
76 "buffers" : [ {}, {} ]
77 })";
78
79 SetupSingleInputSingleOutput("InputTensor", "OutputTensor");
80 }
81};
82
83
84struct MaxPoolLiteFixtureUint1DOutput : MaxPool2DFixture
85{
86 MaxPoolLiteFixtureUint1DOutput() : MaxPool2DFixture("[ 1, 2, 2, 1 ]", "[ 1, 1, 1, 1 ]", "UINT8") {}
87};
88
89struct MaxPoolLiteFixtureFloat1DOutput : MaxPool2DFixture
90{
91 MaxPoolLiteFixtureFloat1DOutput() : MaxPool2DFixture("[ 1, 2, 2, 1 ]", "[ 1, 1, 1, 1 ]", "FLOAT32") {}
92};
93
94struct MaxPoolLiteFixtureUint2DOutput : MaxPool2DFixture
95{
96 MaxPoolLiteFixtureUint2DOutput() : MaxPool2DFixture("[ 1, 4, 4, 1 ]", "[ 1, 2, 2, 1 ]", "UINT8") {}
97};
98
99BOOST_FIXTURE_TEST_CASE(MaxPoolLiteUint1DOutput, MaxPoolLiteFixtureUint1DOutput)
100{
101 RunTest<4, uint8_t>(0, { 2, 3, 5, 2 }, { 5 });
102}
103
104BOOST_FIXTURE_TEST_CASE(MaxPoolLiteFloat1DOutput, MaxPoolLiteFixtureFloat1DOutput)
105{
106 RunTest<4, float>(0, { 2.0f, 3.0f, 5.0f, 2.0f }, { 5.0f });
107}
108
109BOOST_FIXTURE_TEST_CASE(MaxPoolLiteUint2DOutput, MaxPoolLiteFixtureUint2DOutput)
110{
111 RunTest<4, uint8_t>(0, { 1, 2, 2, 3, 5, 6, 7, 8, 3, 2, 1, 0, 1, 2, 3, 4 }, { 6, 8, 3, 4 });
112}
113
114BOOST_FIXTURE_TEST_CASE(MaxPoolIncorrectDataTypeError, MaxPoolLiteFixtureFloat1DOutput)
115{
116 BOOST_CHECK_THROW((RunTest<4, uint8_t>(0, { 2, 3, 5, 2 }, { 5 })), armnn::Exception);
117}
118
119BOOST_AUTO_TEST_SUITE_END()