1
// Tencent is pleased to support the open source community by making ncnn available.
3
// Copyright (C) 2022 THL A29 Limited, a Tencent company. All rights reserved.
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
8
// https://opensource.org/licenses/BSD-3-Clause
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.
17
static int test_deconvolution1d(int w, int h, int outh, int kernel, int dilation, int stride, int pad, int bias, int output_pad_right, int output_w)
19
ncnn::Mat a = RandomMat(w, h);
21
if (output_w > 0 && pad != -233 && pad != -234)
33
pd.set(6, outh * h * kernel);
35
int activation_type = RAND() % 5; // 0 1 2 3 4
36
ncnn::Mat activation_params(2);
37
activation_params[0] = RandomFloat(-1, 0); // alpha
38
activation_params[1] = RandomFloat(0, 1); // beta
39
pd.set(9, activation_type);
40
pd.set(10, activation_params);
42
pd.set(18, output_pad_right);
45
std::vector<ncnn::Mat> weights(2);
46
weights[0] = RandomMat(outh * h * kernel);
47
weights[1] = RandomMat(outh);
49
int ret = test_layer("Deconvolution1D", pd, weights, a);
52
fprintf(stderr, "test_deconvolution1d failed w=%d h=%d outh=%d kernel=%d dilation=%d stride=%d pad=%d bias=%d act=%d actparams=[%f,%f] output_pad_right=%d output_w=%d\n", w, h, outh, kernel, dilation, stride, pad, bias, activation_type, activation_params[0], activation_params[1], output_pad_right, output_w);
58
static int test_deconvolution1d_0()
60
static const int kdsp[16][4] = {
79
for (int i = 0; i < 16; i++)
81
const int k = kdsp[i][0];
82
const int d = kdsp[i][1];
83
const int s = kdsp[i][2];
84
const int p = kdsp[i][3];
87
|| test_deconvolution1d(9, 1, 1, k, d, s, p, 1, 0, 0)
88
|| test_deconvolution1d(9, 4, 13, k, d, s, p, 0, 1, 7)
89
|| test_deconvolution1d(9, 13, 4, k, d, s, p, 1, 1, 0)
90
|| test_deconvolution1d(9, 4, 8, k, d, s, p, 0, 0, 0)
91
|| test_deconvolution1d(9, 8, 4, k, d, s, p, 1, 0, 7)
92
|| test_deconvolution1d(9, 8, 13, k, d, s, p, 0, 2, 0)
93
|| test_deconvolution1d(9, 13, 8, k, d, s, p, 1, 2, 0)
94
|| test_deconvolution1d(9, 16, 16, k, d, s, p, 0, 0, 7);
103
static int test_deconvolution1d_dynamic(int w, int h, int outh, int kernel, int dilation, int stride, int pad, int bias, int output_pad_right, int output_w)
105
ncnn::Mat a = RandomMat(w, h);
107
if (output_w > 0 && pad != -233 && pad != -234)
120
pd.set(28, 1); // dynamic weight
122
int activation_type = RAND() % 5; // 0 1 2 3 4
123
ncnn::Mat activation_params(2);
124
activation_params[0] = RandomFloat(-1, 0); // alpha
125
activation_params[1] = RandomFloat(0, 1); // beta
126
pd.set(9, activation_type);
127
pd.set(10, activation_params);
129
pd.set(18, output_pad_right);
130
pd.set(20, output_w);
132
std::vector<ncnn::Mat> as(bias ? 3 : 2);
134
as[1] = RandomMat(kernel, outh, h);
136
as[2] = RandomMat(outh);
138
std::vector<ncnn::Mat> weights(0);
140
int ret = test_layer("Deconvolution1D", pd, weights, as);
143
fprintf(stderr, "test_deconvolution1d_dynamic failed w=%d h=%d outh=%d kernel=%d dilation=%d stride=%d pad=%d bias=%d act=%d actparams=[%f,%f] output_pad_right=%d output_w=%d\n", w, h, outh, kernel, dilation, stride, pad, bias, activation_type, activation_params[0], activation_params[1], output_pad_right, output_w);
149
static int test_deconvolution1d_1()
151
static const int kdsp[16][4] = {
170
for (int i = 0; i < 16; i++)
172
const int k = kdsp[i][0];
173
const int d = kdsp[i][1];
174
const int s = kdsp[i][2];
175
const int p = kdsp[i][3];
178
|| test_deconvolution1d_dynamic(9, 1, 1, k, d, s, p, 1, 0, 0)
179
|| test_deconvolution1d_dynamic(9, 4, 13, k, d, s, p, 0, 1, 7)
180
|| test_deconvolution1d_dynamic(9, 13, 4, k, d, s, p, 1, 1, 0)
181
|| test_deconvolution1d_dynamic(9, 4, 8, k, d, s, p, 0, 0, 0)
182
|| test_deconvolution1d_dynamic(9, 8, 4, k, d, s, p, 1, 0, 7)
183
|| test_deconvolution1d_dynamic(9, 8, 13, k, d, s, p, 0, 2, 0)
184
|| test_deconvolution1d_dynamic(9, 13, 8, k, d, s, p, 1, 2, 0)
185
|| test_deconvolution1d_dynamic(9, 16, 16, k, d, s, p, 0, 0, 7);
198
return test_deconvolution1d_0() || test_deconvolution1d_1();