未验证 提交 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
...@@ -36,6 +36,7 @@ else: ...@@ -36,6 +36,7 @@ else:
def to_text(obj, encoding='utf-8', inplace=False): 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. 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 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. all items in the object and convert them to literal string.
...@@ -53,6 +54,17 @@ def to_text(obj, encoding='utf-8', inplace=False): ...@@ -53,6 +54,17 @@ def to_text(obj, encoding='utf-8', inplace=False):
Returns: Returns:
Decoded result of obj Decoded result of obj
Examples:
.. code-block:: python
import paddle
data = "paddlepaddle"
data = paddle.compat.to_text(data)
# paddlepaddle
""" """
if obj is None: if obj is None:
return obj return obj
...@@ -120,6 +132,7 @@ def _to_text(obj, encoding): ...@@ -120,6 +132,7 @@ def _to_text(obj, encoding):
def to_bytes(obj, encoding='utf-8', inplace=False): 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. 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 Especially, if the object type is a list or set container, we will iterate
all items in the object and convert them to bytes. all items in the object and convert them to bytes.
...@@ -138,6 +151,17 @@ def to_bytes(obj, encoding='utf-8', inplace=False): ...@@ -138,6 +151,17 @@ def to_bytes(obj, encoding='utf-8', inplace=False):
Returns: Returns:
Decoded result of obj Decoded result of obj
Examples:
.. code-block:: python
import paddle
data = "paddlepaddle"
data = paddle.compat.to_bytes(data)
# b'paddlepaddle'
""" """
if obj is None: if obj is None:
return obj return obj
......
...@@ -2979,11 +2979,7 @@ class GroupNorm(layers.Layer): ...@@ -2979,11 +2979,7 @@ class GroupNorm(layers.Layer):
class SpectralNorm(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. 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. 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 This layer calculates the spectral normalization value of weight parameters of
...@@ -3031,13 +3027,13 @@ class SpectralNorm(layers.Layer): ...@@ -3031,13 +3027,13 @@ class SpectralNorm(layers.Layer):
Examples: Examples:
.. code-block:: python .. code-block:: python
import paddle.fluid as fluid import paddle
import numpy as np x = paddle.rand((2,8,32,32))
with fluid.dygraph.guard(): spectral_norm = paddle.nn.SpectralNorm(x.shape, dim=1, power_iters=2)
weight = np.random.random((2, 8, 32, 32)).astype('float32') spectral_norm_out = spectral_norm(x)
spectralNorm = fluid.dygraph.nn.SpectralNorm(weight.shape, dim=1, power_iters=2)
ret = spectralNorm(fluid.dygraph.base.to_variable(weight)) print(spectral_norm_out.shape) # [2, 8, 32, 32]
""" """
......
...@@ -3554,7 +3554,7 @@ def group_norm(input, ...@@ -3554,7 +3554,7 @@ def group_norm(input,
Refer to `Group Normalization <https://arxiv.org/abs/1803.08494>`_ . Refer to `Group Normalization <https://arxiv.org/abs/1803.08494>`_ .
Parameters: 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 groups(int): The number of groups that divided from channels, the data type
is int32. is int32.
epsilon(float, optional): The small value added to the variance to prevent epsilon(float, optional): The small value added to the variance to prevent
...@@ -3576,26 +3576,17 @@ def group_norm(input, ...@@ -3576,26 +3576,17 @@ def group_norm(input,
property. For more information, please refer to :ref:`api_guide_Name` . property. For more information, please refer to :ref:`api_guide_Name` .
Returns: Returns:
Variable: A 4-D Tensor has same data type and data format with `input`. Tensor: 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.
Examples: Examples:
.. code-block:: python .. code-block:: python
import paddle.fluid as fluid
import paddle import paddle
paddle.enable_static() paddle.enable_static()
data = fluid.data(name='data', shape=[None, 8, 32, 32], dtype='float32') data = paddle.static.data(name='data', shape=[2, 8, 32, 32], dtype='float32')
x = fluid.layers.group_norm(input=data, groups=4) x = paddle.static.nn.group_norm(input=data, groups=4)
print(x.shape) # [2, 8, 32, 32]
""" """
helper = LayerHelper('group_norm', **locals()) helper = LayerHelper('group_norm', **locals())
dtype = helper.input_dtype() dtype = helper.input_dtype()
...@@ -3685,7 +3676,7 @@ def spectral_norm(weight, dim=0, power_iters=1, eps=1e-12, name=None): ...@@ -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>`_ . Refer to `Spectral Normalization <https://arxiv.org/abs/1802.05957>`_ .
Args: Args:
weight(${weight_type}): ${weight_comment} weight(Tensor): ${weight_comment}
dim(int): ${dim_comment} dim(int): ${dim_comment}
power_iters(int): ${power_iters_comment} power_iters(int): ${power_iters_comment}
eps(float): ${eps_comment} eps(float): ${eps_comment}
...@@ -3694,7 +3685,7 @@ def spectral_norm(weight, dim=0, power_iters=1, eps=1e-12, name=None): ...@@ -3694,7 +3685,7 @@ def spectral_norm(weight, dim=0, power_iters=1, eps=1e-12, name=None):
None by default. None by default.
Returns: 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. The data type and shape is same as input tensor.
Examples: Examples:
...@@ -3703,8 +3694,9 @@ def spectral_norm(weight, dim=0, power_iters=1, eps=1e-12, name=None): ...@@ -3703,8 +3694,9 @@ def spectral_norm(weight, dim=0, power_iters=1, eps=1e-12, name=None):
import paddle import paddle
paddle.enable_static() 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) 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()) helper = LayerHelper('spectral_norm', **locals())
check_variable_and_dtype(weight, 'weight', ['float32', 'float64'], 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.
先完成此消息的编辑!
想要评论请 注册