From b63746069bf93c787b984c846159f7200be61bd7 Mon Sep 17 00:00:00 2001 From: tink2123 Date: Mon, 15 Apr 2019 13:19:02 +0000 Subject: [PATCH] polish the code test=develop --- paddle/fluid/operators/affine_channel_op.cc | 9 +++------ paddle/fluid/operators/conv_op.cc | 2 +- paddle/fluid/operators/roi_pool_op.cc | 14 ++++++-------- paddle/fluid/operators/row_conv_op.cc | 8 +------- paddle/fluid/operators/unpool_op.cc | 2 +- 5 files changed, 12 insertions(+), 23 deletions(-) diff --git a/paddle/fluid/operators/affine_channel_op.cc b/paddle/fluid/operators/affine_channel_op.cc index 7663890a478..27370a3c29a 100644 --- a/paddle/fluid/operators/affine_channel_op.cc +++ b/paddle/fluid/operators/affine_channel_op.cc @@ -80,14 +80,11 @@ class AffineChannelOp : public framework::OperatorWithKernel { PADDLE_ENFORCE_EQ(scale_dims.size(), 1UL); PADDLE_ENFORCE_EQ(b_dims.size(), 1UL); - if (ctx->IsRuntime()) { + if (ctx->IsRuntime() || scale_dims[0] > 0) { PADDLE_ENFORCE_EQ(scale_dims[0], C); + } + if (ctx->IsRuntime() || b_dims[0] > 0) { PADDLE_ENFORCE_EQ(b_dims[0], C); - } else { - if (scale_dims[0] > 0 && b_dims[0] > 0) { - PADDLE_ENFORCE_EQ(scale_dims[0], C); - PADDLE_ENFORCE_EQ(b_dims[0], C); - } } ctx->SetOutputDim("Out", ctx->GetInputDim("X")); diff --git a/paddle/fluid/operators/conv_op.cc b/paddle/fluid/operators/conv_op.cc index a78e8ca4fb7..e1281602bf0 100644 --- a/paddle/fluid/operators/conv_op.cc +++ b/paddle/fluid/operators/conv_op.cc @@ -69,7 +69,7 @@ void ConvOp::InferShape(framework::InferShapeContext* ctx) const { std::vector output_shape({in_dims[0], filter_dims[0]}); for (size_t i = 0; i < strides.size(); ++i) { if ((!ctx->IsRuntime()) && - (in_dims[i + 2] == -1 || filter_dims[i + 2] == -1)) { + (in_dims[i + 2] <= 0 || filter_dims[i + 2] <= 0)) { output_shape.push_back(-1); } else { output_shape.push_back(ConvOutputSize(in_dims[i + 2], filter_dims[i + 2], diff --git a/paddle/fluid/operators/roi_pool_op.cc b/paddle/fluid/operators/roi_pool_op.cc index 11b0bf3beec..cfac7e09e12 100644 --- a/paddle/fluid/operators/roi_pool_op.cc +++ b/paddle/fluid/operators/roi_pool_op.cc @@ -50,14 +50,12 @@ class ROIPoolOp : public framework::OperatorWithKernel { int pooled_width = ctx->Attrs().Get("pooled_width"); float spatial_scale = ctx->Attrs().Get("spatial_scale"); - if (ctx->IsRuntime()) { - PADDLE_ENFORCE_GT(pooled_height, 0, - "The pooled output height must greater than 0"); - PADDLE_ENFORCE_GT(pooled_width, 0, - "The pooled output width must greater than 0"); - PADDLE_ENFORCE_GT(spatial_scale, 0.0f, - "The spatial scale must greater than 0"); - } + PADDLE_ENFORCE_GT(pooled_height, 0, + "The pooled output height must greater than 0"); + PADDLE_ENFORCE_GT(pooled_width, 0, + "The pooled output width must greater than 0"); + PADDLE_ENFORCE_GT(spatial_scale, 0.0f, + "The spatial scale must greater than 0"); auto out_dims = input_dims; out_dims[0] = rois_dims[0]; diff --git a/paddle/fluid/operators/row_conv_op.cc b/paddle/fluid/operators/row_conv_op.cc index ac66f469494..b3e9f2d0a51 100644 --- a/paddle/fluid/operators/row_conv_op.cc +++ b/paddle/fluid/operators/row_conv_op.cc @@ -41,16 +41,10 @@ class RowConvOp : public framework::OperatorWithKernel { auto filter_dims = ctx->GetInputDim("Filter"); PADDLE_ENFORCE_EQ(x_dims.size(), 2, "Input(X)'s rank should be 2."); PADDLE_ENFORCE_EQ(filter_dims.size(), 2, "Input(Y)'s rank should be 2."); - if (ctx->IsRuntime()) { + if (ctx->IsRuntime() || (x_dims[1] > 0 && filter_dims[1] > 0)) { PADDLE_ENFORCE_EQ( x_dims[1], filter_dims[1], "The 2nd dimension of Input(X) and Input(Filter) should be same."); - } else { - if (x_dims[1] > 0 && filter_dims[1] > 0) { - PADDLE_ENFORCE_EQ( - x_dims[1], filter_dims[1], - "The 2nd dimension of Input(X) and Input(Filter) should be same."); - } } ctx->SetOutputDim("Out", x_dims); diff --git a/paddle/fluid/operators/unpool_op.cc b/paddle/fluid/operators/unpool_op.cc index bb487e94d53..86b4c06a27c 100644 --- a/paddle/fluid/operators/unpool_op.cc +++ b/paddle/fluid/operators/unpool_op.cc @@ -102,7 +102,7 @@ class UnpoolOp : public framework::OperatorWithKernel { std::vector output_shape({in_x_dims[0], in_x_dims[1]}); for (size_t i = 0; i < ksize.size(); ++i) { - if (!ctx->IsRuntime() && in_x_dims[i + 2] == -1) { + if (!ctx->IsRuntime() && in_x_dims[i + 2] <= 0) { output_shape.push_back(-1); } else { output_shape.push_back(UnpoolOutputSize(in_x_dims[i + 2], ksize[i], -- GitLab