未验证 提交 d7650aef 编写于 作者: B Bai Yifan 提交者: GitHub

Add mse_loss_cn doc (#2385)

* add mse_loss_cn doc

* add index

* add index
上级 21ba9d2e
...@@ -7,3 +7,4 @@ functional ...@@ -7,3 +7,4 @@ functional
functional/l1_loss.rst functional/l1_loss.rst
functional/nll_loss.rst functional/nll_loss.rst
functional/mse_loss.rst
.. _api_nn_functional_mse_loss:
mse_loss
------
.. autoclass:: paddle.nn.functional.mse_loss
:members:
:inherited-members:
:noindex:
...@@ -11,3 +11,4 @@ functional ...@@ -11,3 +11,4 @@ functional
functional_cn/l1_loss_cn.rst functional_cn/l1_loss_cn.rst
functional_cn/nll_loss_cn.rst functional_cn/nll_loss_cn.rst
functional_cn/margin_ranking_loss_cn.rst functional_cn/margin_ranking_loss_cn.rst
functional_cn/mse_loss_cn.rst
mse_loss
-------------------------------
.. py:function:: paddle.nn.functional.mse_loss(input, label, reduction='mean', name=None)
该OP用于计算预测值和目标值的均方差误差。
对于预测值input和目标值label,公式为:
当 `reduction` 设置为 ``'none'`` 时,
.. math::
Out = (input - label)^2
当 `reduction` 设置为 ``'mean'`` 时,
.. math::
Out = \operatorname{mean}((input - label)^2)
当 `reduction` 设置为 ``'sum'`` 时,
.. math::
Out = \operatorname{sum}((input - label)^2)
参数:
:::::::::
- **input** (Tensor) - 预测值,维度为 :math:`[N_1, N_2, ..., N_k]` 的多维Tensor。数据类型为float32或float64。
- **label** (Tensor) - 目标值,维度为 :math:`[N_1, N_2, ..., N_k]` 的多维Tensor。数据类型为float32或float64。
返回
:::::::::
``Tensor``, 输入 ``input`` 和标签 ``label`` 间的 `mse loss` 损失。
**代码示例**:
.. code-block:: python
import numpy as np
import paddle
# static graph mode
paddle.enable_static()
mse_loss = paddle.nn.loss.MSELoss()
input = paddle.data(name="input", shape=[1])
label = paddle.data(name="label", shape=[1])
place = paddle.CPUPlace()
input_data = np.array([1.5]).astype("float32")
label_data = np.array([1.7]).astype("float32")
output = mse_loss(input,label)
exe = paddle.static.Executor(place)
exe.run(paddle.static.default_startup_program())
output_data = exe.run(
paddle.static.default_main_program(),
feed={"input":input_data, "label":label_data},
fetch_list=[output],
return_numpy=True)
print(output_data)
# [array([0.04000002], dtype=float32)]
# dynamic graph mode
paddle.disable_static()
input = paddle.to_variable(input_data)
label = paddle.to_variable(label_data)
output = mse_loss(input, label)
print(output.numpy())
# [0.04000002]
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册