diff --git a/python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py b/python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py index 3170f3f62cc8521cd55783f5c645515ac048b0ba..190f0eaac8911ca035c3388fa6cfcde759d042ed 100644 --- a/python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py +++ b/python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py @@ -1528,6 +1528,24 @@ class TestSundryAPI(unittest.TestCase): origin_result.numpy(), out3.numpy(), rtol=1e-05 ) + def test_upsample(self): + from paddle.nn.functional import upsample + + input_x = paddle.rand([2, 3, 6, 6]) + input_x.stop_gradient = False + + output_size = [ + paddle.full([], 12, dtype="int32"), + paddle.full([], 12, dtype="int32"), + ] + out1 = upsample( + x=input_x, size=output_size, mode="bilinear", align_corners=False + ) + out1.backward() + + self.assertEqual(out1.shape, [2, 3, 12, 12]) + self.assertEqual(input_x.grad.shape, [2, 3, 6, 6]) + def test_maseked_select(self): x = paddle.rand([]) x.stop_gradient = False @@ -2512,6 +2530,28 @@ class TestSundryAPIStatic(unittest.TestCase): self.assertEqual(res2[0].shape, (2, 3, 12, 12)) self.assertEqual(res2[1].shape, (2, 3, 6, 6)) + @prog_scope() + def test_upsample(self): + from paddle.nn.functional import upsample + + input_x = paddle.rand([2, 3, 6, 6]) + input_x.stop_gradient = False + + output_size = [ + paddle.full([], 12, dtype="int32"), + paddle.full([], 12, dtype="int32"), + ] + + out1 = upsample( + x=input_x, size=output_size, mode="bilinear", align_corners=False + ) + paddle.static.append_backward(out1.sum()) + prog = paddle.static.default_main_program() + res1 = self.exe.run(prog, feed={}, fetch_list=[out1, input_x.grad_name]) + + self.assertEqual(res1[0].shape, (2, 3, 12, 12)) + self.assertEqual(res1[1].shape, (2, 3, 6, 6)) + @prog_scope() def test_maseked_select(self): x = paddle.rand([]) diff --git a/python/paddle/nn/functional/common.py b/python/paddle/nn/functional/common.py index 05968d593ebbb896a61001b889cd0709517ad965..5fa2c0eda0dbe7248e3b98b4410b282bdc8f39a6 100644 --- a/python/paddle/nn/functional/common.py +++ b/python/paddle/nn/functional/common.py @@ -318,11 +318,11 @@ def interpolate( size (list|tuple|Tensor|None): Output shape of image resize layer, the shape is (out_w, ) when input is a 3-D Tensor, the shape is (out_h, out_w) when input is a 4-D Tensor and is (out_d, out_h, out_w) when input is a 5-D Tensor. - Default: None. If a list/tuple, each element can be an integer or a Tensor of shape: [1]. + Default: None. If a list/tuple, each element can be an integer or a Tensor of shape: [1] or []. If a Tensor, its dimensions size should be a 1. scale_factor (float|Tensor|list|tuple|None): The multiplier for the input height or width. At least one of :attr:`size` or :attr:`scale_factor` must be set. - And :attr:`size` has a higher priority than :attr:`scale_factor`.Has to match input size if it is either a list or a tuple or a Tensor. + And :attr:`size` has a higher priority than :attr:`scale_factor`.Has to match input size if it is either a list or a tuple or a Tensor.If a list/tuple, each element can be an integer or a Tensor of shape: [1] or []. Default: None. mode (str): The resample method. It supports 'linear', 'area', 'nearest', 'bilinear', 'bicubic' and 'trilinear' currently. Default: 'nearest' @@ -870,12 +870,12 @@ def upsample( size (list|tuple|Tensor|None, optional): Output shape of image resize layer, the shape is (out_w, ) when input is a 3-D Tensor, the shape is (out_h, out_w) when input is a 4-D Tensor and is (out_d, out_h, out_w) when input is a 5-D Tensor. - Default: None. If a list/tuple, each element can be an integer or a Tensor of shape: [1]. + Default: None. If a list/tuple, each element can be an integer or a Tensor of shape: [1] or []. If a Tensor , its dimensions size should be a 1. scale_factor (float|Tensor|list|tuple|None, optional): The multiplier for the input height or width. At least one of :attr:`size` or :attr:`scale_factor` must be set. And :attr:`size` has a higher priority than :attr:`scale_factor`.Has to match input size if - it is either a list or a tuple or a Tensor. + it is either a list or a tuple or a Tensor. If a list/tuple, each element can be an integer or a Tensor of shape: [1] or []. Default: None. mode (str, optional): The resample method. It supports 'linear', 'nearest', 'bilinear', 'bicubic' and 'trilinear' currently. Default: 'nearest'