未验证 提交 cbade6ad 编写于 作者: C Candy2Tang 提交者: GitHub

[xdoctest][task 114] Reformat example code with google style in...

[xdoctest][task 114] Reformat example code with google style in python/paddle/nn/functional/vision.py (#56230)

* [xdoctest][task 114] test=docs_preview

* test=document_fix

* test=document_fix

* adjust indent

---------
Co-authored-by: NSigureMo <sigure.qaq@gmail.com>
上级 12134b2e
...@@ -46,28 +46,27 @@ def affine_grid(theta, out_shape, align_corners=True, name=None): ...@@ -46,28 +46,27 @@ def affine_grid(theta, out_shape, align_corners=True, name=None):
.. code-block:: python .. code-block:: python
import paddle >>> import paddle
import paddle.nn.functional as F >>> import paddle.nn.functional as F
# theta shape = [1, 2, 3] >>> # theta.shape = [1, 2, 3]
theta = paddle.to_tensor([[[-0.7, -0.4, 0.3], >>> theta = paddle.to_tensor([[[-0.7, -0.4, 0.3],
[ 0.6, 0.5, 1.5]]], dtype="float32") ... [ 0.6, 0.5, 1.5]]], dtype="float32")
y_t = F.affine_grid( >>> y_t = F.affine_grid(
theta, ... theta,
[1, 2, 3, 3], ... [1, 2, 3, 3],
align_corners=False) ... align_corners=False
print(y_t) ... )
>>> print(y_t)
#[[[[ 1.0333333 0.76666665] Tensor(shape=[1, 3, 3, 2], dtype=float32, place=Place(cpu), stop_gradient=True,
# [ 0.76666665 1.0999999 ] [[[[ 1.03333330, 0.76666665],
# [ 0.5 1.4333333 ]] [ 0.56666672, 1.16666663],
# [ 0.10000002, 1.56666672]],
# [[ 0.5666667 1.1666666 ] [[ 0.76666665, 1.09999990],
# [ 0.3 1.5 ] [ 0.30000001, 1.50000000],
# [ 0.03333333 1.8333334 ]] [-0.16666666, 1.90000010]],
# [[ 0.50000000, 1.43333328],
# [[ 0.10000002 1.5666667 ] [ 0.03333333, 1.83333337],
# [-0.16666666 1.9000001 ] [-0.43333334, 2.23333335]]]])
# [-0.43333334 2.2333333 ]]]]
""" """
if not isinstance(theta, Variable): if not isinstance(theta, Variable):
raise ValueError("The theta should be a Tensor.") raise ValueError("The theta should be a Tensor.")
...@@ -230,38 +229,38 @@ def grid_sample( ...@@ -230,38 +229,38 @@ def grid_sample(
.. code-block:: python .. code-block:: python
import paddle >>> import paddle
import paddle.nn.functional as F >>> import paddle.nn.functional as F
# x shape=[1, 1, 3, 3] >>> # x shape=[1, 1, 3, 3]
x = paddle.to_tensor([[[[-0.6, 0.8, -0.5], >>> x = paddle.to_tensor([[[[-0.6, 0.8, -0.5],
[-0.5, 0.2, 1.2], ... [-0.5, 0.2, 1.2],
[ 1.4, 0.3, -0.2]]]],dtype='float64') ... [ 1.4, 0.3, -0.2]]]], dtype='float64')
# grid shape = [1, 3, 4, 2] >>> # grid.shape = [1, 3, 4, 2]
grid = paddle.to_tensor([[[[ 0.2, 0.3], >>> grid = paddle.to_tensor([[[[ 0.2, 0.3],
[-0.4, -0.3], ... [-0.4, -0.3],
[-0.9, 0.3], ... [-0.9, 0.3],
[-0.9, -0.6]], ... [-0.9, -0.6]],
[[ 0.4, 0.1], ... [[ 0.4, 0.1],
[ 0.9, -0.8], ... [ 0.9, -0.8],
[ 0.4, 0.5], ... [ 0.4, 0.5],
[ 0.5, -0.2]], ... [ 0.5, -0.2]],
[[ 0.1, -0.8], ... [[ 0.1, -0.8],
[-0.3, -1. ], ... [-0.3, -1. ],
[ 0.7, 0.4], ... [ 0.7, 0.4],
[ 0.2, 0.8]]]],dtype='float64') ... [ 0.2, 0.8]]]], dtype='float64')
y_t = F.grid_sample( >>> y_t = F.grid_sample(
x, ... x,
grid, ... grid,
mode='bilinear', ... mode='bilinear',
padding_mode='border', ... padding_mode='border',
align_corners=True) ... align_corners=True
print(y_t) ... )
>>> print(y_t)
# output shape = [1, 1, 3, 4] Tensor(shape=[1, 1, 3, 4], dtype=float64, place=Place(cpu), stop_gradient=True,
# [[[[ 0.34 0.016 0.086 -0.448] [[[[ 0.34000000, 0.01600000, 0.08600000, -0.44800000],
# [ 0.55 -0.076 0.35 0.59 ] [ 0.55000000, -0.07600000, 0.35000000, 0.59000000],
# [ 0.596 0.38 0.52 0.24 ]]]] [ 0.59600000, 0.38000000, 0.52000000, 0.24000000]]]])
""" """
_modes = ['bilinear', 'nearest'] _modes = ['bilinear', 'nearest']
...@@ -358,13 +357,13 @@ def pixel_shuffle(x, upscale_factor, data_format="NCHW", name=None): ...@@ -358,13 +357,13 @@ def pixel_shuffle(x, upscale_factor, data_format="NCHW", name=None):
Examples: Examples:
.. code-block:: python .. code-block:: python
import paddle >>> import paddle
import paddle.nn.functional as F >>> import paddle.nn.functional as F
x = paddle.randn(shape=[2,9,4,4]) >>> x = paddle.randn(shape=[2,9,4,4])
out_var = F.pixel_shuffle(x, 3) >>> out_var = F.pixel_shuffle(x, 3)
print(out_var.shape) >>> print(out_var.shape)
# [2, 1, 12, 12] [2, 1, 12, 12]
""" """
if not isinstance(upscale_factor, int): if not isinstance(upscale_factor, int):
raise TypeError("upscale factor must be int type") raise TypeError("upscale factor must be int type")
...@@ -411,12 +410,12 @@ def pixel_unshuffle(x, downscale_factor, data_format="NCHW", name=None): ...@@ -411,12 +410,12 @@ def pixel_unshuffle(x, downscale_factor, data_format="NCHW", name=None):
Examples: Examples:
.. code-block:: python .. code-block:: python
import paddle >>> import paddle
import paddle.nn.functional as F >>> import paddle.nn.functional as F
x = paddle.randn([2, 1, 12, 12]) >>> x = paddle.randn([2, 1, 12, 12])
out = F.pixel_unshuffle(x, 3) >>> out = F.pixel_unshuffle(x, 3)
print(out.shape) >>> print(out.shape)
# [2, 9, 4, 4] [2, 9, 4, 4]
""" """
if len(x.shape) != 4: if len(x.shape) != 4:
raise ValueError( raise ValueError(
...@@ -476,23 +475,27 @@ def channel_shuffle(x, groups, data_format="NCHW", name=None): ...@@ -476,23 +475,27 @@ def channel_shuffle(x, groups, data_format="NCHW", name=None):
Examples: Examples:
.. code-block:: python .. code-block:: python
import paddle >>> import paddle
import paddle.nn.functional as F >>> import paddle.nn.functional as F
x = paddle.arange(0, 0.6, 0.1, 'float32') >>> x = paddle.arange(0, 0.6, 0.1, 'float32')
x = paddle.reshape(x, [1, 6, 1, 1]) >>> x = paddle.reshape(x, [1, 6, 1, 1])
# [[[[0. ]], >>> print(x)
# [[0.10000000]], Tensor(shape=[1, 6, 1, 1], dtype=float32, place=Place(cpu), stop_gradient=True,
# [[0.20000000]], [[[[0. ]],
# [[0.30000001]], [[0.10000000]],
# [[0.40000001]], [[0.20000000]],
# [[0.50000000]]]] [[0.30000001]],
y = F.channel_shuffle(x, 3) [[0.40000001]],
# [[[[0. ]], [[0.50000000]]]])
# [[0.20000000]], >>> y = F.channel_shuffle(x, 3)
# [[0.40000001]], >>> print(y)
# [[0.10000000]], Tensor(shape=[1, 6, 1, 1], dtype=float32, place=Place(cpu), stop_gradient=True,
# [[0.30000001]], [[[[0. ]],
# [[0.50000000]]]] [[0.20000000]],
[[0.40000001]],
[[0.10000000]],
[[0.30000001]],
[[0.50000000]]]])
""" """
if len(x.shape) != 4: if len(x.shape) != 4:
raise ValueError( raise ValueError(
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册