Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
机器未来
Paddle
提交
67f5eaff
P
Paddle
项目概览
机器未来
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
67f5eaff
编写于
5月 22, 2018
作者:
W
whs
提交者:
GitHub
5月 22, 2018
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add dice loss (#10717)
* Add dice loss. * Fix comments. * Remove unused code.
上级
62559ace
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
48 addition
and
1 deletion
+48
-1
doc/fluid/api/layers.rst
doc/fluid/api/layers.rst
+7
-1
python/paddle/fluid/layers/nn.py
python/paddle/fluid/layers/nn.py
+41
-0
未找到文件。
doc/fluid/api/layers.rst
浏览文件 @
67f5eaff
...
...
@@ -828,4 +828,10 @@ topk
.. autofunction:: paddle.fluid.layers.topk
:noindex:
dice_loss
----
.. autofunction:: paddle.fluid.layers.dice_loss
:noindex:
python/paddle/fluid/layers/nn.py
浏览文件 @
67f5eaff
...
...
@@ -80,6 +80,7 @@ __all__ = [
'pad'
,
'label_smooth'
,
'roi_pool'
,
'dice_loss'
,
]
...
...
@@ -3816,3 +3817,43 @@ def roi_pool(input, rois, pooled_height=1, pooled_width=1, spatial_scale=1.0):
"spatial_scale"
:
spatial_scale
})
return
pool_out
def
dice_loss
(
input
,
label
,
epsilon
=
0.00001
):
"""
**Dice loss Layer**
Dice loss for comparing the similarity of two batch of data,
usually is used for binary image segmentation i.e. labels are binary.
The dice loss can be defined as below equation:
.. math::
dice\_loss &= 1 -
\\
frac{2 * intersection\_area}{total\_area}
\\\\
&=
\\
frac{(total\_area - intersection\_area) - intersection\_area}{total\_area}
\\\\
&=
\\
frac{(union\_area - intersection\_area)}{total\_area}
Args:
input (Variable): The predictions with rank>=2. The first dimension is batch size,
and the last dimension is class number.
label (Variable): The groud truth with the same rank with input. The first dimension
is batch size, and the last dimension is 1.
epsilon (float): The epsilon will be added to the numerator and denominator.
If both input and label are empty, it makes sure dice is 1.
Default: 0.00001
Returns:
dice_loss (Variable): The dice loss with shape [1].
Examples:
predictions = fluid.layers.softmax(x)
loss = fluid.layers.dice_loss(input=predictions, label=label, 2)
"""
label
=
one_hot
(
label
,
depth
=
input
.
shape
[
-
1
])
reduce_dim
=
range
(
1
,
len
(
input
.
shape
))
inse
=
reduce_sum
(
input
*
label
,
dim
=
reduce_dim
)
dice_denominator
=
reduce_sum
(
input
,
dim
=
reduce_dim
)
+
reduce_sum
(
label
,
dim
=
reduce_dim
)
dice_score
=
1
-
inse
*
2
/
(
dice_denominator
+
epsilon
)
return
reduce_mean
(
dice_score
)
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录