Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleSeg
提交
cb3743d0
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看板
提交
cb3743d0
编写于
12月 12, 2019
作者:
C
chenguowei01
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update model_builder.py
上级
216f38e7
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
53 addition
and
45 deletion
+53
-45
pdseg/models/model_builder.py
pdseg/models/model_builder.py
+53
-45
未找到文件。
pdseg/models/model_builder.py
浏览文件 @
cb3743d0
...
...
@@ -124,32 +124,12 @@ def sigmoid_to_softmax(logit):
logit
=
fluid
.
layers
.
transpose
(
logit
,
[
0
,
3
,
1
,
2
])
return
logit
def
build_model
(
main_prog
,
start_prog
,
phase
=
ModelPhase
.
TRAIN
):
if
not
ModelPhase
.
is_valid_phase
(
phase
):
raise
ValueError
(
"ModelPhase {} is not valid!"
.
format
(
phase
))
if
ModelPhase
.
is_train
(
phase
):
width
=
cfg
.
TRAIN_CROP_SIZE
[
0
]
height
=
cfg
.
TRAIN_CROP_SIZE
[
1
]
else
:
def
export_preprocess
(
image
):
"""导出模型的预处理流程"""
width
=
cfg
.
EVAL_CROP_SIZE
[
0
]
height
=
cfg
.
EVAL_CROP_SIZE
[
1
]
image_shape
=
[
cfg
.
DATASET
.
DATA_DIM
,
height
,
width
]
grt_shape
=
[
1
,
height
,
width
]
class_num
=
cfg
.
DATASET
.
NUM_CLASSES
with
fluid
.
program_guard
(
main_prog
,
start_prog
):
with
fluid
.
unique_name
.
guard
():
# 在导出模型的时候,增加图像标准化预处理,减小预测部署时图像的处理流程
# 预测部署时只须对输入图像增加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
])
image
=
fluid
.
layers
.
transpose
(
image
,
[
0
,
3
,
1
,
2
])
origin_shape
=
fluid
.
layers
.
shape
(
image
)[
-
2
:]
# 不同AUG_METHOD方法的resize
...
...
@@ -185,7 +165,7 @@ def build_model(main_prog, start_prog, phase=ModelPhase.TRAIN):
image
=
fluid
.
layers
.
pad2d
(
image
,
paddings
=
paddings
,
pad_value
=
127.5
)
#
normalize
#
normalize
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
)
...
...
@@ -194,6 +174,34 @@ def build_model(main_prog, start_prog, phase=ModelPhase.TRAIN):
# 很有必要,使后面的网络能通过image.shape获取特征图的shape
image
=
fluid
.
layers
.
reshape
(
image
,
shape
=
[
-
1
,
cfg
.
DATASET
.
DATA_DIM
,
height
,
width
])
return
image
,
valid_shape
,
origin_shape
def
build_model
(
main_prog
,
start_prog
,
phase
=
ModelPhase
.
TRAIN
):
if
not
ModelPhase
.
is_valid_phase
(
phase
):
raise
ValueError
(
"ModelPhase {} is not valid!"
.
format
(
phase
))
if
ModelPhase
.
is_train
(
phase
):
width
=
cfg
.
TRAIN_CROP_SIZE
[
0
]
height
=
cfg
.
TRAIN_CROP_SIZE
[
1
]
else
:
width
=
cfg
.
EVAL_CROP_SIZE
[
0
]
height
=
cfg
.
EVAL_CROP_SIZE
[
1
]
image_shape
=
[
cfg
.
DATASET
.
DATA_DIM
,
height
,
width
]
grt_shape
=
[
1
,
height
,
width
]
class_num
=
cfg
.
DATASET
.
NUM_CLASSES
with
fluid
.
program_guard
(
main_prog
,
start_prog
):
with
fluid
.
unique_name
.
guard
():
# 在导出模型的时候,增加图像标准化预处理,减小预测部署时图像的处理流程
# 预测部署时只须对输入图像增加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
,
valid_shape
,
origin_shape
=
export_preprocess
(
origin_image
)
else
:
image
=
fluid
.
layers
.
data
(
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录