ncnn

Форк
0
/
test_pooling1d.cpp 
260 строк · 12.0 Кб
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

17
static int test_pooling1d(int w, int h, 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);
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("Pooling1D", pd, weights, a);
35
    if (ret != 0)
36
    {
37
        fprintf(stderr, "test_pooling1d failed w=%d h=%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, pooling_type, kernel, stride, pad, global_pooling, pad_mode, avgpool_count_include_pad, adaptive_pooling, out_w);
38
    }
39

40
    return ret;
41
}
42

43
static int test_pooling1d_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_pooling1d(9, 1, 0, ksp[i][0], ksp[i][1], ksp[i][2], 0, 0, 0, 0, 0)
63
                  || test_pooling1d(9, 2, 0, ksp[i][0], ksp[i][1], ksp[i][2], 0, 1, 0, 0, 0)
64
                  || test_pooling1d(9, 3, 0, ksp[i][0], ksp[i][1], ksp[i][2], 0, 2, 0, 0, 0)
65
                  || test_pooling1d(9, 4, 0, ksp[i][0], ksp[i][1], ksp[i][2], 0, 3, 0, 0, 0)
66
                  || test_pooling1d(9, 7, 0, ksp[i][0], ksp[i][1], ksp[i][2], 0, 0, 0, 0, 0)
67
                  || test_pooling1d(9, 8, 0, ksp[i][0], ksp[i][1], ksp[i][2], 0, 1, 0, 0, 0)
68
                  || test_pooling1d(9, 15, 0, ksp[i][0], ksp[i][1], ksp[i][2], 0, 2, 0, 0, 0)
69
                  || test_pooling1d(9, 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

78
static int test_pooling1d_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_pooling1d(9, 1, 1, ksp[i][0], ksp[i][1], ksp[i][2], 0, 0, 0, 0, 0)
98
                  || test_pooling1d(9, 2, 1, ksp[i][0], ksp[i][1], ksp[i][2], 0, 1, 0, 0, 0)
99
                  || test_pooling1d(9, 3, 1, ksp[i][0], ksp[i][1], ksp[i][2], 0, 0, 1, 0, 0)
100
                  || test_pooling1d(9, 4, 1, ksp[i][0], ksp[i][1], ksp[i][2], 0, 1, 0, 0, 0)
101
                  || test_pooling1d(9, 7, 1, ksp[i][0], ksp[i][1], ksp[i][2], 0, 0, 0, 0, 0)
102
                  || test_pooling1d(9, 8, 1, ksp[i][0], ksp[i][1], ksp[i][2], 0, 1, 1, 0, 0)
103
                  || test_pooling1d(9, 12, 1, ksp[i][0], ksp[i][1], ksp[i][2], 0, 2, 1, 0, 0)
104
                  || test_pooling1d(9, 15, 1, ksp[i][0], ksp[i][1], ksp[i][2], 0, 0, 0, 0, 0)
105
                  || test_pooling1d(9, 16, 1, ksp[i][0], ksp[i][1], ksp[i][2], 0, 1, 0, 0, 0)
106
                  || test_pooling1d(9, 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

115
static int test_pooling1d_2()
116
{
117
    return 0
118
           || test_pooling1d(2, 1, 0, 1, 1, 0, 1, 0, 0, 0, 0)
119
           || test_pooling1d(5, 1, 1, 1, 1, 0, 1, 0, 0, 0, 0)
120
           || test_pooling1d(3, 3, 0, 1, 1, 0, 1, 0, 0, 0, 0)
121
           || test_pooling1d(6, 3, 1, 1, 1, 0, 1, 0, 0, 0, 0)
122
           || test_pooling1d(4, 4, 0, 1, 1, 0, 1, 0, 0, 0, 0)
123
           || test_pooling1d(6, 4, 1, 1, 1, 0, 1, 0, 0, 0, 0)
124
           || test_pooling1d(8, 8, 0, 1, 1, 0, 1, 0, 0, 0, 0)
125
           || test_pooling1d(7, 8, 1, 1, 1, 0, 1, 0, 0, 0, 0)
126
           || test_pooling1d(11, 16, 0, 1, 1, 0, 1, 0, 0, 0, 0)
127
           || test_pooling1d(13, 16, 1, 1, 1, 0, 1, 0, 0, 0, 0)
128
           || test_pooling1d(48, 4, 0, 2, 2, 0, 0, 0, 0, 0, 0)
129
           || test_pooling1d(48, 15, 0, 2, 2, 1, 0, 0, 0, 0, 0);
130
}
131

132
// adaptive avg pool
133
static int test_pooling1d_3()
134
{
135
    return 0
136
           || test_pooling1d(2, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1)
137
           || test_pooling1d(2, 1, 1, 1, 1, 0, 0, 0, 0, 1, 2)
138
           || test_pooling1d(2, 1, 1, 1, 1, 0, 0, 0, 0, 1, 3)
139
           || test_pooling1d(2, 1, 1, 1, 1, 0, 0, 0, 0, 1, 4)
140
           || test_pooling1d(2, 1, 1, 1, 1, 0, 0, 0, 0, 1, 5)
141
           || test_pooling1d(2, 1, 1, 1, 1, 0, 0, 0, 0, 1, 6)
142
           || test_pooling1d(5, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1)
143
           || test_pooling1d(5, 1, 1, 1, 1, 0, 0, 0, 0, 1, 2)
144
           || test_pooling1d(5, 1, 1, 1, 1, 0, 0, 0, 0, 1, 3)
145
           || test_pooling1d(5, 1, 1, 1, 1, 0, 0, 0, 0, 1, 4)
146
           || test_pooling1d(5, 1, 1, 1, 1, 0, 0, 0, 0, 1, 5)
147
           || test_pooling1d(5, 1, 1, 1, 1, 0, 0, 0, 0, 1, 6)
148
           || test_pooling1d(3, 3, 1, 1, 1, 0, 0, 0, 0, 1, 1)
149
           || test_pooling1d(3, 3, 1, 1, 1, 0, 0, 0, 0, 1, 2)
150
           || test_pooling1d(3, 3, 1, 1, 1, 0, 0, 0, 0, 1, 3)
151
           || test_pooling1d(3, 3, 1, 1, 1, 0, 0, 0, 0, 1, 4)
152
           || test_pooling1d(3, 3, 1, 1, 1, 0, 0, 0, 0, 1, 5)
153
           || test_pooling1d(3, 3, 1, 1, 1, 0, 0, 0, 0, 1, 6)
154
           || test_pooling1d(4, 4, 1, 1, 1, 0, 0, 0, 0, 1, 1)
155
           || test_pooling1d(4, 4, 1, 1, 1, 0, 0, 0, 0, 1, 2)
156
           || test_pooling1d(4, 4, 1, 1, 1, 0, 0, 0, 0, 1, 3)
157
           || test_pooling1d(4, 4, 1, 1, 1, 0, 0, 0, 0, 1, 4)
158
           || test_pooling1d(4, 4, 1, 1, 1, 0, 0, 0, 0, 1, 5)
159
           || test_pooling1d(4, 4, 1, 1, 1, 0, 0, 0, 0, 1, 6)
160
           || test_pooling1d(4, 4, 1, 1, 1, 0, 0, 0, 0, 1, 7)
161
           || test_pooling1d(4, 4, 1, 1, 1, 0, 0, 0, 0, 1, 8)
162
           || test_pooling1d(6, 4, 1, 1, 1, 0, 0, 0, 0, 1, 1)
163
           || test_pooling1d(6, 4, 1, 1, 1, 0, 0, 0, 0, 1, 2)
164
           || test_pooling1d(6, 4, 1, 1, 1, 0, 0, 0, 0, 1, 3)
165
           || test_pooling1d(6, 4, 1, 1, 1, 0, 0, 0, 0, 1, 4)
166
           || test_pooling1d(6, 4, 1, 1, 1, 0, 0, 0, 0, 1, 5)
167
           || test_pooling1d(6, 4, 1, 1, 1, 0, 0, 0, 0, 1, 6)
168
           || test_pooling1d(8, 8, 1, 1, 1, 0, 0, 0, 0, 1, 1)
169
           || test_pooling1d(8, 8, 1, 1, 1, 0, 0, 0, 0, 1, 2)
170
           || test_pooling1d(8, 8, 1, 1, 1, 0, 0, 0, 0, 1, 3)
171
           || test_pooling1d(8, 8, 1, 1, 1, 0, 0, 0, 0, 1, 4)
172
           || test_pooling1d(8, 8, 1, 1, 1, 0, 0, 0, 0, 1, 5)
173
           || test_pooling1d(8, 8, 1, 1, 1, 0, 0, 0, 0, 1, 6)
174
           || test_pooling1d(8, 8, 1, 1, 1, 0, 0, 0, 0, 1, 7)
175
           || test_pooling1d(8, 8, 1, 1, 1, 0, 0, 0, 0, 1, 8)
176
           || test_pooling1d(11, 16, 1, 1, 1, 0, 0, 0, 1, 0, 1)
177
           || test_pooling1d(11, 16, 1, 1, 1, 0, 0, 0, 1, 0, 3)
178
           || test_pooling1d(11, 16, 1, 1, 1, 0, 0, 0, 1, 0, 5)
179
           || test_pooling1d(11, 16, 1, 1, 1, 0, 0, 0, 1, 0, 7)
180
           || test_pooling1d(11, 16, 1, 1, 1, 0, 0, 0, 1, 0, 9)
181
           || test_pooling1d(11, 16, 1, 1, 1, 0, 0, 0, 1, 0, 11)
182
           || test_pooling1d(11, 16, 1, 1, 1, 0, 0, 0, 1, 0, 13)
183
           || test_pooling1d(13, 16, 1, 1, 1, 0, 0, 0, 1, 0, 2)
184
           || test_pooling1d(13, 16, 1, 1, 1, 0, 0, 0, 1, 0, 4)
185
           || test_pooling1d(13, 16, 1, 1, 1, 0, 0, 0, 1, 0, 6)
186
           || test_pooling1d(13, 16, 1, 1, 1, 0, 0, 0, 1, 0, 8)
187
           || test_pooling1d(13, 16, 1, 1, 1, 0, 0, 0, 1, 0, 10)
188
           || test_pooling1d(13, 16, 1, 1, 1, 0, 0, 0, 1, 0, 12);
189
}
190

191
// adaptive max pool
192
static int test_pooling1d_4()
193
{
194
    return 0
195
           || test_pooling1d(2, 1, 0, 1, 1, 0, 0, 0, 0, 1, 1)
196
           || test_pooling1d(2, 1, 0, 1, 1, 0, 0, 0, 0, 1, 2)
197
           || test_pooling1d(2, 1, 0, 1, 1, 0, 0, 0, 0, 1, 3)
198
           || test_pooling1d(2, 1, 0, 1, 1, 0, 0, 0, 0, 1, 4)
199
           || test_pooling1d(2, 1, 0, 1, 1, 0, 0, 0, 0, 1, 5)
200
           || test_pooling1d(2, 1, 0, 1, 1, 0, 0, 0, 0, 1, 6)
201
           || test_pooling1d(5, 1, 0, 1, 1, 0, 0, 0, 0, 1, 1)
202
           || test_pooling1d(5, 1, 0, 1, 1, 0, 0, 0, 0, 1, 2)
203
           || test_pooling1d(5, 1, 0, 1, 1, 0, 0, 0, 0, 1, 3)
204
           || test_pooling1d(5, 1, 0, 1, 1, 0, 0, 0, 0, 1, 4)
205
           || test_pooling1d(5, 1, 0, 1, 1, 0, 0, 0, 0, 1, 5)
206
           || test_pooling1d(5, 1, 0, 1, 1, 0, 0, 0, 0, 1, 6)
207
           || test_pooling1d(3, 3, 0, 1, 1, 0, 0, 0, 0, 1, 1)
208
           || test_pooling1d(3, 3, 0, 1, 1, 0, 0, 0, 0, 1, 2)
209
           || test_pooling1d(3, 3, 0, 1, 1, 0, 0, 0, 0, 1, 3)
210
           || test_pooling1d(3, 3, 0, 1, 1, 0, 0, 0, 0, 1, 4)
211
           || test_pooling1d(3, 3, 0, 1, 1, 0, 0, 0, 0, 1, 5)
212
           || test_pooling1d(3, 3, 0, 1, 1, 0, 0, 0, 0, 1, 6)
213
           || test_pooling1d(4, 4, 0, 1, 1, 0, 0, 0, 0, 1, 1)
214
           || test_pooling1d(4, 4, 0, 1, 1, 0, 0, 0, 0, 1, 2)
215
           || test_pooling1d(4, 4, 0, 1, 1, 0, 0, 0, 0, 1, 3)
216
           || test_pooling1d(4, 4, 0, 1, 1, 0, 0, 0, 0, 1, 4)
217
           || test_pooling1d(4, 4, 0, 1, 1, 0, 0, 0, 0, 1, 5)
218
           || test_pooling1d(4, 4, 0, 1, 1, 0, 0, 0, 0, 1, 6)
219
           || test_pooling1d(4, 4, 0, 1, 1, 0, 0, 0, 0, 1, 7)
220
           || test_pooling1d(4, 4, 0, 1, 1, 0, 0, 0, 0, 1, 8)
221
           || test_pooling1d(6, 4, 0, 1, 1, 0, 0, 0, 0, 1, 1)
222
           || test_pooling1d(6, 4, 0, 1, 1, 0, 0, 0, 0, 1, 2)
223
           || test_pooling1d(6, 4, 0, 1, 1, 0, 0, 0, 0, 1, 3)
224
           || test_pooling1d(6, 4, 0, 1, 1, 0, 0, 0, 0, 1, 4)
225
           || test_pooling1d(6, 4, 0, 1, 1, 0, 0, 0, 0, 1, 5)
226
           || test_pooling1d(6, 4, 0, 1, 1, 0, 0, 0, 0, 1, 6)
227
           || test_pooling1d(8, 8, 0, 1, 1, 0, 0, 0, 0, 1, 1)
228
           || test_pooling1d(8, 8, 0, 1, 1, 0, 0, 0, 0, 1, 2)
229
           || test_pooling1d(8, 8, 0, 1, 1, 0, 0, 0, 0, 1, 3)
230
           || test_pooling1d(8, 8, 0, 1, 1, 0, 0, 0, 0, 1, 4)
231
           || test_pooling1d(8, 8, 0, 1, 1, 0, 0, 0, 0, 1, 5)
232
           || test_pooling1d(8, 8, 0, 1, 1, 0, 0, 0, 0, 1, 6)
233
           || test_pooling1d(8, 8, 0, 1, 1, 0, 0, 0, 0, 1, 7)
234
           || test_pooling1d(8, 8, 0, 1, 1, 0, 0, 0, 0, 1, 8)
235
           || test_pooling1d(11, 16, 0, 1, 1, 0, 0, 0, 1, 0, 1)
236
           || test_pooling1d(11, 16, 0, 1, 1, 0, 0, 0, 1, 0, 3)
237
           || test_pooling1d(11, 16, 0, 1, 1, 0, 0, 0, 1, 0, 5)
238
           || test_pooling1d(11, 16, 0, 1, 1, 0, 0, 0, 1, 0, 7)
239
           || test_pooling1d(11, 16, 0, 1, 1, 0, 0, 0, 1, 0, 9)
240
           || test_pooling1d(11, 16, 0, 1, 1, 0, 0, 0, 1, 0, 11)
241
           || test_pooling1d(11, 16, 0, 1, 1, 0, 0, 0, 1, 0, 13)
242
           || test_pooling1d(13, 16, 0, 1, 1, 0, 0, 0, 1, 0, 2)
243
           || test_pooling1d(13, 16, 0, 1, 1, 0, 0, 0, 1, 0, 4)
244
           || test_pooling1d(13, 16, 0, 1, 1, 0, 0, 0, 1, 0, 6)
245
           || test_pooling1d(13, 16, 0, 1, 1, 0, 0, 0, 1, 0, 8)
246
           || test_pooling1d(13, 16, 0, 1, 1, 0, 0, 0, 1, 0, 10)
247
           || test_pooling1d(13, 16, 0, 1, 1, 0, 0, 0, 1, 0, 12);
248
}
249

250
int main()
251
{
252
    SRAND(7767517);
253

254
    return 0
255
           || test_pooling1d_0()
256
           || test_pooling1d_1()
257
           || test_pooling1d_2()
258
           || test_pooling1d_3()
259
           || test_pooling1d_4();
260
}
261

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.