From acb29ff8a71b1227f1e501daac2a04385355509c Mon Sep 17 00:00:00 2001 From: LielinJiang <50691816+LielinJiang@users.noreply.github.com> Date: Tue, 29 Dec 2020 11:23:49 +0800 Subject: [PATCH] Fix Conv2DTanspose bug when padding='same' (#29915) (#29936) * fix conv_transpose bug when padding=same --- .../tests/unittests/test_conv2d_transpose_layer.py | 1 + python/paddle/nn/layer/conv.py | 11 +++++------ 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/python/paddle/fluid/tests/unittests/test_conv2d_transpose_layer.py b/python/paddle/fluid/tests/unittests/test_conv2d_transpose_layer.py index f51baf50ec..83d2734318 100644 --- a/python/paddle/fluid/tests/unittests/test_conv2d_transpose_layer.py +++ b/python/paddle/fluid/tests/unittests/test_conv2d_transpose_layer.py @@ -219,6 +219,7 @@ def add_cases(suite): suite.addTest( Conv2DTransposeTestCase( methodName='runTest', padding="valid")) + suite.addTest(Conv2DTransposeTestCase(methodName='runTest', padding="same")) suite.addTest( Conv2DTransposeTestCase( methodName='runTest', filter_size=1, padding=(2, 3))) diff --git a/python/paddle/nn/layer/conv.py b/python/paddle/nn/layer/conv.py index 279f0648db..da76f0f11e 100644 --- a/python/paddle/nn/layer/conv.py +++ b/python/paddle/nn/layer/conv.py @@ -100,14 +100,12 @@ class _ConvNd(layers.Layer): self._padding_mode = padding_mode self.output_padding = output_padding if dims != 1: - self._padding, self._padding_algorithm = _update_padding_nd( + self._updated_padding, self._padding_algorithm = _update_padding_nd( padding, channel_last, dims) if transposed: filter_shape = [self._in_channels, out_channels // groups ] + self._kernel_size - self._padding, self._padding_algorithm = _update_padding_nd( - padding, channel_last, dims) else: if in_channels % groups != 0: raise ValueError("in_channels must be divisible by groups.") @@ -118,7 +116,8 @@ class _ConvNd(layers.Layer): self._reversed_padding_repeated_twice = _reverse_repeat_list( _paired_padding, 2) - self._padding, _ = _update_padding_nd(0, channel_last, dims) + self._updated_padding, self._padding_algorithm = _update_padding_nd( + 0, channel_last, dims) filter_shape = [out_channels, in_channels // groups ] + self._kernel_size @@ -634,7 +633,7 @@ class Conv2D(_ConvNd): self.weight, bias=self.bias, stride=self._stride, - padding=self._padding, + padding=self._updated_padding, padding_algorithm=self._padding_algorithm, dilation=self._dilation, groups=self._groups, @@ -951,7 +950,7 @@ class Conv3D(_ConvNd): self.weight, bias=self.bias, stride=self._stride, - padding=self._padding, + padding=self._updated_padding, padding_algorithm=self._padding_algorithm, dilation=self._dilation, groups=self._groups, -- GitLab