input(Tensor): the first input tensor, it's data type should be float32, float64.
input(Tensor): the first input tensor, it's data type should be float32, float64.
other(Tensor): the second input tensor, it's data type should be float32, float64.
other(Tensor): the second input tensor, it's data type should be float32, float64.
label(Tensor): the label value corresponding to input, it's data type should be float32, float64.
label(Tensor): the label value corresponding to input, it's data type should be float32, float64.
margin (float, optional): The margin value to add, default value is 0;
margin (float, optional): The margin value to add, default value is 0;
reduction (str, optional): Indicate the reduction to apply to the loss, the candicates are ``'none'``, ``'mean'``, ``'sum'``.If :attr:`reduction` is ``'none'``, the unreduced loss is returned; If :attr:`reduction` is ``'mean'``, the reduced mean loss is returned. If :attr:`reduction` is ``'sum'``, the reduced sum loss is returned. Default is ``'mean'``.
reduction (str, optional): Indicate the reduction to apply to the loss, the candicates are ``'none'``, ``'mean'``, ``'sum'``.If :attr:`reduction` is ``'none'``, the unreduced loss is returned; If :attr:`reduction` is ``'mean'``, the reduced mean loss is returned. If :attr:`reduction` is ``'sum'``, the reduced sum loss is returned. Default is ``'mean'``.
name (str, optional): Name for the operation (optional, default is None). For more information, please refer to :ref:`api_guide_Name`.
name (str, optional): Name for the operation (optional, default is None). For more information, please refer to :ref:`api_guide_Name`.
input (Tensor): The input tensor. The shapes is [N, *], where N is batch size and `*` means any number of additional dimensions. It's data type should be float32, float64, int32, int64.
input (Tensor): The input tensor. The shapes is [N, *], where N is batch size and `*` means any number of additional dimensions. It's data type should be float32, float64, int32, int64.
label (Tensor): label. The shapes is [N, *], same shape as ``input`` . It's data type should be float32, float64, int32, int64.
label (Tensor): label. The shapes is [N, *], same shape as ``input`` . It's data type should be float32, float64, int32, int64.
reduction (str, optional): Indicate the reduction to apply to the loss,
reduction (str, optional): Indicate the reduction to apply to the loss,
the candicates are ``'none'`` | ``'mean'`` | ``'sum'``.
the candicates are ``'none'`` | ``'mean'`` | ``'sum'``.
If `reduction` is ``'none'``, the unreduced loss is returned;
If `reduction` is ``'none'``, the unreduced loss is returned;
If `reduction` is ``'mean'``, the reduced mean loss is returned.
If `reduction` is ``'mean'``, the reduced mean loss is returned.
If `reduction` is ``'sum'``, the reduced sum loss is returned.
If `reduction` is ``'sum'``, the reduced sum loss is returned.
Default is ``'mean'``.
Default is ``'mean'``.
name (str, optional): Name for the operation (optional, default is None). For more information, please refer to :ref:`api_guide_Name`.
name (str, optional): Name for the operation (optional, default is None). For more information, please refer to :ref:`api_guide_Name`.
@@ -61,8 +62,8 @@ class CrossEntropyLoss(fluid.dygraph.Layer):
...
@@ -61,8 +62,8 @@ class CrossEntropyLoss(fluid.dygraph.Layer):
Parameters:
Parameters:
input (Variable): Input tensor, the data type is float32, float64. Shape is
input (Variable): Input tensor, the data type is float32, float64. Shape is
(N, C), where C is number of classes, and if shape is more than 2D, this
(N, C), where C is number of classes, and if shape is more than 2D, this
is (N, C, D1, D2,..., Dk), k >= 1.
is (N, C, D1, D2,..., Dk), k >= 1.
label (Variable): Label tensor, the data type is int64. Shape is (N), where each
label (Variable): Label tensor, the data type is int64. Shape is (N), where each
value is 0 <= label[i] <= C-1, and if shape is more than 2D, this is
value is 0 <= label[i] <= C-1, and if shape is more than 2D, this is
(N, D1, D2,..., Dk), k >= 1.
(N, D1, D2,..., Dk), k >= 1.
weight (Variable, optional): Weight tensor, a manual rescaling weight given
weight (Variable, optional): Weight tensor, a manual rescaling weight given
...
@@ -180,9 +181,9 @@ class MSELoss(fluid.dygraph.layers.Layer):
...
@@ -180,9 +181,9 @@ class MSELoss(fluid.dygraph.layers.Layer):
label (Variable): Label tensor, the data type is float32,
label (Variable): Label tensor, the data type is float32,
reduction (string, optional): The reduction method for the output,
reduction (string, optional): The reduction method for the output,
could be 'none' | 'mean' | 'sum'.
could be 'none' | 'mean' | 'sum'.
If :attr:`reduction` is ``'mean'``, the reduced mean loss is returned.
If :attr:`reduction` is ``'mean'``, the reduced mean loss is returned.
If :attr:`size_average` is ``'sum'``, the reduced sum loss is returned.
If :attr:`size_average` is ``'sum'``, the reduced sum loss is returned.
If :attr:`reduction` is ``'none'``, the unreduced loss is returned.
If :attr:`reduction` is ``'none'``, the unreduced loss is returned.
Default is ``'mean'``.
Default is ``'mean'``.
Returns:
Returns:
...
@@ -274,23 +275,23 @@ class L1Loss(fluid.dygraph.Layer):
...
@@ -274,23 +275,23 @@ class L1Loss(fluid.dygraph.Layer):
.. math::
.. math::
Out = SUM(\lvert input - label\rvert)
Out = SUM(\lvert input - label\rvert)
Parameters:
Parameters:
reduction (str, optional): Indicate the reduction to apply to the loss,
reduction (str, optional): Indicate the reduction to apply to the loss,
the candicates are ``'none'`` | ``'mean'`` | ``'sum'``.
the candicates are ``'none'`` | ``'mean'`` | ``'sum'``.
If `reduction` is ``'none'``, the unreduced loss is returned;
If `reduction` is ``'none'``, the unreduced loss is returned;
If `reduction` is ``'mean'``, the reduced mean loss is returned.
If `reduction` is ``'mean'``, the reduced mean loss is returned.
If `reduction` is ``'sum'``, the reduced sum loss is returned.
If `reduction` is ``'sum'``, the reduced sum loss is returned.
Default is ``'mean'``.
Default is ``'mean'``.
name (str, optional): Name for the operation (optional, default is None). For more information, please refer to :ref:`api_guide_Name`.
name (str, optional): Name for the operation (optional, default is None). For more information, please refer to :ref:`api_guide_Name`.
Shape:
Shape:
input (Tensor): The input tensor. The shapes is [N, *], where N is batch size and `*` means any number of additional dimensions. It's data type should be float32, float64, int32, int64.
input (Tensor): The input tensor. The shapes is [N, *], where N is batch size and `*` means any number of additional dimensions. It's data type should be float32, float64, int32, int64.
label (Tensor): label. The shapes is [N, *], same shape as ``input`` . It's data type should be float32, float64, int32, int64.
label (Tensor): label. The shapes is [N, *], same shape as ``input`` . It's data type should be float32, float64, int32, int64.
output (Tensor): The L1 Loss of ``input`` and ``label``.
output (Tensor): The L1 Loss of ``input`` and ``label``.
If `reduction` is ``'none'``, the shape of output loss is [N, *], the same as ``input`` .
If `reduction` is ``'none'``, the shape of output loss is [N, *], the same as ``input`` .
If `reduction` is ``'mean'`` or ``'sum'``, the shape of output loss is [1].
If `reduction` is ``'mean'`` or ``'sum'``, the shape of output loss is [1].
Examples:
Examples:
.. code-block:: python
.. code-block:: python
import paddle
import paddle
...
@@ -304,17 +305,17 @@ class L1Loss(fluid.dygraph.Layer):
...
@@ -304,17 +305,17 @@ class L1Loss(fluid.dygraph.Layer):
l1_loss = paddle.nn.loss.L1Loss()
l1_loss = paddle.nn.loss.L1Loss()
output = l1_loss(input, label)
output = l1_loss(input, label)
print(output.numpy())
print(output.numpy())
# [0.35]
# [0.35]
l1_loss = paddle.nn.loss.L1Loss(reduction='sum')
l1_loss = paddle.nn.loss.L1Loss(reduction='sum')
output = l1_loss(input, label)
output = l1_loss(input, label)
print(output.numpy())
print(output.numpy())
# [1.4]
# [1.4]
l1_loss = paddle.nn.loss.L1Loss(reduction='none')
l1_loss = paddle.nn.loss.L1Loss(reduction='none')
output = l1_loss(input, label)
output = l1_loss(input, label)
print(output.numpy())
print(output.numpy())
# [[0.20000005 0.19999999]
# [[0.20000005 0.19999999]
# [0.2 0.79999995]]
# [0.2 0.79999995]]
"""
"""
...
@@ -335,90 +336,80 @@ class L1Loss(fluid.dygraph.Layer):
...
@@ -335,90 +336,80 @@ class L1Loss(fluid.dygraph.Layer):
If :attr:`reduction` set to ``'mean'``, the reduced mean loss is:
If :attr:`reduction` set to ``'mean'``, the reduced mean loss is:
...
@@ -672,7 +637,7 @@ class MarginRankingLoss(fluid.dygraph.Layer):
...
@@ -672,7 +637,7 @@ class MarginRankingLoss(fluid.dygraph.Layer):
reduction (str, optional): Indicate the reduction to apply to the loss, the candicates are ``'none'``, ``'mean'``, ``'sum'``.If :attr:`reduction` is ``'none'``, the unreduced loss is returned; If :attr:`reduction` is ``'mean'``, the reduced mean loss is returned. If :attr:`reduction` is ``'sum'``, the reduced sum loss is returned. Default is ``'mean'``.
reduction (str, optional): Indicate the reduction to apply to the loss, the candicates are ``'none'``, ``'mean'``, ``'sum'``.If :attr:`reduction` is ``'none'``, the unreduced loss is returned; If :attr:`reduction` is ``'mean'``, the reduced mean loss is returned. If :attr:`reduction` is ``'sum'``, the reduced sum loss is returned. Default is ``'mean'``.
name (str, optional): Name for the operation (optional, default is None). For more information, please refer to :ref:`api_guide_Name`.
name (str, optional): Name for the operation (optional, default is None). For more information, please refer to :ref:`api_guide_Name`.
Shape:
Shape:
input: N-D Tensor, the shape is [N, *], N is batch size and `*` means any number of additional dimensions., available dtype is float32, float64.
input: N-D Tensor, the shape is [N, *], N is batch size and `*` means any number of additional dimensions., available dtype is float32, float64.
other: N-D Tensor, `other` have the same shape and dtype as `input`.
other: N-D Tensor, `other` have the same shape and dtype as `input`.
label: N-D Tensor, label have the same shape and dtype as `input`.
label: N-D Tensor, label have the same shape and dtype as `input`.
...
@@ -685,16 +650,16 @@ class MarginRankingLoss(fluid.dygraph.Layer):
...
@@ -685,16 +650,16 @@ class MarginRankingLoss(fluid.dygraph.Layer):