Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
ae4724cf
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2298
Star
20931
Fork
5422
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1423
列表
看板
标记
里程碑
合并请求
543
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1,423
Issue
1,423
列表
看板
标记
里程碑
合并请求
543
合并请求
543
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
ae4724cf
编写于
8月 24, 2020
作者:
B
Bai Yifan
提交者:
GitHub
8月 24, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix type issue (#26500)
上级
bf4a4636
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
15 addition
and
39 deletion
+15
-39
python/paddle/nn/layer/loss.py
python/paddle/nn/layer/loss.py
+15
-39
未找到文件。
python/paddle/nn/layer/loss.py
浏览文件 @
ae4724cf
...
...
@@ -253,9 +253,6 @@ class CrossEntropyLoss(fluid.dygraph.Layer):
class
MSELoss
(
fluid
.
dygraph
.
layers
.
Layer
):
"""
:alias_main: paddle.nn.MSELoss
:alias: paddle.nn.MSELoss,paddle.nn.layer.MSELoss,paddle.nn.layer.loss.MSELoss
**Mean Square Error Loss**
Computes the mean square error (squared L2 norm) of given input and label.
...
...
@@ -277,8 +274,6 @@ class MSELoss(fluid.dygraph.layers.Layer):
where `input` and `label` are `float32` tensors of same shape.
Parameters:
input (Variable): Input tensor, the data type is float32,
label (Variable): Label tensor, the data type is float32,
reduction (string, optional): The reduction method for the output,
could be 'none' | 'mean' | 'sum'.
If :attr:`reduction` is ``'mean'``, the reduced mean loss is returned.
...
...
@@ -286,46 +281,27 @@ class MSELoss(fluid.dygraph.layers.Layer):
If :attr:`reduction` is ``'none'``, the unreduced loss is returned.
Default is ``'mean'``.
Returns:
The tensor variable storing the MSE loss of input and label.
Return type:
Variable.
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 numpy as np
import paddle
from paddle import fluid
import paddle.fluid.dygraph as dg
mse_loss = paddle.nn.loss.MSELoss()
input = fluid.data(name="input", shape=[1])
label = fluid.data(name="label", shape=[1])
place = fluid.CPUPlace()
input_data = np.array([1.5]).astype("float32")
label_data = np.array([1.7]).astype("float32")
# declarative mode
output = mse_loss(input,label)
exe = fluid.Executor(place)
exe.run(fluid.default_startup_program())
output_data = exe.run(
fluid.default_main_program(),
feed={"input":input_data, "label":label_data},
fetch_list=[output],
return_numpy=True)
print(output_data)
# [array([0.04000002], dtype=float32)]
# imperative mode
with dg.guard(place) as g:
input = dg.to_variable(input_data)
label = dg.to_variable(label_data)
output = mse_loss(input, label)
print(output.numpy())
# [0.04000002]
paddle.disable_static()
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.numpy())
# [0.04000002]
"""
def
__init__
(
self
,
reduction
=
'mean'
):
...
...
@@ -338,10 +314,10 @@ class MSELoss(fluid.dygraph.layers.Layer):
def
forward
(
self
,
input
,
label
):
if
not
fluid
.
framework
.
in_dygraph_mode
():
fluid
.
data_feeder
.
check_variable_and_dtype
(
input
,
'input'
,
[
'float32
'
],
'MSELoss'
)
fluid
.
data_feeder
.
check_variable_and_dtype
(
label
,
'label'
,
[
'float32
'
],
'MSELoss'
)
fluid
.
data_feeder
.
check_variable_and_dtype
(
input
,
'input'
,
[
'float32'
,
'float64
'
],
'MSELoss'
)
fluid
.
data_feeder
.
check_variable_and_dtype
(
label
,
'label'
,
[
'float32'
,
'float64
'
],
'MSELoss'
)
square_out
=
fluid
.
layers
.
square
(
fluid
.
layers
.
elementwise_sub
(
input
,
label
))
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录