Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleSeg
提交
dba781af
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
dba781af
编写于
11月 26, 2019
作者:
W
wuyefeilin
提交者:
wuzewu
11月 26, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add preprocess and argmax to export process (#98)
* add preprocess and argmax to export process * add comments
上级
4f685d1a
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
27 addition
and
3 deletion
+27
-3
pdseg/models/model_builder.py
pdseg/models/model_builder.py
+27
-3
未找到文件。
pdseg/models/model_builder.py
浏览文件 @
dba781af
...
...
@@ -140,8 +140,25 @@ def build_model(main_prog, start_prog, phase=ModelPhase.TRAIN):
with
fluid
.
program_guard
(
main_prog
,
start_prog
):
with
fluid
.
unique_name
.
guard
():
image
=
fluid
.
layers
.
data
(
name
=
'image'
,
shape
=
image_shape
,
dtype
=
'float32'
)
# 在导出模型的时候,增加图像标准化预处理,减小预测部署时图像的处理流程
# 预测部署时只须对输入图像增加batch_size维度即可
if
ModelPhase
.
is_predict
(
phase
):
origin_image
=
fluid
.
layers
.
data
(
name
=
'image'
,
shape
=
[
-
1
,
1
,
1
,
cfg
.
DATASET
.
DATA_DIM
],
dtype
=
'float32'
,
append_batch_size
=
False
)
image
=
fluid
.
layers
.
transpose
(
origin_image
,
[
0
,
3
,
1
,
2
])
origin_shape
=
fluid
.
layers
.
shape
(
image
)[
-
2
:]
mean
=
np
.
array
(
cfg
.
MEAN
).
reshape
(
1
,
len
(
cfg
.
MEAN
),
1
,
1
)
mean
=
fluid
.
layers
.
assign
(
mean
.
astype
(
'float32'
))
std
=
np
.
array
(
cfg
.
STD
).
reshape
(
1
,
len
(
cfg
.
STD
),
1
,
1
)
std
=
fluid
.
layers
.
assign
(
std
.
astype
(
'float32'
))
image
=
(
image
/
255
-
mean
)
/
std
image
=
fluid
.
layers
.
resize_bilinear
(
image
,
out_shape
=
[
height
,
width
],
align_corners
=
False
,
align_mode
=
0
)
else
:
image
=
fluid
.
layers
.
data
(
name
=
'image'
,
shape
=
image_shape
,
dtype
=
'float32'
)
label
=
fluid
.
layers
.
data
(
name
=
'label'
,
shape
=
grt_shape
,
dtype
=
'int32'
)
mask
=
fluid
.
layers
.
data
(
...
...
@@ -162,9 +179,11 @@ def build_model(main_prog, start_prog, phase=ModelPhase.TRAIN):
if
not
isinstance
(
loss_type
,
list
):
loss_type
=
list
(
loss_type
)
# dice_loss或bce_loss只适用两类分割中
if
class_num
>
2
and
((
"dice_loss"
in
loss_type
)
or
(
"bce_loss"
in
loss_type
)):
raise
Exception
(
"dice loss and bce loss is only applicable to binary classfication"
)
# 在两类分割情况下,当loss函数选择dice_loss或bce_loss的时候,最后logit输出通道数设置为1
if
(
"dice_loss"
in
loss_type
)
or
(
"bce_loss"
in
loss_type
):
class_num
=
1
if
"softmax_loss"
in
loss_type
:
...
...
@@ -172,6 +191,7 @@ def build_model(main_prog, start_prog, phase=ModelPhase.TRAIN):
logits
=
model_func
(
image
,
class_num
)
# 根据选择的loss函数计算相应的损失函数
if
ModelPhase
.
is_train
(
phase
)
or
ModelPhase
.
is_eval
(
phase
):
loss_valid
=
False
avg_loss_list
=
[]
...
...
@@ -213,11 +233,15 @@ def build_model(main_prog, start_prog, phase=ModelPhase.TRAIN):
# return image input and logit output for inference graph prune
if
ModelPhase
.
is_predict
(
phase
):
# 两类分割中,使用dice_loss或bce_loss返回的logit为单通道,进行到两通道的变换
if
class_num
==
1
:
logit
=
sigmoid_to_softmax
(
logit
)
else
:
logit
=
softmax
(
logit
)
return
image
,
logit
logit
=
fluid
.
layers
.
resize_bilinear
(
logit
,
out_shape
=
origin_shape
,
align_corners
=
False
,
align_mode
=
0
)
logit
=
fluid
.
layers
.
transpose
(
logit
,
[
0
,
2
,
3
,
1
])
logit
=
fluid
.
layers
.
argmax
(
logit
,
axis
=
3
)
return
origin_image
,
logit
if
class_num
==
1
:
out
=
sigmoid_to_softmax
(
logit
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录