Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleSeg
提交
03661410
P
PaddleSeg
项目概览
PaddlePaddle
/
PaddleSeg
通知
285
Star
8
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
53
列表
看板
标记
里程碑
合并请求
3
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleSeg
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
53
Issue
53
列表
看板
标记
里程碑
合并请求
3
合并请求
3
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
03661410
编写于
9月 24, 2020
作者:
L
LutaoChu
提交者:
GitHub
9月 24, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Support MULTI_LOSS_WEIGHT for lovasz loss (#411)
上级
f37a862a
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
44 addition
and
5 deletion
+44
-5
pdseg/lovasz_losses.py
pdseg/lovasz_losses.py
+41
-0
pdseg/models/model_builder.py
pdseg/models/model_builder.py
+3
-5
未找到文件。
pdseg/lovasz_losses.py
浏览文件 @
03661410
...
@@ -18,6 +18,7 @@ from __future__ import division
...
@@ -18,6 +18,7 @@ from __future__ import division
from
__future__
import
print_function
from
__future__
import
print_function
import
paddle.fluid
as
fluid
import
paddle.fluid
as
fluid
import
numpy
as
np
import
numpy
as
np
from
utils.config
import
cfg
def
_cumsum
(
x
):
def
_cumsum
(
x
):
...
@@ -203,3 +204,43 @@ def flatten_probas(probas, labels, ignore=None):
...
@@ -203,3 +204,43 @@ def flatten_probas(probas, labels, ignore=None):
vprobas
=
fluid
.
layers
.
gather
(
probas
,
indexs
[:,
0
])
vprobas
=
fluid
.
layers
.
gather
(
probas
,
indexs
[:,
0
])
vlabels
=
fluid
.
layers
.
gather
(
labels
,
indexs
[:,
0
])
vlabels
=
fluid
.
layers
.
gather
(
labels
,
indexs
[:,
0
])
return
vprobas
,
vlabels
return
vprobas
,
vlabels
def
multi_lovasz_softmax_loss
(
logits
,
label
,
ignore_mask
=
None
):
if
isinstance
(
logits
,
tuple
):
avg_loss
=
0
for
i
,
logit
in
enumerate
(
logits
):
if
label
.
shape
[
2
]
!=
logit
.
shape
[
2
]
or
label
.
shape
[
3
]
!=
logit
.
shape
[
3
]:
logit_label
=
fluid
.
layers
.
resize_nearest
(
label
,
logit
.
shape
[
2
:])
else
:
logit_label
=
label
logit_mask
=
(
logit_label
.
astype
(
'int32'
)
!=
cfg
.
DATASET
.
IGNORE_INDEX
).
astype
(
'int32'
)
probas
=
fluid
.
layers
.
softmax
(
logit
,
axis
=
1
)
loss
=
lovasz_softmax
(
probas
,
logit_label
,
ignore
=
logit_mask
)
avg_loss
+=
cfg
.
MODEL
.
MULTI_LOSS_WEIGHT
[
i
]
*
loss
else
:
probas
=
fluid
.
layers
.
softmax
(
logits
,
axis
=
1
)
avg_loss
=
lovasz_softmax
(
probas
,
label
,
ignore
=
ignore_mask
)
return
avg_loss
def
multi_lovasz_hinge_loss
(
logits
,
label
,
ignore_mask
=
None
):
if
isinstance
(
logits
,
tuple
):
avg_loss
=
0
for
i
,
logit
in
enumerate
(
logits
):
if
label
.
shape
[
2
]
!=
logit
.
shape
[
2
]
or
label
.
shape
[
3
]
!=
logit
.
shape
[
3
]:
logit_label
=
fluid
.
layers
.
resize_nearest
(
label
,
logit
.
shape
[
2
:])
else
:
logit_label
=
label
logit_mask
=
(
logit_label
.
astype
(
'int32'
)
!=
cfg
.
DATASET
.
IGNORE_INDEX
).
astype
(
'int32'
)
loss
=
lovasz_hinge
(
logit
,
logit_label
,
ignore
=
logit_mask
)
avg_loss
+=
cfg
.
MODEL
.
MULTI_LOSS_WEIGHT
[
i
]
*
loss
else
:
avg_loss
=
lovasz_hinge
(
logits
,
label
,
ignore
=
ignore_mask
)
return
avg_loss
pdseg/models/model_builder.py
浏览文件 @
03661410
...
@@ -24,8 +24,7 @@ from utils.config import cfg
...
@@ -24,8 +24,7 @@ from utils.config import cfg
from
loss
import
multi_softmax_with_loss
from
loss
import
multi_softmax_with_loss
from
loss
import
multi_dice_loss
from
loss
import
multi_dice_loss
from
loss
import
multi_bce_loss
from
loss
import
multi_bce_loss
from
lovasz_losses
import
lovasz_hinge
from
lovasz_losses
import
multi_lovasz_hinge_loss
,
multi_lovasz_softmax_loss
from
lovasz_losses
import
lovasz_softmax
from
models.modeling
import
deeplab
,
unet
,
icnet
,
pspnet
,
hrnet
,
fast_scnn
,
ocrnet
from
models.modeling
import
deeplab
,
unet
,
icnet
,
pspnet
,
hrnet
,
fast_scnn
,
ocrnet
...
@@ -189,13 +188,12 @@ def build_model(main_prog, start_prog, phase=ModelPhase.TRAIN):
...
@@ -189,13 +188,12 @@ def build_model(main_prog, start_prog, phase=ModelPhase.TRAIN):
valid_loss
.
append
(
"bce_loss"
)
valid_loss
.
append
(
"bce_loss"
)
if
"lovasz_hinge_loss"
in
loss_type
:
if
"lovasz_hinge_loss"
in
loss_type
:
avg_loss_list
.
append
(
avg_loss_list
.
append
(
lovasz_hinge
(
logits
,
label
,
ignore
=
mask
))
multi_lovasz_hinge_loss
(
logits
,
label
,
mask
))
loss_valid
=
True
loss_valid
=
True
valid_loss
.
append
(
"lovasz_hinge_loss"
)
valid_loss
.
append
(
"lovasz_hinge_loss"
)
if
"lovasz_softmax_loss"
in
loss_type
:
if
"lovasz_softmax_loss"
in
loss_type
:
probas
=
fluid
.
layers
.
softmax
(
logits
,
axis
=
1
)
avg_loss_list
.
append
(
avg_loss_list
.
append
(
lovasz_softmax
(
probas
,
label
,
ignore
=
mask
))
multi_lovasz_softmax_loss
(
logits
,
label
,
mask
))
loss_valid
=
True
loss_valid
=
True
valid_loss
.
append
(
"lovasz_softmax_loss"
)
valid_loss
.
append
(
"lovasz_softmax_loss"
)
if
not
loss_valid
:
if
not
loss_valid
:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录