• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
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 
9 BOOST_AUTO_TEST_SUITE(TensorflowLiteParser)
10 
11 struct MaxPool2DFixture : public ParserFlatbuffersFixture
12 {
MaxPool2DFixtureMaxPool2DFixture13     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 
84 struct MaxPoolLiteFixtureUint1DOutput : MaxPool2DFixture
85 {
MaxPoolLiteFixtureUint1DOutputMaxPoolLiteFixtureUint1DOutput86     MaxPoolLiteFixtureUint1DOutput() : MaxPool2DFixture("[ 1, 2, 2, 1 ]", "[ 1, 1, 1, 1 ]", "UINT8") {}
87 };
88 
89 struct MaxPoolLiteFixtureFloat1DOutput : MaxPool2DFixture
90 {
MaxPoolLiteFixtureFloat1DOutputMaxPoolLiteFixtureFloat1DOutput91     MaxPoolLiteFixtureFloat1DOutput() : MaxPool2DFixture("[ 1, 2, 2, 1 ]", "[ 1, 1, 1, 1 ]", "FLOAT32") {}
92 };
93 
94 struct MaxPoolLiteFixtureUint2DOutput : MaxPool2DFixture
95 {
MaxPoolLiteFixtureUint2DOutputMaxPoolLiteFixtureUint2DOutput96     MaxPoolLiteFixtureUint2DOutput() : MaxPool2DFixture("[ 1, 4, 4, 1 ]", "[ 1, 2, 2, 1 ]", "UINT8") {}
97 };
98 
BOOST_FIXTURE_TEST_CASE(MaxPoolLiteUint1DOutput,MaxPoolLiteFixtureUint1DOutput)99 BOOST_FIXTURE_TEST_CASE(MaxPoolLiteUint1DOutput, MaxPoolLiteFixtureUint1DOutput)
100 {
101     RunTest<4, armnn::DataType::QAsymmU8>(0, { 2, 3, 5, 2 }, { 5 });
102 }
103 
BOOST_FIXTURE_TEST_CASE(MaxPoolLiteFloat1DOutput,MaxPoolLiteFixtureFloat1DOutput)104 BOOST_FIXTURE_TEST_CASE(MaxPoolLiteFloat1DOutput, MaxPoolLiteFixtureFloat1DOutput)
105 {
106     RunTest<4, armnn::DataType::Float32>(0, { 2.0f, 3.0f, 5.0f, 2.0f },  { 5.0f });
107 }
108 
BOOST_FIXTURE_TEST_CASE(MaxPoolLiteUint2DOutput,MaxPoolLiteFixtureUint2DOutput)109 BOOST_FIXTURE_TEST_CASE(MaxPoolLiteUint2DOutput, MaxPoolLiteFixtureUint2DOutput)
110 {
111     RunTest<4, armnn::DataType::QAsymmU8>(
112         0, { 1, 2, 2, 3, 5, 6, 7, 8, 3, 2, 1, 0, 1, 2, 3, 4 }, { 6, 8, 3, 4 });
113 }
114 
BOOST_FIXTURE_TEST_CASE(MaxPoolIncorrectDataTypeError,MaxPoolLiteFixtureFloat1DOutput)115 BOOST_FIXTURE_TEST_CASE(MaxPoolIncorrectDataTypeError, MaxPoolLiteFixtureFloat1DOutput)
116 {
117     BOOST_CHECK_THROW((RunTest<4, armnn::DataType::QAsymmU8>(0, { 2, 3, 5, 2 }, { 5 })), armnn::Exception);
118 }
119 
120 BOOST_AUTO_TEST_SUITE_END()
121