forked from Tencent/ncnn
-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathtest_pooling.cpp
261 lines (242 loc) · 12.1 KB
/
test_pooling.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
// Tencent is pleased to support the open source community by making ncnn available.
//
// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved.
//
// Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
// in compliance with the License. You may obtain a copy of the License at
//
// https://opensource.org/licenses/BSD-3-Clause
//
// Unless required by applicable law or agreed to in writing, software distributed
// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
// CONDITIONS OF ANY KIND, either express or implied. See the License for the
// specific language governing permissions and limitations under the License.
#include "layer/pooling.h"
#include "testutil.h"
static int test_pooling(int w, int h, int c, int pooling_type, int kernel, int stride, int pad, int global_pooling, int pad_mode, int avgpool_count_include_pad, int adaptive_pooling, int out_h)
{
ncnn::Mat a = RandomMat(w, h, c);
ncnn::ParamDict pd;
pd.set(0, pooling_type); // pooling_type
pd.set(1, kernel); // kernel_w
pd.set(2, stride); // stride_w
pd.set(3, pad); // pad_w
pd.set(4, global_pooling); // global_pooling
pd.set(5, pad_mode); // pad_mode
pd.set(6, avgpool_count_include_pad); // avgpool_count_include_pad
pd.set(7, adaptive_pooling); // adaptive_pooling
pd.set(8, out_h); // out_h
std::vector<ncnn::Mat> weights(0);
int ret = test_layer<ncnn::Pooling>("Pooling", pd, weights, a);
if (ret != 0)
{
fprintf(stderr, "test_pooling failed w=%d h=%d c=%d pooling_type=%d kernel=%d stride=%d pad=%d global_pooling=%d pad_mode=%d avgpool_count_include_pad=%d adaptive_pooling=%d out_h=%d\n", w, h, c, pooling_type, kernel, stride, pad, global_pooling, pad_mode, avgpool_count_include_pad, adaptive_pooling, out_h);
}
return ret;
}
static int test_pooling_0()
{
static const int ksp[11][3] = {
{2, 1, 0},
{2, 2, 0},
{3, 1, 0},
{3, 2, 1},
{4, 1, 0},
{4, 2, 1},
{5, 1, 0},
{5, 2, 2},
{7, 1, 0},
{7, 2, 1},
{7, 3, 2},
};
for (int i = 0; i < 11; i++)
{
int ret = 0
|| test_pooling(9, 7, 1, 0, ksp[i][0], ksp[i][1], ksp[i][2], 0, 0, 0, 0, 0)
|| test_pooling(9, 7, 2, 0, ksp[i][0], ksp[i][1], ksp[i][2], 0, 1, 0, 0, 0)
|| test_pooling(9, 7, 3, 0, ksp[i][0], ksp[i][1], ksp[i][2], 0, 2, 0, 0, 0)
|| test_pooling(9, 7, 4, 0, ksp[i][0], ksp[i][1], ksp[i][2], 0, 3, 0, 0, 0)
|| test_pooling(9, 7, 7, 0, ksp[i][0], ksp[i][1], ksp[i][2], 0, 0, 0, 0, 0)
|| test_pooling(9, 7, 8, 0, ksp[i][0], ksp[i][1], ksp[i][2], 0, 1, 0, 0, 0)
|| test_pooling(9, 7, 15, 0, ksp[i][0], ksp[i][1], ksp[i][2], 0, 2, 0, 0, 0)
|| test_pooling(9, 7, 16, 0, ksp[i][0], ksp[i][1], ksp[i][2], 0, 3, 0, 0, 0);
if (ret != 0)
return -1;
}
return 0;
}
static int test_pooling_1()
{
static const int ksp[11][3] = {
{2, 1, 0},
{2, 2, 0},
{3, 1, 0},
{3, 2, 1},
{4, 1, 0},
{4, 2, 1},
{5, 1, 0},
{5, 2, 2},
{7, 1, 0},
{7, 2, 1},
{7, 3, 2},
};
for (int i = 0; i < 11; i++)
{
int ret = 0
|| test_pooling(9, 7, 1, 1, ksp[i][0], ksp[i][1], ksp[i][2], 0, 0, 0, 0, 0)
|| test_pooling(9, 7, 2, 1, ksp[i][0], ksp[i][1], ksp[i][2], 0, 1, 0, 0, 0)
|| test_pooling(9, 7, 3, 1, ksp[i][0], ksp[i][1], ksp[i][2], 0, 0, 1, 0, 0)
|| test_pooling(9, 7, 4, 1, ksp[i][0], ksp[i][1], ksp[i][2], 0, 1, 0, 0, 0)
|| test_pooling(9, 7, 7, 1, ksp[i][0], ksp[i][1], ksp[i][2], 0, 0, 0, 0, 0)
|| test_pooling(9, 7, 8, 1, ksp[i][0], ksp[i][1], ksp[i][2], 0, 1, 1, 0, 0)
|| test_pooling(9, 7, 15, 1, ksp[i][0], ksp[i][1], ksp[i][2], 0, 0, 0, 0, 0)
|| test_pooling(9, 7, 16, 1, ksp[i][0], ksp[i][1], ksp[i][2], 0, 1, 0, 0, 0);
if (ret != 0)
return -1;
}
return 0;
}
static int test_pooling_2()
{
return 0
|| test_pooling(2, 5, 1, 0, 1, 1, 0, 1, 0, 0, 0, 0)
|| test_pooling(5, 2, 1, 1, 1, 1, 0, 1, 0, 0, 0, 0)
|| test_pooling(3, 6, 3, 0, 1, 1, 0, 1, 0, 0, 0, 0)
|| test_pooling(6, 3, 3, 1, 1, 1, 0, 1, 0, 0, 0, 0)
|| test_pooling(4, 4, 4, 0, 1, 1, 0, 1, 0, 0, 0, 0)
|| test_pooling(6, 4, 4, 1, 1, 1, 0, 1, 0, 0, 0, 0)
|| test_pooling(8, 7, 8, 0, 1, 1, 0, 1, 0, 0, 0, 0)
|| test_pooling(7, 8, 8, 1, 1, 1, 0, 1, 0, 0, 0, 0)
|| test_pooling(11, 13, 16, 0, 1, 1, 0, 1, 0, 0, 0, 0)
|| test_pooling(13, 11, 16, 1, 1, 1, 0, 1, 0, 0, 0, 0)
|| test_pooling(48, 48, 4, 0, 2, 2, 0, 0, 0, 0, 0, 0)
|| test_pooling(48, 48, 15, 0, 2, 2, 1, 0, 0, 0, 0, 0);
}
// adaptive avg pool
static int test_pooling_3()
{
return 0
|| test_pooling(2, 5, 1, 1, 1, 1, 0, 1, 0, 0, 1, 1)
|| test_pooling(2, 5, 1, 1, 1, 1, 0, 1, 0, 0, 1, 2)
|| test_pooling(2, 5, 1, 1, 1, 1, 0, 1, 0, 0, 1, 3)
|| test_pooling(2, 5, 1, 1, 1, 1, 0, 1, 0, 0, 1, 4)
|| test_pooling(2, 5, 1, 1, 1, 1, 0, 1, 0, 0, 1, 5)
|| test_pooling(2, 5, 1, 1, 1, 1, 0, 1, 0, 0, 1, 6)
|| test_pooling(5, 2, 1, 1, 1, 1, 0, 1, 0, 0, 1, 1)
|| test_pooling(5, 2, 1, 1, 1, 1, 0, 1, 0, 0, 1, 2)
|| test_pooling(5, 2, 1, 1, 1, 1, 0, 1, 0, 0, 1, 3)
|| test_pooling(5, 2, 1, 1, 1, 1, 0, 1, 0, 0, 1, 4)
|| test_pooling(5, 2, 1, 1, 1, 1, 0, 1, 0, 0, 1, 5)
|| test_pooling(5, 2, 1, 1, 1, 1, 0, 1, 0, 0, 1, 6)
|| test_pooling(3, 6, 3, 1, 1, 1, 0, 1, 0, 0, 1, 1)
|| test_pooling(3, 6, 3, 1, 1, 1, 0, 1, 0, 0, 1, 2)
|| test_pooling(3, 6, 3, 1, 1, 1, 0, 1, 0, 0, 1, 3)
|| test_pooling(3, 6, 3, 1, 1, 1, 0, 1, 0, 0, 1, 4)
|| test_pooling(3, 6, 3, 1, 1, 1, 0, 1, 0, 0, 1, 5)
|| test_pooling(3, 6, 3, 1, 1, 1, 0, 1, 0, 0, 1, 6)
|| test_pooling(4, 4, 4, 1, 1, 1, 0, 1, 0, 0, 1, 1)
|| test_pooling(4, 4, 4, 1, 1, 1, 0, 1, 0, 0, 1, 2)
|| test_pooling(4, 4, 4, 1, 1, 1, 0, 1, 0, 0, 1, 3)
|| test_pooling(4, 4, 4, 1, 1, 1, 0, 1, 0, 0, 1, 4)
|| test_pooling(4, 4, 4, 1, 1, 1, 0, 1, 0, 0, 1, 5)
|| test_pooling(4, 4, 4, 1, 1, 1, 0, 1, 0, 0, 1, 6)
|| test_pooling(4, 4, 4, 1, 1, 1, 0, 1, 0, 0, 1, 7)
|| test_pooling(4, 4, 4, 1, 1, 1, 0, 1, 0, 0, 1, 8)
|| test_pooling(6, 4, 4, 1, 1, 1, 0, 1, 0, 0, 1, 1)
|| test_pooling(6, 4, 4, 1, 1, 1, 0, 1, 0, 0, 1, 2)
|| test_pooling(6, 4, 4, 1, 1, 1, 0, 1, 0, 0, 1, 3)
|| test_pooling(6, 4, 4, 1, 1, 1, 0, 1, 0, 0, 1, 4)
|| test_pooling(6, 4, 4, 1, 1, 1, 0, 1, 0, 0, 1, 5)
|| test_pooling(6, 4, 4, 1, 1, 1, 0, 1, 0, 0, 1, 6)
|| test_pooling(8, 7, 8, 1, 1, 1, 0, 1, 0, 0, 1, 1)
|| test_pooling(8, 7, 8, 1, 1, 1, 0, 1, 0, 0, 1, 2)
|| test_pooling(8, 7, 8, 1, 1, 1, 0, 1, 0, 0, 1, 3)
|| test_pooling(8, 7, 8, 1, 1, 1, 0, 1, 0, 0, 1, 4)
|| test_pooling(8, 7, 8, 1, 1, 1, 0, 1, 0, 0, 1, 5)
|| test_pooling(8, 7, 8, 1, 1, 1, 0, 1, 0, 0, 1, 6)
|| test_pooling(8, 7, 8, 1, 1, 1, 0, 1, 0, 0, 1, 7)
|| test_pooling(8, 7, 8, 1, 1, 1, 0, 1, 0, 0, 1, 8)
|| test_pooling(8, 7, 8, 1, 1, 1, 0, 1, 0, 0, 1, 9)
|| test_pooling(11, 13, 16, 1, 1, 1, 0, 1, 0, 1, 0, 1)
|| test_pooling(11, 13, 16, 1, 1, 1, 0, 1, 0, 1, 0, 3)
|| test_pooling(11, 13, 16, 1, 1, 1, 0, 1, 0, 1, 0, 5)
|| test_pooling(11, 13, 16, 1, 1, 1, 0, 1, 0, 1, 0, 7)
|| test_pooling(11, 13, 16, 1, 1, 1, 0, 1, 0, 1, 0, 9)
|| test_pooling(11, 13, 16, 1, 1, 1, 0, 1, 0, 1, 0, 11)
|| test_pooling(11, 13, 16, 1, 1, 1, 0, 1, 0, 1, 0, 13)
|| test_pooling(13, 11, 16, 1, 1, 1, 0, 1, 0, 1, 0, 2)
|| test_pooling(13, 11, 16, 1, 1, 1, 0, 1, 0, 1, 0, 4)
|| test_pooling(13, 11, 16, 1, 1, 1, 0, 1, 0, 1, 0, 6)
|| test_pooling(13, 11, 16, 1, 1, 1, 0, 1, 0, 1, 0, 8)
|| test_pooling(13, 11, 16, 1, 1, 1, 0, 1, 0, 1, 0, 10)
|| test_pooling(13, 11, 16, 1, 1, 1, 0, 1, 0, 1, 0, 12);
}
// adaptive max pool
static int test_pooling_4()
{
return 0
|| test_pooling(2, 5, 1, 0, 1, 1, 0, 1, 0, 0, 1, 1)
|| test_pooling(2, 5, 1, 0, 1, 1, 0, 1, 0, 0, 1, 2)
|| test_pooling(2, 5, 1, 0, 1, 1, 0, 1, 0, 0, 1, 3)
|| test_pooling(2, 5, 1, 0, 1, 1, 0, 1, 0, 0, 1, 4)
|| test_pooling(2, 5, 1, 0, 1, 1, 0, 1, 0, 0, 1, 5)
|| test_pooling(2, 5, 1, 0, 1, 1, 0, 1, 0, 0, 1, 6)
|| test_pooling(5, 2, 1, 0, 1, 1, 0, 1, 0, 0, 1, 1)
|| test_pooling(5, 2, 1, 0, 1, 1, 0, 1, 0, 0, 1, 2)
|| test_pooling(5, 2, 1, 0, 1, 1, 0, 1, 0, 0, 1, 3)
|| test_pooling(5, 2, 1, 0, 1, 1, 0, 1, 0, 0, 1, 4)
|| test_pooling(5, 2, 1, 0, 1, 1, 0, 1, 0, 0, 1, 5)
|| test_pooling(5, 2, 1, 0, 1, 1, 0, 1, 0, 0, 1, 6)
|| test_pooling(3, 6, 3, 0, 1, 1, 0, 1, 0, 0, 1, 1)
|| test_pooling(3, 6, 3, 0, 1, 1, 0, 1, 0, 0, 1, 2)
|| test_pooling(3, 6, 3, 0, 1, 1, 0, 1, 0, 0, 1, 3)
|| test_pooling(3, 6, 3, 0, 1, 1, 0, 1, 0, 0, 1, 4)
|| test_pooling(3, 6, 3, 0, 1, 1, 0, 1, 0, 0, 1, 5)
|| test_pooling(3, 6, 3, 0, 1, 1, 0, 1, 0, 0, 1, 6)
|| test_pooling(4, 4, 4, 0, 1, 1, 0, 1, 0, 0, 1, 1)
|| test_pooling(4, 4, 4, 0, 1, 1, 0, 1, 0, 0, 1, 2)
|| test_pooling(4, 4, 4, 0, 1, 1, 0, 1, 0, 0, 1, 3)
|| test_pooling(4, 4, 4, 0, 1, 1, 0, 1, 0, 0, 1, 4)
|| test_pooling(4, 4, 4, 0, 1, 1, 0, 1, 0, 0, 1, 5)
|| test_pooling(4, 4, 4, 0, 1, 1, 0, 1, 0, 0, 1, 6)
|| test_pooling(4, 4, 4, 0, 1, 1, 0, 1, 0, 0, 1, 7)
|| test_pooling(4, 4, 4, 0, 1, 1, 0, 1, 0, 0, 1, 8)
|| test_pooling(6, 4, 4, 0, 1, 1, 0, 1, 0, 0, 1, 1)
|| test_pooling(6, 4, 4, 0, 1, 1, 0, 1, 0, 0, 1, 2)
|| test_pooling(6, 4, 4, 0, 1, 1, 0, 1, 0, 0, 1, 3)
|| test_pooling(6, 4, 4, 0, 1, 1, 0, 1, 0, 0, 1, 4)
|| test_pooling(6, 4, 4, 0, 1, 1, 0, 1, 0, 0, 1, 5)
|| test_pooling(6, 4, 4, 0, 1, 1, 0, 1, 0, 0, 1, 6)
|| test_pooling(8, 7, 8, 0, 1, 1, 0, 1, 0, 0, 1, 1)
|| test_pooling(8, 7, 8, 0, 1, 1, 0, 1, 0, 0, 1, 2)
|| test_pooling(8, 7, 8, 0, 1, 1, 0, 1, 0, 0, 1, 3)
|| test_pooling(8, 7, 8, 0, 1, 1, 0, 1, 0, 0, 1, 4)
|| test_pooling(8, 7, 8, 0, 1, 1, 0, 1, 0, 0, 1, 5)
|| test_pooling(8, 7, 8, 0, 1, 1, 0, 1, 0, 0, 1, 6)
|| test_pooling(8, 7, 8, 0, 1, 1, 0, 1, 0, 0, 1, 7)
|| test_pooling(8, 7, 8, 0, 1, 1, 0, 1, 0, 0, 1, 8)
|| test_pooling(8, 7, 8, 0, 1, 1, 0, 1, 0, 0, 1, 9)
|| test_pooling(11, 13, 16, 0, 1, 1, 0, 1, 0, 1, 0, 1)
|| test_pooling(11, 13, 16, 0, 1, 1, 0, 1, 0, 1, 0, 3)
|| test_pooling(11, 13, 16, 0, 1, 1, 0, 1, 0, 1, 0, 5)
|| test_pooling(11, 13, 16, 0, 1, 1, 0, 1, 0, 1, 0, 7)
|| test_pooling(11, 13, 16, 0, 1, 1, 0, 1, 0, 1, 0, 9)
|| test_pooling(11, 13, 16, 0, 1, 1, 0, 1, 0, 1, 0, 11)
|| test_pooling(11, 13, 16, 0, 1, 1, 0, 1, 0, 1, 0, 13)
|| test_pooling(13, 11, 16, 0, 1, 1, 0, 1, 0, 1, 0, 2)
|| test_pooling(13, 11, 16, 0, 1, 1, 0, 1, 0, 1, 0, 4)
|| test_pooling(13, 11, 16, 0, 1, 1, 0, 1, 0, 1, 0, 6)
|| test_pooling(13, 11, 16, 0, 1, 1, 0, 1, 0, 1, 0, 8)
|| test_pooling(13, 11, 16, 0, 1, 1, 0, 1, 0, 1, 0, 10)
|| test_pooling(13, 11, 16, 0, 1, 1, 0, 1, 0, 1, 0, 12);
}
int main()
{
SRAND(7767517);
return 0
|| test_pooling_0()
|| test_pooling_1()
|| test_pooling_2()
|| test_pooling_3()
|| test_pooling_4();
}