diff --git a/paddle/fluid/operators/conv_op.cc b/paddle/fluid/operators/conv_op.cc index 2ecece707314f1e8b1b0bc9ad28f53ec5e1d405e..83b7708bf337b70f97c5e9126efd142b9b957b00 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 c93c2e73f720ae025a4ad4f8146a7c6c3c382eea..12b45f1d65019f623268cb9da9004bac5e1f72a3 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 c7729ad1322588c0558a136dbd5d48f757d38412..a87a3511ee46dd657c27da26feb43ba43a08f25d 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; } diff --git a/python/paddle/fluid/tests/unittests/test_conv2d_op.py b/python/paddle/fluid/tests/unittests/test_conv2d_op.py index 1fada38a0359d4a0130d58ae2f8442fbfce21e2e..1321cfd484ec8be1d8a817535386db949d825574 100644 --- a/python/paddle/fluid/tests/unittests/test_conv2d_op.py +++ b/python/paddle/fluid/tests/unittests/test_conv2d_op.py @@ -210,6 +210,19 @@ class TestWithDilation(TestConv2dOp): self.groups = 3 +class TestWithInput1x1Filter1x1(TestConv2dOp): + def init_test_case(self): + self.pad = [0, 0] + self.stride = [1, 1] + self.input_size = [2, 3, 1, 1] # NCHW + assert np.mod(self.input_size[1], self.groups) == 0 + f_c = self.input_size[1] / self.groups + self.filter_size = [6, f_c, 1, 1] + + def init_group(self): + self.groups = 3 + + #----------------Conv2dCUDNN---------------- class TestCUDNN(TestConv2dOp): def init_op_type(self): @@ -241,6 +254,12 @@ class TestCUDNNWith1x1(TestWith1x1): self.op_type = "conv2d" +class TestCUDNNWithInput1x1Filter1x1(TestWithInput1x1Filter1x1): + def init_op_type(self): + self.use_cudnn = True + self.op_type = "conv2d" + + class TestDepthwiseConv(TestConv2dOp): def init_test_case(self): self.pad = [1, 1] @@ -265,7 +284,8 @@ class TestDepthwiseConv2(TestConv2dOp): self.op_type = "depthwise_conv2d" -# cudnn v5 does not support dilation conv. +# Please Don't remove the following code. +# Currently, CI use cudnn V5.0 which not support dilation conv. # class TestCUDNNWithDilation(TestWithDilation): # def init_op_type(self): # self.op_type = "conv_cudnn" diff --git a/python/paddle/fluid/tests/unittests/test_conv2d_transpose_op.py b/python/paddle/fluid/tests/unittests/test_conv2d_transpose_op.py index 9831b7eb1269938cfcb1d6a3a2940836ee19ed56..d864b9b348e961c585749d47d449d775b2dfebc9 100644 --- a/python/paddle/fluid/tests/unittests/test_conv2d_transpose_op.py +++ b/python/paddle/fluid/tests/unittests/test_conv2d_transpose_op.py @@ -200,7 +200,8 @@ class TestCUDNNWithStride(TestWithStride): self.op_type = "conv2d_transpose" -# #cudnn v5 does not support dilation conv. +# Please Don't remove the following code. +# Currently, CI use cudnn V5.0 which not support dilation conv. # class TestCUDNNWithDilation(TestWithDilation): # def init_test_case(self): # self.pad = [1, 1] diff --git a/python/paddle/fluid/tests/unittests/test_conv3d_op.py b/python/paddle/fluid/tests/unittests/test_conv3d_op.py index 4d3df5e33c426c92213a199b4841f649446c6e28..d5dd63e8737cbdd9b91d083fbd0b38f8baf570b3 100644 --- a/python/paddle/fluid/tests/unittests/test_conv3d_op.py +++ b/python/paddle/fluid/tests/unittests/test_conv3d_op.py @@ -200,6 +200,22 @@ class TestWith1x1(TestConv3dOp): self.groups = 3 +class TestWithInput1x1Filter1x1(TestConv3dOp): + def init_test_case(self): + self.pad = [0, 0, 0] + self.stride = [1, 1, 1] + self.input_size = [2, 3, 1, 1, 1] # NCHW + assert np.mod(self.input_size[1], self.groups) == 0 + f_c = self.input_size[1] / self.groups + self.filter_size = [6, f_c, 1, 1, 1] + + def init_dilation(self): + self.dilations = [1, 1, 1] + + def init_group(self): + self.groups = 3 + + class TestWithDilation(TestConv3dOp): def init_test_case(self): self.pad = [0, 0, 0] @@ -240,6 +256,12 @@ class TestWith1x1CUDNN(TestWith1x1): self.op_type = "conv3d" +class TestWithInput1x1Filter1x1CUDNN(TestWithInput1x1Filter1x1): + def init_op_type(self): + self.use_cudnn = True + self.op_type = "conv3d" + + # FIXME(typhoonzero): find a way to determine if # using cudnn > 6 in python # class TestWithDilationCUDNN(TestWithDilation): diff --git a/python/paddle/fluid/tests/unittests/test_conv3d_transpose_op.py b/python/paddle/fluid/tests/unittests/test_conv3d_transpose_op.py index a79bfa13d6ca21cac6640deb5a21ef457af984df..55ba238710c56dd0daea388cd2dcdb79243bb71e 100644 --- a/python/paddle/fluid/tests/unittests/test_conv3d_transpose_op.py +++ b/python/paddle/fluid/tests/unittests/test_conv3d_transpose_op.py @@ -207,7 +207,8 @@ class TestCUDNNWithStride(TestWithStride): self.op_type = "conv3d_transpose" -# #cudnn v5 does not support dilation conv. +# Please Don't remove the following code. +# Currently, CI use cudnn V5.0 which not support dilation conv. # class TestCUDNNWithDilation(TestWithDilation): # def init_test_case(self): # self.pad = [1, 1, 1]