Elffuss BraidHub

kikocis/ncnn public

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