blob: fdab4da296f3457209ff7c5b81b3b53ec7e74d37 [file] [log] [blame]
telsoa01c577f2c2018-08-31 09:22:23 +01001//
2// Copyright © 2017 Arm Ltd. All rights reserved.
David Beckecb56cd2018-09-05 12:52:57 +01003// SPDX-License-Identifier: MIT
telsoa01c577f2c2018-08-31 09:22:23 +01004//
telsoa01c577f2c2018-08-31 09:22:23 +01005#include "armnnTfLiteParser/ITfLiteParser.hpp"
6#include "ParserFlatbuffersFixture.hpp"
7
Sadik Armagan1625efc2021-06-10 18:24:34 +01008TEST_SUITE("TensorflowLiteParser_AvgPool2D")
9{
telsoa01c577f2c2018-08-31 09:22:23 +010010struct AvgPool2DFixture : public ParserFlatbuffersFixture
11{
12 explicit AvgPool2DFixture(std::string inputdim, std::string outputdim, std::string dataType)
13 {
14 m_JsonString = R"(
15 {
16 "version": 3,
17 "operator_codes": [ { "builtin_code": "AVERAGE_POOL_2D" } ],
18 "subgraphs": [
19 {
20 "tensors": [
21 {
22 "shape": )"
23 + outputdim
24 + R"(,
25 "type": )"
26 + dataType
27 + R"(,
28 "buffer": 0,
29 "name": "OutputTensor",
30 "quantization": {
31 "min": [ 0.0 ],
32 "max": [ 255.0 ],
33 "scale": [ 1.0 ],
34 "zero_point": [ 0 ]
35 }
36 },
37 {
38 "shape": )"
39 + inputdim
40 + R"(,
41 "type": )"
42 + dataType
43 + R"(,
44 "buffer": 1,
45 "name": "InputTensor",
46 "quantization": {
47 "min": [ 0.0 ],
48 "max": [ 255.0 ],
49 "scale": [ 1.0 ],
50 "zero_point": [ 0 ]
51 }
52 }
53 ],
54 "inputs": [ 1 ],
55 "outputs": [ 0 ],
56 "operators": [ {
57 "opcode_index": 0,
58 "inputs": [ 1 ],
59 "outputs": [ 0 ],
60 "builtin_options_type": "Pool2DOptions",
61 "builtin_options":
62 {
63 "padding": "VALID",
64 "stride_w": 2,
65 "stride_h": 2,
66 "filter_width": 2,
67 "filter_height": 2,
68 "fused_activation_function": "NONE"
69 },
70 "custom_options_format": "FLEXBUFFERS"
71 } ]
72 }
73 ],
74 "description": "AvgPool2D test.",
75 "buffers" : [ {}, {} ]
76 })";
77
78 SetupSingleInputSingleOutput("InputTensor", "OutputTensor");
79 }
80};
81
82
83struct AvgPoolLiteFixtureUint1DOutput : AvgPool2DFixture
84{
85 AvgPoolLiteFixtureUint1DOutput() : AvgPool2DFixture("[ 1, 2, 2, 1 ]", "[ 1, 1, 1, 1 ]", "UINT8") {}
86};
87
88struct AvgPoolLiteFixtureFloat1DOutput : AvgPool2DFixture
89{
90 AvgPoolLiteFixtureFloat1DOutput() : AvgPool2DFixture("[ 1, 2, 2, 1 ]", "[ 1, 1, 1, 1 ]", "FLOAT32") {}
91};
92
93struct AvgPoolLiteFixture2DOutput : AvgPool2DFixture
94{
95 AvgPoolLiteFixture2DOutput() : AvgPool2DFixture("[ 1, 4, 4, 1 ]", "[ 1, 2, 2, 1 ]", "UINT8") {}
96};
97
Sadik Armagan1625efc2021-06-10 18:24:34 +010098TEST_CASE_FIXTURE(AvgPoolLiteFixtureUint1DOutput, "AvgPoolLite1DOutput")
telsoa01c577f2c2018-08-31 09:22:23 +010099{
Derek Lambertif90c56d2020-01-10 17:14:08 +0000100 RunTest<4, armnn::DataType::QAsymmU8>(0, {2, 3, 5, 2 }, { 3 });
telsoa01c577f2c2018-08-31 09:22:23 +0100101}
102
Sadik Armagan1625efc2021-06-10 18:24:34 +0100103TEST_CASE_FIXTURE(AvgPoolLiteFixtureFloat1DOutput, "AvgPoolLiteFloat1DOutput")
telsoa01c577f2c2018-08-31 09:22:23 +0100104{
Nattapat Chaimanowong649dd952019-01-22 16:10:44 +0000105 RunTest<4, armnn::DataType::Float32>(0, { 2.0f, 3.0f, 5.0f, 2.0f }, { 3.0f });
telsoa01c577f2c2018-08-31 09:22:23 +0100106}
107
Sadik Armagan1625efc2021-06-10 18:24:34 +0100108TEST_CASE_FIXTURE(AvgPoolLiteFixture2DOutput, "AvgPoolLite2DOutput")
telsoa01c577f2c2018-08-31 09:22:23 +0100109{
Derek Lambertif90c56d2020-01-10 17:14:08 +0000110 RunTest<4, armnn::DataType::QAsymmU8>(
Nattapat Chaimanowong649dd952019-01-22 16:10:44 +0000111 0, { 1, 2, 2, 3, 5, 6, 7, 8, 3, 2, 1, 0, 1, 2, 3, 4 }, { 4, 5, 2, 2 });
telsoa01c577f2c2018-08-31 09:22:23 +0100112}
113
Sadik Armagan1625efc2021-06-10 18:24:34 +0100114TEST_CASE_FIXTURE(AvgPoolLiteFixtureFloat1DOutput, "IncorrectDataTypeError")
telsoa01c577f2c2018-08-31 09:22:23 +0100115{
Sadik Armagan1625efc2021-06-10 18:24:34 +0100116 CHECK_THROWS_AS((RunTest<4, armnn::DataType::QAsymmU8>(0, {2, 3, 5, 2 }, { 3 })), armnn::Exception);
telsoa01c577f2c2018-08-31 09:22:23 +0100117}
118
Sadik Armagan1625efc2021-06-10 18:24:34 +0100119}