未验证 提交 1a0f3490 编写于 作者: X xiaoting 提交者: GitHub

[Zero-Dim] add upsample 0D test and fix api doc (#50237)

* add upsample 0d test

* update api references

* update api references

* update api reference
上级 1a4a1520
...@@ -1528,6 +1528,24 @@ class TestSundryAPI(unittest.TestCase): ...@@ -1528,6 +1528,24 @@ class TestSundryAPI(unittest.TestCase):
origin_result.numpy(), out3.numpy(), rtol=1e-05 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): def test_maseked_select(self):
x = paddle.rand([]) x = paddle.rand([])
x.stop_gradient = False x.stop_gradient = False
...@@ -2512,6 +2530,28 @@ class TestSundryAPIStatic(unittest.TestCase): ...@@ -2512,6 +2530,28 @@ class TestSundryAPIStatic(unittest.TestCase):
self.assertEqual(res2[0].shape, (2, 3, 12, 12)) self.assertEqual(res2[0].shape, (2, 3, 12, 12))
self.assertEqual(res2[1].shape, (2, 3, 6, 6)) 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() @prog_scope()
def test_maseked_select(self): def test_maseked_select(self):
x = paddle.rand([]) x = paddle.rand([])
......
...@@ -318,11 +318,11 @@ def interpolate( ...@@ -318,11 +318,11 @@ def interpolate(
size (list|tuple|Tensor|None): Output shape of image resize 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) 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. 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. 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 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. 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. Default: None.
mode (str): The resample method. It supports 'linear', 'area', 'nearest', 'bilinear', mode (str): The resample method. It supports 'linear', 'area', 'nearest', 'bilinear',
'bicubic' and 'trilinear' currently. Default: 'nearest' 'bicubic' and 'trilinear' currently. Default: 'nearest'
...@@ -870,12 +870,12 @@ def upsample( ...@@ -870,12 +870,12 @@ def upsample(
size (list|tuple|Tensor|None, optional): Output shape of image resize 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) 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. 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. 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 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. 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 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. Default: None.
mode (str, optional): The resample method. It supports 'linear', 'nearest', 'bilinear', mode (str, optional): The resample method. It supports 'linear', 'nearest', 'bilinear',
'bicubic' and 'trilinear' currently. Default: 'nearest' 'bicubic' and 'trilinear' currently. Default: 'nearest'
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册