diff --git a/python/paddle/nn/functional/pooling.py b/python/paddle/nn/functional/pooling.py index f79a43fbc03a62d350ac44a8e29407bc0de5a72f..4bb53e1737bf80e6ecd03b9e6dd85246905103be 100755 --- a/python/paddle/nn/functional/pooling.py +++ b/python/paddle/nn/functional/pooling.py @@ -1273,24 +1273,20 @@ def max_pool3d(x, def adaptive_avg_pool1d(x, output_size, name=None): """ - This API implements adaptive average pooling 1d operation. - See more details in :ref:`api_nn_pooling_AdaptiveAvgPool1d` . + Adaptive average pooling 1d operation on :attr:`x` according to :attr:`output_size`. + + Notes: + See more details in :ref:`api_nn_pooling_AdaptiveAvgPool1d` . Args: - x (Tensor): The input tensor of pooling operator, which is a 3-D tensor - with shape [N, C, L]. The format of input tensor is NCL, - where N is batch size, C is the number of channels, L is the - length of the feature. The data type is float32 or float64. - output_size (int): The target output size. It must be an integer. - name(str, optional): For detailed information, please refer - to :ref:`api_guide_Name`. Usually name is no need to set and - None by default. + x (Tensor): The input Tensor of pooling, which is a 3-D tensor with shape :math:`[N, C, L]`, where :math:`N` is batch size, :math:`C` is the number of channels and :math:`L` is the length of the feature. The data type is float32 or float64. + output_size (int): The target output size. Its data type must be int. + name (str, optional): For details, please refer to :ref:`api_guide_Name`. Generally, no setting is required. Default: None. Returns: - Tensor: The output tensor of adaptive average pooling result. The data type is same - as input tensor. + Tensor: The result of 1D adaptive average pooling. Its data type is same as input. Examples: .. code-block:: python - :name: code-example1 + :name: adaptive_avg_pool1d-example # average adaptive pool1d # suppose input data in shape of [N, C, L], `output_size` is m or [m], diff --git a/python/paddle/nn/initializer/xavier.py b/python/paddle/nn/initializer/xavier.py index e11790df7dfbcdb4f94f730e3d4bea9d37ba5a52..d6570f9db2fe596d605013db811986b8353e3d34 100644 --- a/python/paddle/nn/initializer/xavier.py +++ b/python/paddle/nn/initializer/xavier.py @@ -22,28 +22,26 @@ class XavierNormal(XavierInitializer): This class implements the Xavier weight initializer from the paper `Understanding the difficulty of training deep feedforward neural networks `_ - by Xavier Glorot and Yoshua Bengio, using a normal distribution. - - The mean is 0 and the standard deviation is + by Xavier Glorot and Yoshua Bengio, using a normal distribution whose mean is :math:`0` and standard deviation is .. math:: - \sqrt{\frac{2.0}{fan\_in + fan\_out}} + \sqrt{\frac{2.0}{fan\_in + fan\_out}}. Args: - fan_in (float, optional): fan_in for Xavier initialization, It is - inferred from the tensor. The default value is None. - fan_out (float, optional): fan_out for Xavier initialization, it is - inferred from the tensor. The default value is None. - name(str, optional): The default value is None. Normally there is no need for user to set this - property. For more information, please refer to :ref:`api_guide_Name`. + fan_in (float, optional): fan_in for Xavier initialization, which is + inferred from the Tensor. The default value is None. + fan_out (float, optional): fan_out for Xavier initialization, which is + inferred from the Tensor. The default value is None. + name (str, optional): For details, please refer to :ref:`api_guide_Name`. Generally, no setting is required. Default: None. Returns: A parameter initialized by Xavier weight, using a normal distribution. Examples: .. code-block:: python + :name: initializer_XavierNormal-example import paddle @@ -81,25 +79,25 @@ class XavierUniform(XavierInitializer): This initializer is designed to keep the scale of the gradients approximately same in all the layers. In case of Uniform distribution, - the range is [-x, x], where + the range is :math:`[-x,x]`, where .. math:: - x = \sqrt{\frac{6.0}{fan\_in + fan\_out}} + x = \sqrt{\frac{6.0}{fan\_in + fan\_out}}. Args: - fan_in (float, optional): fan_in for Xavier initialization, it is - inferred from the tensor. The default value is None. - fan_out (float, optional): fan_out for Xavier initialization, it is - inferred from the tensor. The default value is None. - name(str, optional): The default value is None. Normally there is no need for user to set this - property. For more information, please refer to :ref:`api_guide_Name`. + fan_in (float, optional): fan_in for Xavier initialization, which is + inferred from the Tensor. The default value is None. + fan_out (float, optional): fan_out for Xavier initialization, which is + inferred from the Tensor. The default value is None. + name (str, optional): For details, please refer to :ref:`api_guide_Name`. Generally, no setting is required. Default: None. Returns: A parameter initialized by Xavier weight, using a uniform distribution. Examples: .. code-block:: python + :name: initializer_XavierUniform-example import paddle diff --git a/python/paddle/nn/layer/pooling.py b/python/paddle/nn/layer/pooling.py index 990d0b610786414189428fb3d1284e46969f171e..e7b6fc24afad8b268726f13fcb12f2cccc701380 100755 --- a/python/paddle/nn/layer/pooling.py +++ b/python/paddle/nn/layer/pooling.py @@ -619,42 +619,32 @@ class MaxPool3D(Layer): class AdaptiveAvgPool1D(Layer): r""" - This operation applies a 1D adaptive average pooling over an input signal composed - of several input planes, based on the input, output_size, return_mask parameters. - Input(X) and output(Out) are in NCL format, where N is batch - size, C is the number of channels, L is the length of the feature. - The output tensor shape will be [N, C, output_size]. + A 1D adaptive average pooling over an input signal composed + of several input planes, based on :attr:`output_size`. + Input and output are in NCL format, where N is batch + size, C is the number of channels and L is the length of the feature. + The shape of output will be :math:`[N, C, output\_size]`. - For average adaptive pool1d: + The formulation for average adaptive pool1d is .. math:: - lstart &= floor(i * L_{in} / L_{out}) + lstart &= \lfloor i * L_{in} / L_{out}\rfloor, - lend &= ceil((i + 1) * L_{in} / L_{out}) + lend &= \lceil(i + 1) * L_{in} / L_{out}\rceil, - Output(i) &= \frac{ \sum Input[lstart:lend]}{lend - lstart} + Output(i) &= \frac{\sum Input[lstart:lend]}{lend - lstart}. Parameters: - output_size(int): The target output size. It must be an integer. - name(str, optional): For detailed information, please refer to :ref:`api_guide_Name`. - Usually name is no need to set and None by default. + output_size(int): The target output size. Its data type must be int. + name (str, optional): For details, please refer to :ref:`api_guide_Name`. Generally, no setting is required. Default: None. Returns: - A callable object of AdaptiveAvgPool1D. - - Raises: - ValueError: 'output_size' should be an integer. - - Shape: - - x(Tensor): 3-D tensor. The input tensor of adaptive avg pool1d operator, which is a 3-D tensor. - The data type can be float32, float64. - - output(Tensor): 3-D tensor. The output tensor of adaptive avg pool1d operator, which is a 3-D tensor. - The data type is same as input x. + A callable object for computing 1D adaptive average pooling. Examples: .. code-block:: python - + :name: AdaptiveAvgPool1D-example # average adaptive pool1d # suppose input data in shape of [N, C, L], `output_size` is m or [m], # output shape is [N, C, m], adaptive pool divide L dimension diff --git a/python/paddle/tensor/creation.py b/python/paddle/tensor/creation.py index 67547212bb196f75bcd4dec14a6f6b32f8d45e27..521839af902b5606bf5189b55a5e6df1ae866e38 100644 --- a/python/paddle/tensor/creation.py +++ b/python/paddle/tensor/creation.py @@ -1479,22 +1479,21 @@ def empty_like(x, dtype=None, name=None): def assign(x, output=None): """ - The OP copies the :attr:`x` to the :attr:`output`. + Copy value of the :attr:`x` to the :attr:`output`. Parameters: - x (Tensor|np.ndarray|list|tuple|scalar): A tensor, numpy ndarray, tuple/list of scalar, - or scalar. Its data type supports float16, float32, float64, int32, int64, and bool. - Note: the float64 data will be converted to float32 because of current platform protobuf + x (Tensor|np.ndarray|list|tuple|scalar): A Tensor, numpy ndarray, tuple/list of scalar, + or scalar. Its data type can be float16, float32, float64, int32, int64 or bool. Note: the float64 data will be converted to float32 because of current platform protobuf data limitation. - output (Tensor, optional): A tensor. If :attr:`output` is None, a new tensor will - be created as :attr:`output`. Default: None. + output (Tensor, optional): A Tensor. If :attr:`output` is None, a new Tensor will be created as :attr:`output`. Default: None. Returns: - Tensor: A tensor with the same shape, data type and value as :attr:`x`. + Tensor: A Tensor with the same shape, data type and value as :attr:`x`. Examples: .. code-block:: python - + :name: assign-example + import paddle import numpy as np data = paddle.full(shape=[3, 2], fill_value=2.5, dtype='float64') # [[2.5, 2.5], [2.5, 2.5], [2.5, 2.5]] diff --git a/python/paddle/tensor/search.py b/python/paddle/tensor/search.py index 42087ac7dafa396b2f524ed437df8655e6f9f992..94a05294aaa63cc8c56df5b01ce3c6b6ad429e93 100644 --- a/python/paddle/tensor/search.py +++ b/python/paddle/tensor/search.py @@ -572,49 +572,46 @@ def mode(x, axis=-1, keepdim=False, name=None): def where(condition, x=None, y=None, name=None): r""" - Return a tensor of elements selected from either $x$ or $y$, depending on $condition$. - - **Note**: - ``paddle.where(condition)`` is identical to ``paddle.nonzero(condition, as_tuple=True)``. + Return a Tensor of elements selected from either :attr:`x` or :attr:`y` according to corresponding elements of :attr:`condition`. Concretely, .. math:: - out_i = - \begin{cases} - x_i, \quad \text{if} \ condition_i \ is \ True \\ - y_i, \quad \text{if} \ condition_i \ is \ False \\ - \end{cases} + out_i = + \begin{cases} + x_i, & \text{if} \ condition_i \ \text{is} \ True \\ + y_i, & \text{if} \ condition_i \ \text{is} \ False \\ + \end{cases}. + Notes: + ``numpy.where(condition)`` is identical to ``paddle.nonzero(condition, as_tuple=True)``, please refer to :ref:`api_tensor_search_nonzero`. Args: - condition(Tensor): The condition to choose x or y. When True(nonzero), yield x, otherwise yield y. - x(Tensor or Scalar, optional): x is a Tensor or Scalar with data type float32, float64, int32, int64. Either both or neither of x and y should be given. - y(Tensor or Scalar, optional): y is a Tensor or Scalar with data type float32, float64, int32, int64. Either both or neither of x and y should be given. - - name(str, optional): The default value is None. Normally there is no - need for user to set this property. For more information, please - refer to :ref:`api_guide_Name`. + condition (Tensor): The condition to choose x or y. When True (nonzero), yield x, otherwise yield y. + x (Tensor|scalar, optional): A Tensor or scalar to choose when the condition is True with data type of float32, float64, int32 or int64. Either both or neither of x and y should be given. + y (Tensor|scalar, optional): A Tensor or scalar to choose when the condition is False with data type of float32, float64, int32 or int64. Either both or neither of x and y should be given. + name (str, optional): For details, please refer to :ref:`api_guide_Name`. Generally, no setting is required. Default: None. Returns: - Tensor: A Tensor with the same data dype as x. + Tensor: A Tensor with the same shape as :attr:`condition` and same data type as :attr:`x` and :attr:`y`. Examples: .. code-block:: python + :name:where-example - import paddle + import paddle - x = paddle.to_tensor([0.9383, 0.1983, 3.2, 1.2]) - y = paddle.to_tensor([1.0, 1.0, 1.0, 1.0]) - out = paddle.where(x>1, x, y) + x = paddle.to_tensor([0.9383, 0.1983, 3.2, 1.2]) + y = paddle.to_tensor([1.0, 1.0, 1.0, 1.0]) + out = paddle.where(x>1, x, y) - print(out) - #out: [1.0, 1.0, 3.2, 1.2] + print(out) + #out: [1.0, 1.0, 3.2, 1.2] - out = paddle.where(x>1) - print(out) - #out: (Tensor(shape=[2, 1], dtype=int64, place=CPUPlace, stop_gradient=True, - # [[2], - # [3]]),) + out = paddle.where(x>1) + print(out) + #out: (Tensor(shape=[2, 1], dtype=int64, place=CPUPlace, stop_gradient=True, + # [[2], + # [3]]),) """ if np.isscalar(x): x = paddle.full([1], x, np.array([x]).dtype.name)