From a779b424507b85f6f47d6d96222474d983806179 Mon Sep 17 00:00:00 2001 From: chengduoZH Date: Tue, 27 Feb 2018 22:46:50 +0800 Subject: [PATCH] follow comments --- paddle/fluid/operators/conv_op.cc | 6 ------ paddle/fluid/operators/conv_op.h | 9 ++++++++- paddle/fluid/operators/pool_op.cc | 5 +++++ 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/paddle/fluid/operators/conv_op.cc b/paddle/fluid/operators/conv_op.cc index f703b4cac11..83b7708bf33 100644 --- a/paddle/fluid/operators/conv_op.cc +++ b/paddle/fluid/operators/conv_op.cc @@ -54,12 +54,6 @@ 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) { - PADDLE_ENFORCE(in_dims[i + 2] + 2 * paddings[i] - - (dilations[i] * (filter_dims[i + 2] - 1) + 1) >= - 0, - "Due to the settings of paddings, filter_dims and " - "dilations, the output size is less than 0, please check " - "again."); output_shape.push_back(ConvOutputSize(in_dims[i + 2], filter_dims[i + 2], dilations[i], paddings[i], strides[i])); diff --git a/paddle/fluid/operators/conv_op.h b/paddle/fluid/operators/conv_op.h index c93c2e73f72..12b45f1d650 100644 --- a/paddle/fluid/operators/conv_op.h +++ b/paddle/fluid/operators/conv_op.h @@ -31,7 +31,14 @@ using Tensor = framework::Tensor; inline int ConvOutputSize(int input_size, int filter_size, int dilation, int padding, int stride) { const int dkernel = dilation * (filter_size - 1) + 1; - const int output_size = (input_size + 2 * padding - dkernel) / stride + 1; + int output_size = (input_size + 2 * padding - dkernel) / stride + 1; + PADDLE_ENFORCE( + output_size > 0, + "Due to the settings of padding(%d), filter_size(%d), dilation(%d) and " + "stride(%d), the output size is less than 0, please check " + "again. Input_size:%d", + padding, filter_size, dilation, stride, input_size); + return output_size; } inline bool IsExpand(std::vector& filter_dim, diff --git a/paddle/fluid/operators/pool_op.cc b/paddle/fluid/operators/pool_op.cc index c7729ad1322..a87a3511ee4 100644 --- a/paddle/fluid/operators/pool_op.cc +++ b/paddle/fluid/operators/pool_op.cc @@ -19,6 +19,11 @@ namespace operators { int PoolOutputSize(int input_size, int filter_size, int padding, int stride) { int output_size = (input_size - filter_size + 2 * padding) / stride + 1; + PADDLE_ENFORCE(output_size > 0, + "Due to the settings of padding(%d), filter_size(%d) and " + "stride(%d), the output size is less than 0, please check " + "again. Input_size:%d", + padding, filter_size, stride, input_size); return output_size; } -- GitLab