From b53887fdd92647433bc54d71fe2b092440539f2f Mon Sep 17 00:00:00 2001 From: WeiXin Date: Wed, 1 Sep 2021 12:43:48 +0800 Subject: [PATCH] fix bug:When axes in paddle.slice is a tuple, an error occurs. (#35267) * fix bug:When axes in paddle.sile is a tuple, an error occurs. * polish code. --- python/paddle/fluid/layers/nn.py | 1 + python/paddle/fluid/tests/unittests/test_slice_op.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/python/paddle/fluid/layers/nn.py b/python/paddle/fluid/layers/nn.py index 59dfec005d8..4216384b6f8 100755 --- a/python/paddle/fluid/layers/nn.py +++ b/python/paddle/fluid/layers/nn.py @@ -10977,6 +10977,7 @@ def slice(input, axes, starts, ends): ends_tensor = None if isinstance(axes, (list, tuple)): + axes = list(axes) if len(axes) == 0: raise ValueError( "Input axes should not be an empty list/tuple.") diff --git a/python/paddle/fluid/tests/unittests/test_slice_op.py b/python/paddle/fluid/tests/unittests/test_slice_op.py index f69993c52ae..a80dc87525a 100644 --- a/python/paddle/fluid/tests/unittests/test_slice_op.py +++ b/python/paddle/fluid/tests/unittests/test_slice_op.py @@ -705,7 +705,7 @@ class TestInferShape(unittest.TestCase): np_slice = x_arr[:, :, 0:1] self.assertTrue(np.array_equal(pp_slice, np_slice)) - pp_slice = paddle.slice(x, [-100, ], [0], [1]) + pp_slice = paddle.slice(x, (-100, ), [0], [1]) np_slice = x_arr[0:1] self.assertTrue(np.array_equal(pp_slice, np_slice)) -- GitLab