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 89339303567f2a50d67475a6890a0a3d2578f75d..e2c80404a5db597d873ab46cbbe37a957dd7f995 100644 --- a/python/paddle/fluid/tests/unittests/test_conv2d_transpose_op.py +++ b/python/paddle/fluid/tests/unittests/test_conv2d_transpose_op.py @@ -1013,6 +1013,17 @@ class TestConv2DTransposeRepr(unittest.TestCase): paddle.enable_static() +class TestConv2dTranspose(unittest.TestCase): + def error_weight_input(self): + array = np.array([1], dtype=np.float32) + x = paddle.to_tensor(np.reshape(array, [1, 1, 1, 1]), dtype='float32') + weight = paddle.to_tensor(np.reshape(array, [1]), dtype='float32') + paddle.nn.functional.conv2d_transpose(x, weight, bias=0) + + def test_type_error(self): + self.assertRaises(ValueError, self.error_weight_input) + + class TestTensorOutputSize1(UnittestBase): def init_info(self): self.shapes = [[2, 3, 8, 8]] diff --git a/python/paddle/nn/functional/conv.py b/python/paddle/nn/functional/conv.py index 350eeaa3832436f0e0986c4ab64d46a2bb5ad20d..2ad865c47995fd802000e69759d7c23d50b75d7a 100644 --- a/python/paddle/nn/functional/conv.py +++ b/python/paddle/nn/functional/conv.py @@ -1204,6 +1204,12 @@ def conv2d_transpose( x.shape ) ) + if len(weight.shape) != 4: + raise ValueError( + "Input weight should be 4D tensor, but received weight with the shape of {}".format( + weight.shape + ) + ) num_channels = x.shape[channel_dim] if num_channels < 0: raise ValueError(