diff --git a/python/paddle/nn/functional/loss.py b/python/paddle/nn/functional/loss.py index 87a89ea1e4293d012ac44c7df873fd56a69f9ec8..1e34e9c9bebe041bacf691683825483776dee0f8 100755 --- a/python/paddle/nn/functional/loss.py +++ b/python/paddle/nn/functional/loss.py @@ -2346,21 +2346,21 @@ def cross_entropy( ): r""" - By default, this operator implements the cross entropy loss function with softmax. This function + By default, the cross entropy loss function is implemented using softmax. This function combines the calculation of the softmax operation and the cross entropy loss function to provide a more numerically stable computing. - This operator will calculate the cross entropy loss function without softmax when use_softmax=False. + Calculate the cross entropy loss function without softmax when use_softmax=False. - By default, this operator will calculate the mean of the result, and you can also affect + By default, calculate the mean of the result, and you can also affect the default behavior by using the reduction parameter. Please refer to the part of parameters for details. - This operator can be used to calculate the softmax cross entropy loss with soft and hard labels. + Can be used to calculate the softmax cross entropy loss with soft and hard labels. Where, the hard labels mean the actual label value, 0, 1, 2, etc. And the soft labels mean the probability of the actual label, 0.6, 0.8, 0.2, etc. - The calculation of this operator includes the following two steps. + The calculation includes the following two steps. - **1.softmax cross entropy** @@ -3480,7 +3480,7 @@ def cosine_embedding_loss( input1, input2, label, margin=0, reduction='mean', name=None ): r""" - This operator computes the cosine embedding loss of Tensor ``input1``, ``input2`` and ``label`` as follows. + Compute the cosine embedding loss of Tensor ``input1``, ``input2`` and ``label`` as follows. If label = 1, then the loss value can be calculated as follow: @@ -3496,12 +3496,12 @@ def cosine_embedding_loss( .. math:: cos(x1, x2) = \frac{x1 \cdot{} x2}{\Vert x1 \Vert_2 * \Vert x2 \Vert_2} - Parameters: - input1 (Tensor): tensor with shape: [N, M] or [M], 'N' means batch size, 'M' means the length of input array. + Parameters: + input1 (Tensor): tensor with shape: [N, M] or [M], 'N' means batch size, which can be 0, 'M' means the length of input array. Available dtypes are float32, float64. - input2 (Tensor): tensor with shape: [N, M] or [M], 'N' means batch size, 'M' means the length of input array. + input2 (Tensor): tensor with shape: [N, M] or [M], 'N' means batch size, which can be 0, 'M' means the length of input array. Available dtypes are float32, float64. - label (Tensor): tensor with shape: [N] or [1]. The target labels values should be -1 or 1. + label (Tensor): tensor with shape: [N] or [1], 'N' means the length of input array. The target labels values should be -1 or 1. Available dtypes are int32, int64, float32, float64. margin (float, optional): Should be a number from :math:`-1` to :math:`1`, :math:`0` to :math:`0.5` is suggested. If :attr:`margin` is missing, the diff --git a/python/paddle/nn/functional/vision.py b/python/paddle/nn/functional/vision.py index 2cb448f9fdb2c456fb807f3a4fb4f0367decdf31..a246a8eb76bfe3c1374b1493f6fb19586db49c41 100644 --- a/python/paddle/nn/functional/vision.py +++ b/python/paddle/nn/functional/vision.py @@ -465,12 +465,12 @@ def pixel_unshuffle(x, downscale_factor, data_format="NCHW", name=None): def channel_shuffle(x, groups, data_format="NCHW", name=None): """ This API implements channel shuffle operation. - See more details in :ref:`api_nn_vision_ChannelShuffle` . + See more details in :ref:`api_nn_vision_ChannelShuffle`. Parameters: x (Tensor): 4-D tensor, the data type should be float32 or float64. groups (int): Number of groups to divide channels in. - data_format (str): The data format of the input and output data. An optional string of NCHW or NHWC. The default is NCHW. When it is NCHW, the data is stored in the order of [batch_size, input_channels, input_height, input_width]. + data_format (str, optional): The data format of the input and output data. An optional string of NCHW or NHWC. The default is NCHW. When it is NCHW, the data is stored in the order of [batch_size, input_channels, input_height, input_width]. name (str, optional): Name for the operation (optional, default is None). Normally there is no need for user to set this property. For more information, please refer to :ref:`api_guide_Name`. Returns: diff --git a/python/paddle/nn/layer/loss.py b/python/paddle/nn/layer/loss.py index cd2e6b5177043df1afc367f10d6be271c2f01f89..f9e9a4ec152b701e4a31d25bd1634540049ff7f7 100644 --- a/python/paddle/nn/layer/loss.py +++ b/python/paddle/nn/layer/loss.py @@ -138,21 +138,21 @@ class BCEWithLogitsLoss(Layer): class CrossEntropyLoss(Layer): r""" - By default, this operator implements the cross entropy loss function with softmax. This function + By default, the cross entropy loss function is implemented using softmax. This function combines the calculation of the softmax operation and the cross entropy loss function to provide a more numerically stable computing. - This operator will calculate the cross entropy loss function without softmax when use_softmax=False. + Calculate the cross entropy loss function without softmax when use_softmax=False. - By default, this operator will calculate the mean of the result, and you can also affect + By default, calculate the mean of the result, and you can also affect the default behavior by using the reduction parameter. Please refer to the part of parameters for details. - This operator can be used to calculate the softmax cross entropy loss with soft and hard labels. + Can be used to calculate the softmax cross entropy loss with soft and hard labels. Where, the hard labels mean the actual label value, 0, 1, 2, etc. And the soft labels mean the probability of the actual label, 0.6, 0.8, 0.2, etc. - The calculation of this operator includes the following two steps. + The calculation includes the following two steps. - **I.softmax cross entropy** @@ -277,8 +277,8 @@ class CrossEntropyLoss(Layer): Shape: - - **input** (Tensor), the data type is float32, float64. Shape is - :math:`[N_1, N_2, ..., N_k, C]`, where C is number of classes , ``k >= 1`` . + - **input** (Tensor), the data type is float32, float64. Shape is :math:`[N_1, N_2, ..., N_k, C]`, where C is number of classes, ``k >= 1`` . + Note: 1. when use_softmax=True, it expects unscaled logits. This operator should not be used with the @@ -1413,11 +1413,11 @@ class CosineEmbeddingLoss(Layer): For more information, please refer to :ref:`api_guide_Name`. Shape: - input1 (Tensor): tensor with shape: [N, M] or [M], 'N' means batch size, 'M' means the length of input array. + input1 (Tensor): tensor with shape: [N, M] or [M], 'N' means batch size, which can be 0, 'M' means the length of input array. Available dtypes are float32, float64. - input2 (Tensor): tensor with shape: [N, M] or [M], 'N' means batch size, 'M' means the length of input array. + input2 (Tensor): tensor with shape: [N, M] or [M], 'N' means batch size, which can be 0, 'M' means the length of input array. Available dtypes are float32, float64. - label (Tensor): tensor with shape: [N] or [1]. The target labels values should be -1 or 1. + label (Tensor): tensor with shape: [N] or [1], 'N' means the length of input array. The target labels values should be -1 or 1. Available dtypes are int32, int64, float32, float64. output (Tensor): Tensor, the cosine embedding Loss of Tensor ``input1`` ``input2`` and ``label``. If `reduction` is ``'none'``, the shape of output loss is [N], the same as ``input`` . diff --git a/python/paddle/nn/layer/vision.py b/python/paddle/nn/layer/vision.py index 8542e2b62111ed6e95f2ede5397cec7e97c40e84..8058aeadf871a83f93ea8c80c08853fa9cfd0b9b 100644 --- a/python/paddle/nn/layer/vision.py +++ b/python/paddle/nn/layer/vision.py @@ -156,7 +156,7 @@ class PixelUnshuffle(Layer): class ChannelShuffle(Layer): """ - This operator divides channels in a tensor of shape [N, C, H, W] or [N, H, W, C] into g groups, + Can divide channels in a tensor of shape [N, C, H, W] or [N, H, W, C] into g groups, getting a tensor with the shape of [N, g, C/g, H, W] or [N, H, W, g, C/g], and transposes them as [N, C/g, g, H, W] or [N, H, W, g, C/g], then rearranges them to original tensor shape. This operation can improve the interaction between channels, using features efficiently. Please @@ -166,7 +166,7 @@ class ChannelShuffle(Layer): Parameters: groups (int): Number of groups to divide channels in. - data_format (str): The data format of the input and output data. An optional string of NCHW or NHWC. The default is NCHW. When it is NCHW, the data is stored in the order of [batch_size, input_channels, input_height, input_width]. + data_format (str, optional): The data format of the input and output data. An optional string of NCHW or NHWC. The default is NCHW. When it is NCHW, the data is stored in the order of [batch_size, input_channels, input_height, input_width]. name (str, optional): Name for the operation (optional, default is None). Normally there is no need for user to set this property. For more information, please refer to :ref:`api_guide_Name`. Shape: