From f76a7c5a2a640f5f9364fe87cc03a2c84fa1f03d Mon Sep 17 00:00:00 2001 From: LoneRanger <836253168@qq.com> Date: Thu, 2 Feb 2023 16:50:05 +0800 Subject: [PATCH] Fix Python IndexError of case18: paddle.nn.functional.conv3d_transpose (#50001) --- .../tests/unittests/test_conv3d_transpose_op.py | 13 +++++++++++++ python/paddle/nn/functional/conv.py | 6 ++++++ 2 files changed, 19 insertions(+) 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 bf223b8d59..aac4116739 100644 --- a/python/paddle/fluid/tests/unittests/test_conv3d_transpose_op.py +++ b/python/paddle/fluid/tests/unittests/test_conv3d_transpose_op.py @@ -555,5 +555,18 @@ class TestCUDNNWithGroups_NHWC(TestWithGroups): self.op_type = "conv3d_transpose" +class TestConv3dTranspose(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, 1]), dtype='float32' + ) + weight = paddle.to_tensor(np.reshape(array, [1]), dtype='float32') + paddle.nn.functional.conv3d_transpose(x, weight, bias=0) + + def test_type_error(self): + self.assertRaises(ValueError, self.error_weight_input) + + if __name__ == '__main__': unittest.main() diff --git a/python/paddle/nn/functional/conv.py b/python/paddle/nn/functional/conv.py index 82d25747ea..350eeaa383 100644 --- a/python/paddle/nn/functional/conv.py +++ b/python/paddle/nn/functional/conv.py @@ -1678,6 +1678,12 @@ def conv3d_transpose( x.shape ) ) + if len(weight.shape) != 5: + raise ValueError( + "Input weight should be 5D tensor, but received weight with the shape of {}".format( + weight.shape + ) + ) num_channels = x.shape[channel_dim] num_filters = weight.shape[1] if num_channels < 0: -- GitLab