未验证 提交 018e1699 编写于 作者: C Chen Long 提交者: GitHub

fix some docs (#29011)

* fix some docs test=develop;test=document_fix

* add code example test=develop;test=document_fix

* fix code example test=develop;test=document_fix

* fix code example test=develop;test=document_fix

* fix code example test=develop;test=document_fix
上级 5e26a154
......@@ -35,7 +35,8 @@ else:
# str and bytes related functions
def to_text(obj, encoding='utf-8', inplace=False):
"""
All string in PaddlePaddle should be represented as a literal string.
All string in PaddlePaddle should be represented as a literal string.
This function will convert object to a literal string without any encoding.
Especially, if the object type is a list or set container, we will iterate
all items in the object and convert them to literal string.
......@@ -53,6 +54,17 @@ def to_text(obj, encoding='utf-8', inplace=False):
Returns:
Decoded result of obj
Examples:
.. code-block:: python
import paddle
data = "paddlepaddle"
data = paddle.compat.to_text(data)
# paddlepaddle
"""
if obj is None:
return obj
......@@ -119,7 +131,8 @@ def _to_text(obj, encoding):
def to_bytes(obj, encoding='utf-8', inplace=False):
"""
All string in PaddlePaddle should be represented as a literal string.
All string in PaddlePaddle should be represented as a literal string.
This function will convert object to a bytes with specific encoding.
Especially, if the object type is a list or set container, we will iterate
all items in the object and convert them to bytes.
......@@ -138,6 +151,17 @@ def to_bytes(obj, encoding='utf-8', inplace=False):
Returns:
Decoded result of obj
Examples:
.. code-block:: python
import paddle
data = "paddlepaddle"
data = paddle.compat.to_bytes(data)
# b'paddlepaddle'
"""
if obj is None:
return obj
......
......@@ -2979,11 +2979,7 @@ class GroupNorm(layers.Layer):
class SpectralNorm(layers.Layer):
r"""
:alias_main: paddle.nn.SpectralNorm
:alias: paddle.nn.SpectralNorm,paddle.nn.layer.SpectralNorm,paddle.nn.layer.norm.SpectralNorm
:old_api: paddle.fluid.dygraph.SpectralNorm
"""
This interface is used to construct a callable object of the ``SpectralNorm`` class.
For more details, refer to code examples. It implements the function of the Spectral Normalization Layer.
This layer calculates the spectral normalization value of weight parameters of
......@@ -3031,13 +3027,13 @@ class SpectralNorm(layers.Layer):
Examples:
.. code-block:: python
import paddle.fluid as fluid
import numpy as np
import paddle
x = paddle.rand((2,8,32,32))
with fluid.dygraph.guard():
weight = np.random.random((2, 8, 32, 32)).astype('float32')
spectralNorm = fluid.dygraph.nn.SpectralNorm(weight.shape, dim=1, power_iters=2)
ret = spectralNorm(fluid.dygraph.base.to_variable(weight))
spectral_norm = paddle.nn.SpectralNorm(x.shape, dim=1, power_iters=2)
spectral_norm_out = spectral_norm(x)
print(spectral_norm_out.shape) # [2, 8, 32, 32]
"""
......
......@@ -3554,7 +3554,7 @@ def group_norm(input,
Refer to `Group Normalization <https://arxiv.org/abs/1803.08494>`_ .
Parameters:
input(Variable): 4-D Tensor, the data type is float32 or float64.
input(Tensor): 4-D Tensor, the data type is float32 or float64.
groups(int): The number of groups that divided from channels, the data type
is int32.
epsilon(float, optional): The small value added to the variance to prevent
......@@ -3576,26 +3576,17 @@ def group_norm(input,
property. For more information, please refer to :ref:`api_guide_Name` .
Returns:
Variable: A 4-D Tensor has same data type and data format with `input`.
Raises:
ValueError: If `data_layout` is neither 'NCHW' nor 'NHWC'.
ValueError: If `groups` is greater than the number of input channels.
ValueError: If `groups` is less than 1.
ShapeError: If the param_attr(Scale) is not 1-D Tensor.
ShapeError: If the param_attr(Scale)'s first dimension size is not equal to the input channels.
ShapeError: If the bias_attr(Bias) is not 1-D Tensor.
ShapeError: If the bias_attr(Bias)'s first dimension size is not equal to the input channels.
Tensor: A 4-D Tensor has same data type and data format with `input`.
Examples:
.. code-block:: python
import paddle.fluid as fluid
import paddle
paddle.enable_static()
data = fluid.data(name='data', shape=[None, 8, 32, 32], dtype='float32')
x = fluid.layers.group_norm(input=data, groups=4)
data = paddle.static.data(name='data', shape=[2, 8, 32, 32], dtype='float32')
x = paddle.static.nn.group_norm(input=data, groups=4)
print(x.shape) # [2, 8, 32, 32]
"""
helper = LayerHelper('group_norm', **locals())
dtype = helper.input_dtype()
......@@ -3685,7 +3676,7 @@ def spectral_norm(weight, dim=0, power_iters=1, eps=1e-12, name=None):
Refer to `Spectral Normalization <https://arxiv.org/abs/1802.05957>`_ .
Args:
weight(${weight_type}): ${weight_comment}
weight(Tensor): ${weight_comment}
dim(int): ${dim_comment}
power_iters(int): ${power_iters_comment}
eps(float): ${eps_comment}
......@@ -3694,7 +3685,7 @@ def spectral_norm(weight, dim=0, power_iters=1, eps=1e-12, name=None):
None by default.
Returns:
Variable: A tensor variable of weight parameters after spectral normalization.
Tensor: A tensor of weight parameters after spectral normalization.
The data type and shape is same as input tensor.
Examples:
......@@ -3703,8 +3694,9 @@ def spectral_norm(weight, dim=0, power_iters=1, eps=1e-12, name=None):
import paddle
paddle.enable_static()
weight = paddle.data(name='weight', shape=[2, 8, 32, 32], dtype='float32')
weight = paddle.static.data(name='weight', shape=[2, 8, 32, 32], dtype='float32')
x = paddle.static.nn.spectral_norm(weight=weight, dim=1, power_iters=2)
print(x.shape) # [2, 8, 32, 32]
"""
helper = LayerHelper('spectral_norm', **locals())
check_variable_and_dtype(weight, 'weight', ['float32', 'float64'],
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册