|
|
|
@@ -22,7 +22,7 @@ class TestOpenCL_Conv2dTranspose : public CommonTest {}; |
|
|
|
|
|
|
|
namespace { |
|
|
|
// PrimitiveType_DeConv2D: src/ops/populate/deconv2d_populate.cc |
|
|
|
OpParameter *CreateParameter(int n, int h, int w, int ci, int co, int kh, int kw, int pad, |
|
|
|
OpParameter *CreateParameter(int n, int h, int w, int ci, int co, int kh, int kw, std::vector<int> pad, int oh, int ow, |
|
|
|
std::vector<int> *input_shape, std::vector<int> *weight_shape, |
|
|
|
std::vector<int> *bias_shape, std::vector<int> *output_shape) { |
|
|
|
auto *param = test::CreateParameter<ConvParameter>(schema::PrimitiveType_DeConv2D); |
|
|
|
@@ -30,16 +30,15 @@ OpParameter *CreateParameter(int n, int h, int w, int ci, int co, int kh, int kw |
|
|
|
param->kernel_w_ = kw; |
|
|
|
param->stride_h_ = 2; |
|
|
|
param->stride_w_ = 2; |
|
|
|
param->pad_u_ = pad; |
|
|
|
param->pad_d_ = pad; |
|
|
|
param->pad_l_ = pad; |
|
|
|
param->pad_r_ = pad; |
|
|
|
MS_ASSERT(pad.size() == 4); |
|
|
|
param->pad_u_ = pad[0]; |
|
|
|
param->pad_d_ = pad[1]; |
|
|
|
param->pad_l_ = pad[2]; |
|
|
|
param->pad_r_ = pad[3]; |
|
|
|
param->dilation_h_ = 1; |
|
|
|
param->dilation_w_ = 1; |
|
|
|
param->act_type_ = ActType_No; |
|
|
|
|
|
|
|
int oh = 2 * h - 1 + 2 * (kh - 1 - pad) - kh + 1; |
|
|
|
int ow = 2 * w - 1 + 2 * (kw - 1 - pad) - kw + 1; |
|
|
|
*input_shape = {n, h, w, ci}; |
|
|
|
*weight_shape = {co, kh, kw, ci}; |
|
|
|
*bias_shape = {co}; |
|
|
|
@@ -52,11 +51,13 @@ TEST_F(TestOpenCL_Conv2dTranspose, test0) { |
|
|
|
int n = 1; |
|
|
|
int h = 2; |
|
|
|
int w = 2; |
|
|
|
int oh = 4; |
|
|
|
int ow = 4; |
|
|
|
int ci = 2; |
|
|
|
int co = 1; |
|
|
|
int kh = 2; |
|
|
|
int kw = 2; |
|
|
|
int pad = 0; |
|
|
|
std::vector<int> pad = {0, 0, 0, 0}; |
|
|
|
float input_data[] = {0, 1, 2, 3, 4, 5, 6, 7}; |
|
|
|
float weight_data[] = {1, 2, 3, 4, 5, 6, 7, 8}; |
|
|
|
float bias_data[] = {0.5}; |
|
|
|
@@ -65,7 +66,36 @@ TEST_F(TestOpenCL_Conv2dTranspose, test0) { |
|
|
|
for (auto fp16_enable : {false, true}) { |
|
|
|
std::vector<int> input_shape, weight_shape, bias_shape, output_shape; |
|
|
|
auto *param = |
|
|
|
CreateParameter(n, h, w, ci, co, kh, kw, pad, &input_shape, &weight_shape, &bias_shape, &output_shape); |
|
|
|
CreateParameter(n, h, w, ci, co, kh, kw, pad, oh, ow, &input_shape, &weight_shape, &bias_shape, &output_shape); |
|
|
|
TestMain({{input_shape, input_data, VAR}, |
|
|
|
{weight_shape, weight_data, CONST_TENSOR}, |
|
|
|
{bias_shape, bias_data, CONST_TENSOR}}, |
|
|
|
{output_shape, output_data}, param, fp16_enable); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
TEST_F(TestOpenCL_Conv2dTranspose, test1) { |
|
|
|
int n = 1; |
|
|
|
int h = 3; |
|
|
|
int w = 3; |
|
|
|
int oh = 6; |
|
|
|
int ow = 6; |
|
|
|
int ci = 2; |
|
|
|
int co = 1; |
|
|
|
int kh = 2; |
|
|
|
int kw = 2; |
|
|
|
std::vector<int> pad = {0, 1, 0, 1}; |
|
|
|
float input_data[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17}; |
|
|
|
float weight_data[] = {0, 2, 4, 6, 1, 3, 5, 7}; |
|
|
|
float bias_data[] = {0.5}; |
|
|
|
float output_data[] = {1.5, 3.5, 3.5, 13.5, 5.5, 23.5, 5.5, 7.5, 23.5, 33.5, 41.5, 59.5, |
|
|
|
7.5, 33.5, 9.5, 43.5, 11.5, 53.5, 59.5, 85.5, 77.5, 111.5, 95.5, 137.5, |
|
|
|
13.5, 63.5, 15.5, 73.5, 17.5, 83.5, 113.5, 163.5, 131.5, 189.5, 149.5, 215.5}; |
|
|
|
|
|
|
|
for (auto fp16_enable : {false, true}) { |
|
|
|
std::vector<int> input_shape, weight_shape, bias_shape, output_shape; |
|
|
|
auto *param = |
|
|
|
CreateParameter(n, h, w, ci, co, kh, kw, pad, oh, ow, &input_shape, &weight_shape, &bias_shape, &output_shape); |
|
|
|
TestMain({{input_shape, input_data, VAR}, |
|
|
|
{weight_shape, weight_data, CONST_TENSOR}, |
|
|
|
{bias_shape, bias_data, CONST_TENSOR}}, |
|
|
|
|