blob: 1c6fe9c8dbe17afcd4e5904226673e13cb6b30d2 [file] [log] [blame]
Saoirse Stewart3166c3e2019-02-18 15:24:53 +00001//
2// Copyright © 2017 Arm Ltd. All rights reserved.
3// SPDX-License-Identifier: MIT
4//
5
Saoirse Stewart3166c3e2019-02-18 15:24:53 +00006#include "ParserFlatbuffersSerializeFixture.hpp"
Finn Williams85d36712021-01-26 22:30:06 +00007#include <armnnDeserializer/IDeserializer.hpp>
Saoirse Stewart3166c3e2019-02-18 15:24:53 +00008
9#include <string>
Saoirse Stewart3166c3e2019-02-18 15:24:53 +000010
Sadik Armagan1625efc2021-06-10 18:24:34 +010011TEST_SUITE("Deserializer_Pooling2d")
12{
Saoirse Stewart3166c3e2019-02-18 15:24:53 +000013struct Pooling2dFixture : public ParserFlatbuffersSerializeFixture
14{
15 explicit Pooling2dFixture(const std::string &inputShape,
16 const std::string &outputShape,
17 const std::string &dataType,
18 const std::string &dataLayout,
19 const std::string &poolingAlgorithm)
20 {
21 m_JsonString = R"(
22 {
23 inputIds: [0],
24 outputIds: [2],
25 layers: [
26 {
27 layer_type: "InputLayer",
28 layer: {
29 base: {
30 layerBindingId: 0,
31 base: {
32 index: 0,
33 layerName: "InputLayer",
34 layerType: "Input",
35 inputSlots: [{
36 index: 0,
37 connection: {sourceLayerIndex:0, outputSlotIndex:0 },
38 }],
39 outputSlots: [ {
40 index: 0,
41 tensorInfo: {
42 dimensions: )" + inputShape + R"(,
43 dataType: )" + dataType + R"(
44 }}]
45 }
46 }}},
47 {
48 layer_type: "Pooling2dLayer",
49 layer: {
50 base: {
51 index: 1,
52 layerName: "Pooling2dLayer",
53 layerType: "Pooling2d",
54 inputSlots: [{
55 index: 0,
56 connection: {sourceLayerIndex:0, outputSlotIndex:0 },
57 }],
58 outputSlots: [ {
59 index: 0,
60 tensorInfo: {
61 dimensions: )" + outputShape + R"(,
62 dataType: )" + dataType + R"(
63
64 }}]},
65 descriptor: {
66 poolType: )" + poolingAlgorithm + R"(,
67 outputShapeRounding: "Floor",
68 paddingMethod: Exclude,
69 dataLayout: )" + dataLayout + R"(,
70 padLeft: 0,
71 padRight: 0,
72 padTop: 0,
73 padBottom: 0,
74 poolWidth: 2,
75 poolHeight: 2,
76 strideX: 2,
77 strideY: 2
78 }
79 }},
80 {
81 layer_type: "OutputLayer",
82 layer: {
83 base:{
84 layerBindingId: 0,
85 base: {
86 index: 2,
87 layerName: "OutputLayer",
88 layerType: "Output",
89 inputSlots: [{
90 index: 0,
91 connection: {sourceLayerIndex:1, outputSlotIndex:0 },
92 }],
93 outputSlots: [ {
94 index: 0,
95 tensorInfo: {
96 dimensions: )" + outputShape + R"(,
97 dataType: )" + dataType + R"(
98 },
99 }],
100 }}},
101 }]
102 }
103 )";
104 SetupSingleInputSingleOutput("InputLayer", "OutputLayer");
105 }
106};
107
ruoyan0123e1de62019-02-20 13:53:22 +0000108struct SimpleAvgPooling2dFixture : Pooling2dFixture
Saoirse Stewart3166c3e2019-02-18 15:24:53 +0000109{
Teresa Charlin4c600de2021-03-11 21:59:43 +0000110 SimpleAvgPooling2dFixture() : Pooling2dFixture("[ 1, 2, 2, 1 ]",
111 "[ 1, 1, 1, 1 ]",
ruoyan0123e1de62019-02-20 13:53:22 +0000112 "Float32", "NHWC", "Average") {}
Saoirse Stewart3166c3e2019-02-18 15:24:53 +0000113};
114
ruoyan0123e1de62019-02-20 13:53:22 +0000115struct SimpleAvgPooling2dFixture2 : Pooling2dFixture
Saoirse Stewart3166c3e2019-02-18 15:24:53 +0000116{
ruoyan0123e1de62019-02-20 13:53:22 +0000117 SimpleAvgPooling2dFixture2() : Pooling2dFixture("[ 1, 2, 2, 1 ]",
118 "[ 1, 1, 1, 1 ]",
119 "QuantisedAsymm8", "NHWC", "Average") {}
Saoirse Stewart3166c3e2019-02-18 15:24:53 +0000120};
121
ruoyan0123e1de62019-02-20 13:53:22 +0000122struct SimpleMaxPooling2dFixture : Pooling2dFixture
Saoirse Stewart3166c3e2019-02-18 15:24:53 +0000123{
ruoyan0123e1de62019-02-20 13:53:22 +0000124 SimpleMaxPooling2dFixture() : Pooling2dFixture("[ 1, 1, 2, 2 ]",
125 "[ 1, 1, 1, 1 ]",
126 "Float32", "NCHW", "Max") {}
Saoirse Stewart3166c3e2019-02-18 15:24:53 +0000127};
128
ruoyan0123e1de62019-02-20 13:53:22 +0000129struct SimpleMaxPooling2dFixture2 : Pooling2dFixture
Saoirse Stewart3166c3e2019-02-18 15:24:53 +0000130{
ruoyan0123e1de62019-02-20 13:53:22 +0000131 SimpleMaxPooling2dFixture2() : Pooling2dFixture("[ 1, 1, 2, 2 ]",
132 "[ 1, 1, 1, 1 ]",
133 "QuantisedAsymm8", "NCHW", "Max") {}
Saoirse Stewart3166c3e2019-02-18 15:24:53 +0000134};
135
Teresa Charlin4c600de2021-03-11 21:59:43 +0000136struct SimpleL2Pooling2dFixture : Pooling2dFixture
137{
138 SimpleL2Pooling2dFixture() : Pooling2dFixture("[ 1, 2, 2, 1 ]",
139 "[ 1, 1, 1, 1 ]",
140 "Float32", "NHWC", "L2") {}
141};
142
Sadik Armagan1625efc2021-06-10 18:24:34 +0100143TEST_CASE_FIXTURE(SimpleAvgPooling2dFixture, "Pooling2dFloat32Avg")
Saoirse Stewart3166c3e2019-02-18 15:24:53 +0000144{
145 RunTest<4, armnn::DataType::Float32>(0, { 2, 3, 5, 2 }, { 3 });
146}
147
Sadik Armagan1625efc2021-06-10 18:24:34 +0100148TEST_CASE_FIXTURE(SimpleAvgPooling2dFixture2, "Pooling2dQuantisedAsymm8Avg")
Saoirse Stewart3166c3e2019-02-18 15:24:53 +0000149{
Teresa Charlin4c600de2021-03-11 21:59:43 +0000150 RunTest<4, armnn::DataType::QAsymmU8>(0,{ 20, 40, 60, 80 },{ 50 });
Saoirse Stewart3166c3e2019-02-18 15:24:53 +0000151}
152
Sadik Armagan1625efc2021-06-10 18:24:34 +0100153TEST_CASE_FIXTURE(SimpleMaxPooling2dFixture, "Pooling2dFloat32Max")
Saoirse Stewart3166c3e2019-02-18 15:24:53 +0000154{
155 RunTest<4, armnn::DataType::Float32>(0, { 2, 5, 5, 2 }, { 5 });
156}
157
Sadik Armagan1625efc2021-06-10 18:24:34 +0100158TEST_CASE_FIXTURE(SimpleMaxPooling2dFixture2, "Pooling2dQuantisedAsymm8Max")
Saoirse Stewart3166c3e2019-02-18 15:24:53 +0000159{
Teresa Charlin4c600de2021-03-11 21:59:43 +0000160 RunTest<4, armnn::DataType::QAsymmU8>(0,{ 20, 40, 60, 80 },{ 80 });
161}
162
Sadik Armagan1625efc2021-06-10 18:24:34 +0100163TEST_CASE_FIXTURE(SimpleL2Pooling2dFixture, "Pooling2dFloat32L2")
Teresa Charlin4c600de2021-03-11 21:59:43 +0000164{
165 RunTest<4, armnn::DataType::Float32>(0, { 2, 3, 5, 2 }, { 3.2403703f });
Saoirse Stewart3166c3e2019-02-18 15:24:53 +0000166}
167
Sadik Armagan1625efc2021-06-10 18:24:34 +0100168}
Saoirse Stewart3166c3e2019-02-18 15:24:53 +0000169