From 9c59d42b8b742cab6aaad5b81c816dde06b2b4c2 Mon Sep 17 00:00:00 2001 From: whisky-12 <79358023+whisky-12@users.noreply.github.com> Date: Fri, 17 Feb 2023 14:22:52 +0800 Subject: [PATCH] =?UTF-8?q?[note]-MSELoss-=20API=E8=8B=B1=E6=96=87?= =?UTF-8?q?=E6=96=87=E6=A1=A3=E4=B8=AD=E5=8C=85=E5=90=AB=E6=8A=A5=E9=94=99?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=E7=9A=84=E9=97=AE=E9=A2=98=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=20(#49577)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- python/paddle/nn/layer/loss.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/python/paddle/nn/layer/loss.py b/python/paddle/nn/layer/loss.py index c91a04f8d17..b2cec383eb9 100644 --- a/python/paddle/nn/layer/loss.py +++ b/python/paddle/nn/layer/loss.py @@ -525,16 +525,24 @@ class MSELoss(Layer): r""" **Mean Square Error Loss** Computes the mean square error (squared L2 norm) of given input and label. + If :attr:`reduction` is set to ``'none'``, loss is calculated as: + .. math:: Out = (input - label)^2 + If :attr:`reduction` is set to ``'mean'``, loss is calculated as: + .. math:: Out = \operatorname{mean}((input - label)^2) + If :attr:`reduction` is set to ``'sum'``, loss is calculated as: + .. math:: Out = \operatorname{sum}((input - label)^2) + where `input` and `label` are `float32` tensors of same shape. + Parameters: reduction (str, optional): The reduction method for the output, could be 'none' | 'mean' | 'sum'. @@ -542,12 +550,16 @@ class MSELoss(Layer): If :attr:`size_average` is ``'sum'``, the reduced sum loss is returned. If :attr:`reduction` is ``'none'``, the unreduced loss is returned. Default is ``'mean'``. + Shape: input (Tensor): Input tensor, the data type is float32 or float64 label (Tensor): Label tensor, the data type is float32 or float64 output (Tensor): output tensor storing the MSE loss of input and label, the data type is same as input. + Examples: + .. code-block:: python + import paddle mse_loss = paddle.nn.loss.MSELoss() input = paddle.to_tensor([1.5]) @@ -555,6 +567,7 @@ class MSELoss(Layer): output = mse_loss(input, label) print(output) # [0.04000002] + """ def __init__(self, reduction='mean'): -- GitLab