MSELoss¶
- class paddle.nn. MSELoss ( reduction='mean' ) [source]
-
Mean Square Error Loss Computes the mean square error (squared L2 norm) of given input and label.
If
reductionis set to'none', loss is calculated as:\[Out = (input - label)^2\]If
reductionis set to'mean', loss is calculated as:\[Out = \operatorname{mean}((input - label)^2)\]If
reductionis set to'sum', loss is calculated as:\[Out = \operatorname{sum}((input - label)^2)\]where input and label are float32 tensors of same shape.
- Parameters
-
reduction (string, optional) – The reduction method for the output, could be ‘none’ | ‘mean’ | ‘sum’. If
reductionis'mean', the reduced mean loss is returned. Ifsize_averageis'sum', the reduced sum loss is returned. Ifreductionis'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
import numpy as np import paddle input_data = np.array([1.5]).astype("float32") label_data = np.array([1.7]).astype("float32") mse_loss = paddle.nn.loss.MSELoss() input = paddle.to_tensor(input_data) label = paddle.to_tensor(label_data) output = mse_loss(input, label) print(output) # [0.04000002]
-
forward
(
input,
label
)
forward¶
-
Defines the computation performed at every call. Should be overridden by all subclasses.
- Parameters
-
*inputs (tuple) – unpacked tuple arguments
**kwargs (dict) – unpacked dict arguments
