blob: 561a0473f28bf0bd54f9a6d5ea0c6058deb6debb [file] [log] [blame]
telsoa01c577f2c2018-08-31 09:22:23 +01001//
Finn Williamsb49ed182021-06-29 15:50:08 +01002// Copyright © 2017 Arm Ltd and Contributors. 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 "ParserFlatbuffersFixture.hpp"
6
Sadik Armagan1625efc2021-06-10 18:24:34 +01007TEST_SUITE("TensorflowLiteParser_AvgPool2D")
8{
telsoa01c577f2c2018-08-31 09:22:23 +01009struct AvgPool2DFixture : public ParserFlatbuffersFixture
10{
11 explicit AvgPool2DFixture(std::string inputdim, std::string outputdim, std::string dataType)
12 {
13 m_JsonString = R"(
14 {
15 "version": 3,
16 "operator_codes": [ { "builtin_code": "AVERAGE_POOL_2D" } ],
17 "subgraphs": [
18 {
19 "tensors": [
20 {
21 "shape": )"
22 + outputdim
23 + R"(,
24 "type": )"
25 + dataType
26 + R"(,
27 "buffer": 0,
28 "name": "OutputTensor",
29 "quantization": {
30 "min": [ 0.0 ],
31 "max": [ 255.0 ],
32 "scale": [ 1.0 ],
33 "zero_point": [ 0 ]
34 }
35 },
36 {
37 "shape": )"
38 + inputdim
39 + R"(,
40 "type": )"
41 + dataType
42 + R"(,
43 "buffer": 1,
44 "name": "InputTensor",
45 "quantization": {
46 "min": [ 0.0 ],
47 "max": [ 255.0 ],
48 "scale": [ 1.0 ],
49 "zero_point": [ 0 ]
50 }
51 }
52 ],
53 "inputs": [ 1 ],
54 "outputs": [ 0 ],
55 "operators": [ {
56 "opcode_index": 0,
57 "inputs": [ 1 ],
58 "outputs": [ 0 ],
59 "builtin_options_type": "Pool2DOptions",
60 "builtin_options":
61 {
62 "padding": "VALID",
63 "stride_w": 2,
64 "stride_h": 2,
65 "filter_width": 2,
66 "filter_height": 2,
67 "fused_activation_function": "NONE"
68 },
69 "custom_options_format": "FLEXBUFFERS"
70 } ]
71 }
72 ],
73 "description": "AvgPool2D test.",
74 "buffers" : [ {}, {} ]
75 })";
76
77 SetupSingleInputSingleOutput("InputTensor", "OutputTensor");
78 }
79};
80
81
82struct AvgPoolLiteFixtureUint1DOutput : AvgPool2DFixture
83{
84 AvgPoolLiteFixtureUint1DOutput() : AvgPool2DFixture("[ 1, 2, 2, 1 ]", "[ 1, 1, 1, 1 ]", "UINT8") {}
85};
86
87struct AvgPoolLiteFixtureFloat1DOutput : AvgPool2DFixture
88{
89 AvgPoolLiteFixtureFloat1DOutput() : AvgPool2DFixture("[ 1, 2, 2, 1 ]", "[ 1, 1, 1, 1 ]", "FLOAT32") {}
90};
91
92struct AvgPoolLiteFixture2DOutput : AvgPool2DFixture
93{
94 AvgPoolLiteFixture2DOutput() : AvgPool2DFixture("[ 1, 4, 4, 1 ]", "[ 1, 2, 2, 1 ]", "UINT8") {}
95};
96
Sadik Armagan1625efc2021-06-10 18:24:34 +010097TEST_CASE_FIXTURE(AvgPoolLiteFixtureUint1DOutput, "AvgPoolLite1DOutput")
telsoa01c577f2c2018-08-31 09:22:23 +010098{
Derek Lambertif90c56d2020-01-10 17:14:08 +000099 RunTest<4, armnn::DataType::QAsymmU8>(0, {2, 3, 5, 2 }, { 3 });
telsoa01c577f2c2018-08-31 09:22:23 +0100100}
101
Sadik Armagan1625efc2021-06-10 18:24:34 +0100102TEST_CASE_FIXTURE(AvgPoolLiteFixtureFloat1DOutput, "AvgPoolLiteFloat1DOutput")
telsoa01c577f2c2018-08-31 09:22:23 +0100103{
Nattapat Chaimanowong649dd952019-01-22 16:10:44 +0000104 RunTest<4, armnn::DataType::Float32>(0, { 2.0f, 3.0f, 5.0f, 2.0f }, { 3.0f });
telsoa01c577f2c2018-08-31 09:22:23 +0100105}
106
Sadik Armagan1625efc2021-06-10 18:24:34 +0100107TEST_CASE_FIXTURE(AvgPoolLiteFixture2DOutput, "AvgPoolLite2DOutput")
telsoa01c577f2c2018-08-31 09:22:23 +0100108{
Derek Lambertif90c56d2020-01-10 17:14:08 +0000109 RunTest<4, armnn::DataType::QAsymmU8>(
Nattapat Chaimanowong649dd952019-01-22 16:10:44 +0000110 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 +0100111}
112
Sadik Armagan1625efc2021-06-10 18:24:34 +0100113TEST_CASE_FIXTURE(AvgPoolLiteFixtureFloat1DOutput, "IncorrectDataTypeError")
telsoa01c577f2c2018-08-31 09:22:23 +0100114{
Sadik Armagan1625efc2021-06-10 18:24:34 +0100115 CHECK_THROWS_AS((RunTest<4, armnn::DataType::QAsymmU8>(0, {2, 3, 5, 2 }, { 3 })), armnn::Exception);
telsoa01c577f2c2018-08-31 09:22:23 +0100116}
117
Sadik Armagan1625efc2021-06-10 18:24:34 +0100118}