Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
e2c2652f
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看板
提交
e2c2652f
编写于
12月 27, 2017
作者:
Y
Yibing Liu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
amend comments in cross_entropy_op
上级
4177e805
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
16 addition
and
16 deletion
+16
-16
paddle/operators/cross_entropy_op.cc
paddle/operators/cross_entropy_op.cc
+3
-3
python/paddle/v2/fluid/layers/nn.py
python/paddle/v2/fluid/layers/nn.py
+13
-13
未找到文件。
paddle/operators/cross_entropy_op.cc
浏览文件 @
e2c2652f
...
...
@@ -114,15 +114,15 @@ class CrossEntropyOpMaker : public framework::OpProtoAndCheckerMaker {
CrossEntropyOpMaker
(
OpProto
*
proto
,
OpAttrChecker
*
op_checker
)
:
OpProtoAndCheckerMaker
(
proto
,
op_checker
)
{
AddInput
(
"X"
,
"(Tensor, default Tensor<float>), a 2-D tensor with shape
N x D,
"
"where N is the batch size and D is the number of classes. "
"(Tensor, default Tensor<float>), a 2-D tensor with shape
[N x D],
"
"
where N is the batch size and D is the number of classes. "
"This input is a probability computed by the previous operator, "
"which is almost always the result of a softmax operator."
);
AddInput
(
"Label"
,
"(Tensor), the ground truth which is a 2-D tensor. When "
"soft_label is set to false, Label is a Tensor<int64> with shape "
"[N x 1]. When soft_label is set to true, Label is a "
"Tensor<float/double> with shape [N x
K
]."
);
"Tensor<float/double> with shape [N x
D
]."
);
AddOutput
(
"Y"
,
"(Tensor, default Tensor<float>), a 2-D tensor with shape "
"[N x 1]. The cross entropy loss."
);
...
...
python/paddle/v2/fluid/layers/nn.py
浏览文件 @
e2c2652f
...
...
@@ -365,47 +365,47 @@ def cross_entropy(input, label, **kwargs):
both standard cross-entropy and soft-label cross-entropy loss computation.
1) One-hot cross-entropy:
`soft_label =
f
alse`, `Label[i, 0]` indicates the class index for sample i:
`soft_label =
F
alse`, `Label[i, 0]` indicates the class index for sample i:
.. math::
Y[i] = -\log(X[i, Label[i]])
2) Soft-label cross-entropy:
`soft_label =
t
rue`, `Label[i, j]` indicates the soft label of class j
`soft_label =
T
rue`, `Label[i, j]` indicates the soft label of class j
for sample i:
.. math::
Y[i] = \sum_j{-Label[i, j] * log(X[i, j])}
Please make sure that in this case the summ
u
ation of each row of `label`
Please make sure that in this case the summation of each row of `label`
equals one.
3) One-hot cross-entropy with vecterized `label`:
As a special case of 2), when each row of 'label' has only one
non-zero element
(equals 1), soft-label cross-entropy degenerates to a
one-hot cross-entropy with one-hot label representation.
non-zero element
which is equal to 1, soft-label cross-entropy degenerates
to a
one-hot cross-entropy with one-hot label representation.
Args:
input (Variable|list): a 2-D tensor with shape
N x D
, where N is the
input (Variable|list): a 2-D tensor with shape
[N x D]
, where N is the
batch size and D is the number of classes. This input is a probability
computed by the previous operator, which is almost always the result
of a softmax operator.
label (Variable|list): the ground truth which is a 2-D tensor. When
`soft_label` is set to `
f
alse`, `label` is a tensor<int64> with shape
[N x 1]. When `soft_label` is set to `
t
rue`, `label` is a
tensor<float/double> with shape [N x
K
].
`soft_label` is set to `
F
alse`, `label` is a tensor<int64> with shape
[N x 1]. When `soft_label` is set to `
T
rue`, `label` is a
tensor<float/double> with shape [N x
D
].
soft_label (bool, via `**kwargs`): a flag indicating whether to interpretate
the given labels as soft labels, default `
f
alse`.
the given labels as soft labels, default `
F
alse`.
Returns:
A 2-D tensor with shape [N x 1], the cross entropy loss.
Raises:
`ValueError`: 1)
If the 1st dimension of `input` and `label` are not equal; 2) If
\
`soft_label ==
t
rue`, and the 2nd dimension of `input` and `label` are not
\
equal; 3)
If `soft_label == f
alse`, and the 2nd dimension of `label` is not 1.
`ValueError`: 1)
the 1st dimension of `input` and `label` are not equal; 2) when
\
`soft_label ==
T
rue`, and the 2nd dimension of `input` and `label` are not
\
equal; 3)
when `soft_label == F
alse`, and the 2nd dimension of `label` is not 1.
Examples:
.. code-block:: python
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录