ncnn

Форк
0
/
test_crop.cpp 
279 строк · 13.7 Кб
1
// Tencent is pleased to support the open source community by making ncnn available.
2
//
3
// Copyright (C) 2020 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_crop(const ncnn::Mat& a, int woffset, int hoffset, int doffset, int coffset, int outw, int outh, int outd, int outc, int woffset2, int hoffset2, int doffset2, int coffset2)
18
{
19
    ncnn::ParamDict pd;
20
    pd.set(0, woffset);   // woffset
21
    pd.set(1, hoffset);   // hoffset
22
    pd.set(13, doffset);  // doffset
23
    pd.set(2, coffset);   // coffset
24
    pd.set(3, outw);      // outw
25
    pd.set(4, outh);      // outh
26
    pd.set(14, outd);     // outd
27
    pd.set(5, outc);      // outc
28
    pd.set(6, woffset2);  // woffset2
29
    pd.set(7, hoffset2);  // hoffset2
30
    pd.set(15, doffset2); // doffset2
31
    pd.set(8, coffset2);  // coffset2
32

33
    std::vector<ncnn::Mat> weights(0);
34

35
    int ret = test_layer("Crop", pd, weights, a);
36
    if (ret != 0)
37
    {
38
        fprintf(stderr, "test_crop failed a.dims=%d a=(%d %d %d %d) woffset=%d hoffset=%d doffset=%d coffset=%d outw=%d outh=%d outd=%d outc=%d woffset2=%d hoffset2=%d doffset2=%d coffset2=%d\n", a.dims, a.w, a.h, a.d, a.c, woffset, hoffset, doffset, coffset, outw, outh, outd, outc, woffset2, hoffset2, doffset2, coffset2);
39
    }
40

41
    return ret;
42
}
43

44
static int test_crop_0(const ncnn::Mat& a)
45
{
46
    return 0
47
           || test_crop(a, 0, 0, 0, 0, -233, 0, 0, 0, 0, 0, 0, 0)
48
           || test_crop(a, 11, 0, 0, 0, -233, 0, 0, 0, 0, 0, 0, 0)
49
           || test_crop(a, 11, 0, 0, 0, 7, 0, 0, 0, 0, 0, 0, 0)
50
           || test_crop(a, 12, 0, 0, 0, 12, 0, 0, 0, 0, 0, 0, 0)
51
           || test_crop(a, 16, 0, 0, 0, 16, 0, 0, 0, 0, 0, 0, 0)
52
           || test_crop(a, 11, 0, 0, 0, -233, 0, 0, 0, 12, 0, 0, 0)
53
           || test_crop(a, 12, 0, 0, 0, -233, 0, 0, 0, 16, 0, 0, 0)
54
           || test_crop(a, 16, 0, 0, 0, -233, 0, 0, 0, 7, 0, 0, 0);
55
}
56

57
static int test_crop_3(const ncnn::Mat& a)
58
{
59
    return 0
60
           || test_crop(a, 0, 0, 0, 0, -233, -233, 0, 0, 0, 0, 0, 0)
61
           || test_crop(a, 5, 0, 0, 0, -233, -233, 0, 0, 0, 0, 0, 0)
62
           || test_crop(a, 0, 11, 0, 0, -233, -233, 0, 0, 0, 0, 0, 0)
63
           || test_crop(a, 0, 12, 0, 0, -233, -233, 0, 0, 0, 0, 0, 0)
64
           || test_crop(a, 6, 12, 0, 0, -233, -233, 0, 0, 0, 0, 0, 0)
65
           || test_crop(a, 4, 8, 0, 0, -233, -233, 0, 0, 0, 0, 0, 0)
66

67
           || test_crop(a, 5, 0, 0, 0, 5, -233, 0, 0, 0, 0, 0, 0)
68
           || test_crop(a, 6, 0, 0, 0, 6, -233, 0, 0, 0, 0, 0, 0)
69
           || test_crop(a, 4, 0, 0, 0, 4, -233, 0, 0, 0, 0, 0, 0)
70

71
           || test_crop(a, 0, 11, 0, 0, -233, 12, 0, 0, 0, 0, 0, 0)
72
           || test_crop(a, 0, 12, 0, 0, -233, 16, 0, 0, 0, 0, 0, 0)
73
           || test_crop(a, 0, 8, 0, 0, -233, 7, 0, 0, 0, 0, 0, 0)
74

75
           || test_crop(a, 5, 11, 0, 0, 4, 16, 0, 0, 0, 0, 0, 0)
76
           || test_crop(a, 6, 12, 0, 0, 5, 7, 0, 0, 0, 0, 0, 0)
77
           || test_crop(a, 4, 8, 0, 0, 6, 12, 0, 0, 0, 0, 0, 0)
78

79
           || test_crop(a, 5, 0, 0, 0, -233, -233, 0, 0, 5, 0, 0, 0)
80
           || test_crop(a, 6, 0, 0, 0, -233, -233, 0, 0, 6, 0, 0, 0)
81
           || test_crop(a, 4, 0, 0, 0, -233, -233, 0, 0, 4, 0, 0, 0)
82

83
           || test_crop(a, 0, 11, 0, 0, -233, -233, 0, 0, 0, 12, 0, 0)
84
           || test_crop(a, 0, 12, 0, 0, -233, -233, 0, 0, 0, 16, 0, 0)
85
           || test_crop(a, 0, 8, 0, 0, -233, -233, 0, 0, 0, 7, 0, 0)
86

87
           || test_crop(a, 5, 11, 0, 0, -233, -233, 0, 0, 4, 16, 0, 0)
88
           || test_crop(a, 6, 12, 0, 0, -233, -233, 0, 0, 5, 7, 0, 0)
89
           || test_crop(a, 4, 8, 0, 0, -233, -233, 0, 0, 6, 12, 0, 0);
90
}
91

92
static int test_crop_6(const ncnn::Mat& a)
93
{
94
    return 0
95
           || test_crop(a, 0, 0, 0, 0, -233, -233, 0, -233, 0, 0, 0, 0)
96
           || test_crop(a, 6, 0, 0, 0, -233, -233, 0, -233, 0, 0, 0, 0)
97
           || test_crop(a, 0, 5, 0, 0, -233, -233, 0, -233, 0, 0, 0, 0)
98
           || test_crop(a, 0, 4, 0, 0, -233, -233, 0, -233, 0, 0, 0, 0)
99
           || test_crop(a, 0, 0, 0, 12, -233, -233, 0, -233, 0, 0, 0, 0)
100
           || test_crop(a, 5, 5, 0, 0, -233, -233, 0, -233, 0, 0, 0, 0)
101
           || test_crop(a, 4, 4, 0, 0, -233, -233, 0, -233, 0, 0, 0, 0)
102
           || test_crop(a, 0, 6, 0, 12, -233, -233, 0, -233, 0, 0, 0, 0)
103
           || test_crop(a, 5, 0, 0, 11, -233, -233, 0, -233, 0, 0, 0, 0)
104
           || test_crop(a, 4, 0, 0, 8, -233, -233, 0, -233, 0, 0, 0, 0)
105
           || test_crop(a, 6, 6, 0, 12, -233, -233, 0, -233, 0, 0, 0, 0)
106

107
           || test_crop(a, 5, 0, 0, 0, 6, -233, 0, -233, 0, 0, 0, 0)
108
           || test_crop(a, 6, 0, 0, 0, 4, -233, 0, -233, 0, 0, 0, 0)
109
           || test_crop(a, 4, 0, 0, 0, 5, -233, 0, -233, 0, 0, 0, 0)
110

111
           || test_crop(a, 0, 5, 0, 0, -233, 4, 0, -233, 0, 0, 0, 0)
112
           || test_crop(a, 0, 6, 0, 0, -233, 5, 0, -233, 0, 0, 0, 0)
113
           || test_crop(a, 0, 4, 0, 0, -233, 6, 0, -233, 0, 0, 0, 0)
114

115
           || test_crop(a, 0, 0, 0, 11, -233, -233, 0, 7, 0, 0, 0, 0)
116
           || test_crop(a, 0, 0, 0, 12, -233, -233, 0, 12, 0, 0, 0, 0)
117
           || test_crop(a, 0, 0, 0, 8, -233, -233, 0, 16, 0, 0, 0, 0)
118

119
           || test_crop(a, 5, 5, 0, 0, 4, 4, 0, -233, 0, 0, 0, 0)
120
           || test_crop(a, 6, 6, 0, 0, 6, 6, 0, -233, 0, 0, 0, 0)
121
           || test_crop(a, 4, 4, 0, 0, 5, 5, 0, -233, 0, 0, 0, 0)
122

123
           || test_crop(a, 0, 5, 0, 11, -233, 6, 0, 12, 0, 0, 0, 0)
124
           || test_crop(a, 0, 6, 0, 12, -233, 4, 0, 16, 0, 0, 0, 0)
125
           || test_crop(a, 0, 4, 0, 8, -233, 5, 0, 7, 0, 0, 0, 0)
126

127
           || test_crop(a, 5, 0, 0, 11, 4, -233, 0, 16, 0, 0, 0, 0)
128
           || test_crop(a, 6, 0, 0, 12, 5, -233, 0, 7, 0, 0, 0, 0)
129
           || test_crop(a, 4, 0, 0, 8, 4, -233, 0, 12, 0, 0, 0, 0)
130

131
           || test_crop(a, 5, 3, 0, 11, 6, 5, 0, 12, 0, 0, 0, 0)
132
           || test_crop(a, 6, 4, 0, 12, 4, 4, 0, 16, 0, 0, 0, 0)
133
           || test_crop(a, 4, 5, 0, 8, 5, 3, 0, 7, 0, 0, 0, 0)
134

135
           || test_crop(a, 5, 0, 0, 0, -233, -233, 0, -233, 4, 0, 0, 0)
136
           || test_crop(a, 6, 0, 0, 0, -233, -233, 0, -233, 5, 0, 0, 0)
137
           || test_crop(a, 4, 0, 0, 0, -233, -233, 0, -233, 6, 0, 0, 0)
138

139
           || test_crop(a, 0, 5, 0, 0, -233, -233, 0, -233, 0, 5, 0, 0)
140
           || test_crop(a, 0, 6, 0, 0, -233, -233, 0, -233, 0, 6, 0, 0)
141
           || test_crop(a, 0, 4, 0, 0, -233, -233, 0, -233, 0, 4, 0, 0)
142

143
           || test_crop(a, 0, 0, 0, 11, -233, -233, 0, -233, 0, 0, 0, 12)
144
           || test_crop(a, 0, 0, 0, 12, -233, -233, 0, -233, 0, 0, 0, 16)
145
           || test_crop(a, 0, 0, 0, 8, -233, -233, 0, -233, 0, 0, 0, 7)
146

147
           || test_crop(a, 5, 4, 0, 0, -233, -233, 0, -233, 4, 2, 0, 0)
148
           || test_crop(a, 6, 3, 0, 0, -233, -233, 0, -233, 5, 3, 0, 0)
149
           || test_crop(a, 4, 2, 0, 0, -233, -233, 0, -233, 6, 4, 0, 0)
150

151
           || test_crop(a, 0, 5, 0, 11, -233, -233, 0, -233, 0, 5, 0, 7)
152
           || test_crop(a, 0, 6, 0, 12, -233, -233, 0, -233, 0, 6, 0, 12)
153
           || test_crop(a, 0, 4, 0, 8, -233, -233, 0, -233, 0, 4, 0, 16)
154

155
           || test_crop(a, 5, 0, 0, 11, -233, -233, 0, -233, 6, 0, 0, 12)
156
           || test_crop(a, 6, 0, 0, 12, -233, -233, 0, -233, 4, 0, 0, 16)
157
           || test_crop(a, 4, 0, 0, 8, -233, -233, 0, -233, 5, 0, 0, 7)
158

159
           || test_crop(a, 5, 2, 0, 11, -233, -233, 0, -233, 4, 3, 0, 16)
160
           || test_crop(a, 6, 3, 0, 12, -233, -233, 0, -233, 5, 4, 0, 7)
161
           || test_crop(a, 4, 4, 0, 8, -233, -233, 0, -233, 6, 2, 0, 12);
162
}
163

164
static int test_crop_9(const ncnn::Mat& a)
165
{
166
    return 0
167
           || test_crop(a, 0, 0, 0, 0, -233, -233, -233, -233, 0, 0, 0, 0)
168
           || test_crop(a, 6, 0, 0, 0, -233, -233, -233, -233, 0, 0, 0, 0)
169
           || test_crop(a, 0, 5, 0, 0, -233, -233, -233, -233, 0, 0, 0, 0)
170
           || test_crop(a, 0, 4, 0, 0, -233, -233, -233, -233, 0, 0, 0, 0)
171
           || test_crop(a, 0, 0, 5, 0, -233, -233, -233, -233, 0, 0, 0, 0)
172
           || test_crop(a, 0, 0, 4, 0, -233, -233, -233, -233, 0, 0, 0, 0)
173
           || test_crop(a, 0, 0, 0, 12, -233, -233, -233, -233, 0, 0, 0, 0)
174
           || test_crop(a, 5, 5, 5, 0, -233, -233, -233, -233, 0, 0, 0, 0)
175
           || test_crop(a, 4, 4, 4, 0, -233, -233, -233, -233, 0, 0, 0, 0)
176
           || test_crop(a, 0, 6, 6, 12, -233, -233, -233, -233, 0, 0, 0, 0)
177
           || test_crop(a, 5, 0, 5, 11, -233, -233, -233, -233, 0, 0, 0, 0)
178
           || test_crop(a, 4, 0, 4, 8, -233, -233, -233, -233, 0, 0, 0, 0)
179
           || test_crop(a, 6, 6, 6, 12, -233, -233, -233, -233, 0, 0, 0, 0)
180

181
           || test_crop(a, 5, 0, 0, 0, 6, -233, -233, -233, 0, 0, 0, 0)
182
           || test_crop(a, 6, 0, 0, 0, 5, -233, -233, -233, 0, 0, 0, 0)
183
           || test_crop(a, 4, 0, 0, 0, 4, -233, -233, -233, 0, 0, 0, 0)
184

185
           || test_crop(a, 0, 5, 0, 0, -233, 4, -233, -233, 0, 0, 0, 0)
186
           || test_crop(a, 0, 6, 0, 0, -233, 5, -233, -233, 0, 0, 0, 0)
187
           || test_crop(a, 0, 4, 0, 0, -233, 6, -233, -233, 0, 0, 0, 0)
188

189
           || test_crop(a, 0, 0, 5, 0, -233, -233, 6, -233, 0, 0, 0, 0)
190
           || test_crop(a, 0, 0, 6, 0, -233, -233, 4, -233, 0, 0, 0, 0)
191
           || test_crop(a, 0, 0, 4, 0, -233, -233, 5, -233, 0, 0, 0, 0)
192

193
           || test_crop(a, 0, 0, 0, 11, -233, -233, -233, 7, 0, 0, 0, 0)
194
           || test_crop(a, 0, 0, 0, 12, -233, -233, -233, 12, 0, 0, 0, 0)
195
           || test_crop(a, 0, 0, 0, 8, -233, -233, -233, 16, 0, 0, 0, 0)
196

197
           || test_crop(a, 5, 2, 0, 0, 6, 5, -233, -233, 0, 0, 0, 0)
198
           || test_crop(a, 6, 3, 0, 0, 5, 6, -233, -233, 0, 0, 0, 0)
199
           || test_crop(a, 4, 4, 0, 0, 4, 4, -233, -233, 0, 0, 0, 0)
200

201
           || test_crop(a, 5, 0, 3, 0, 2, -233, 5, -233, 0, 0, 0, 0)
202
           || test_crop(a, 6, 0, 2, 0, 3, -233, 3, -233, 0, 0, 0, 0)
203
           || test_crop(a, 4, 0, 4, 0, 4, -233, 4, -233, 0, 0, 0, 0)
204

205
           || test_crop(a, 0, 5, 0, 11, -233, 1, -233, 12, 0, 0, 0, 0)
206
           || test_crop(a, 0, 6, 0, 12, -233, 2, -233, 16, 0, 0, 0, 0)
207
           || test_crop(a, 0, 4, 0, 8, -233, 3, -233, 7, 0, 0, 0, 0)
208

209
           || test_crop(a, 0, 0, 4, 11, -233, -233, 3, 16, 0, 0, 0, 0)
210
           || test_crop(a, 0, 0, 5, 12, -233, -233, 2, 7, 0, 0, 0, 0)
211
           || test_crop(a, 0, 0, 6, 8, -233, -233, 1, 16, 0, 0, 0, 0)
212

213
           || test_crop(a, 5, 0, 5, 11, 1, -233, 2, 16, 0, 0, 0, 0)
214
           || test_crop(a, 6, 0, 6, 12, 2, -233, 3, 7, 0, 0, 0, 0)
215
           || test_crop(a, 4, 0, 4, 8, 3, -233, 1, 16, 0, 0, 0, 0)
216

217
           || test_crop(a, 4, 6, 3, 11, 2, 3, 4, 12, 0, 0, 0, 0)
218
           || test_crop(a, 5, 5, 4, 12, 3, 4, 5, 16, 0, 0, 0, 0)
219
           || test_crop(a, 6, 4, 2, 8, 4, 5, 6, 7, 0, 0, 0, 0)
220

221
           || test_crop(a, 5, 0, 0, 0, -233, -233, -233, -233, 2, 0, 0, 0)
222
           || test_crop(a, 6, 0, 0, 0, -233, -233, -233, -233, 3, 0, 0, 0)
223
           || test_crop(a, 4, 0, 0, 0, -233, -233, -233, -233, 4, 0, 0, 0)
224

225
           || test_crop(a, 0, 4, 0, 0, -233, -233, -233, -233, 0, 4, 0, 0)
226
           || test_crop(a, 0, 3, 0, 0, -233, -233, -233, -233, 0, 3, 0, 0)
227
           || test_crop(a, 0, 2, 0, 0, -233, -233, -233, -233, 0, 2, 0, 0)
228

229
           || test_crop(a, 0, 0, 4, 0, -233, -233, -233, -233, 0, 0, 4, 0)
230
           || test_crop(a, 0, 0, 5, 0, -233, -233, -233, -233, 0, 0, 2, 0)
231
           || test_crop(a, 0, 0, 6, 0, -233, -233, -233, -233, 0, 0, 3, 0)
232

233
           || test_crop(a, 0, 0, 0, 11, -233, -233, -233, -233, 0, 0, 0, 12)
234
           || test_crop(a, 0, 0, 0, 12, -233, -233, -233, -233, 0, 0, 0, 16)
235
           || test_crop(a, 0, 0, 0, 8, -233, -233, -233, -233, 0, 0, 0, 7)
236

237
           || test_crop(a, 5, 3, 0, 0, -233, -233, -233, -233, 5, 2, 0, 0)
238
           || test_crop(a, 6, 4, 0, 0, -233, -233, -233, -233, 3, 3, 0, 0)
239
           || test_crop(a, 4, 4, 0, 0, -233, -233, -233, -233, 2, 5, 0, 0)
240

241
           || test_crop(a, 0, 4, 0, 11, -233, -233, -233, -233, 0, 3, 0, 7)
242
           || test_crop(a, 0, 3, 0, 12, -233, -233, -233, -233, 0, 4, 0, 12)
243
           || test_crop(a, 0, 2, 0, 8, -233, -233, -233, -233, 0, 5, 0, 16)
244

245
           || test_crop(a, 0, 4, 4, 0, -233, -233, -233, -233, 0, 4, 1, 0)
246
           || test_crop(a, 0, 5, 5, 0, -233, -233, -233, -233, 0, 2, 2, 0)
247
           || test_crop(a, 0, 2, 6, 0, -233, -233, -233, -233, 0, 1, 3, 0)
248

249
           || test_crop(a, 3, 0, 0, 11, -233, -233, -233, -233, 3, 0, 0, 12)
250
           || test_crop(a, 4, 0, 0, 12, -233, -233, -233, -233, 4, 0, 0, 16)
251
           || test_crop(a, 5, 0, 0, 8, -233, -233, -233, -233, 2, 0, 0, 7)
252

253
           || test_crop(a, 0, 4, 4, 11, -233, -233, -233, -233, 0, 4, 4, 12)
254
           || test_crop(a, 0, 5, 5, 12, -233, -233, -233, -233, 0, 4, 4, 16)
255
           || test_crop(a, 0, 6, 6, 8, -233, -233, -233, -233, 0, 3, 3, 7)
256

257
           || test_crop(a, 1, 1, 1, 11, -233, -233, -233, -233, 1, 1, 1, 16)
258
           || test_crop(a, 2, 2, 2, 12, -233, -233, -233, -233, 2, 2, 2, 7)
259
           || test_crop(a, 3, 3, 3, 8, -233, -233, -233, -233, 3, 3, 3, 12);
260
}
261

262
int main()
263
{
264
    SRAND(776757);
265

266
    return 0
267
           || test_crop_0(RandomMat(112))
268
           || test_crop_0(RandomMat(126))
269
           || test_crop_0(RandomMat(127))
270
           || test_crop_3(RandomMat(20, 48))
271
           || test_crop_3(RandomMat(15, 36))
272
           || test_crop_3(RandomMat(16, 33))
273
           || test_crop_6(RandomMat(20, 20, 48))
274
           || test_crop_6(RandomMat(15, 15, 36))
275
           || test_crop_6(RandomMat(16, 16, 33))
276
           || test_crop_9(RandomMat(20, 20, 20, 48))
277
           || test_crop_9(RandomMat(15, 15, 15, 36))
278
           || test_crop_9(RandomMat(16, 16, 16, 33));
279
}
280

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

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

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

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