Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
X2Paddle
提交
ea91537b
X
X2Paddle
项目概览
PaddlePaddle
/
X2Paddle
大约 1 年 前同步成功
通知
328
Star
698
Fork
167
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
26
列表
看板
标记
里程碑
合并请求
4
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
X
X2Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
26
Issue
26
列表
看板
标记
里程碑
合并请求
4
合并请求
4
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
ea91537b
编写于
10月 31, 2019
作者:
M
mamingjie-China
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add params merge
上级
1b2b70f7
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
21 addition
and
21 deletion
+21
-21
x2paddle/convert.py
x2paddle/convert.py
+19
-19
x2paddle/core/op_mapper.py
x2paddle/core/op_mapper.py
+2
-2
未找到文件。
x2paddle/convert.py
浏览文件 @
ea91537b
...
@@ -68,7 +68,7 @@ def arg_parser():
...
@@ -68,7 +68,7 @@ def arg_parser():
action
=
"store_true"
,
action
=
"store_true"
,
default
=
False
,
default
=
False
,
help
=
"define input shape for tf model"
)
help
=
"define input shape for tf model"
)
parser
.
add_argument
(
"--param_merge"
,
parser
.
add_argument
(
"--param
s
_merge"
,
"-pm"
,
"-pm"
,
action
=
"store_true"
,
action
=
"store_true"
,
default
=
False
,
default
=
False
,
...
@@ -81,7 +81,7 @@ def tf2paddle(model_path,
...
@@ -81,7 +81,7 @@ def tf2paddle(model_path,
save_dir
,
save_dir
,
without_data_format_optimization
=
False
,
without_data_format_optimization
=
False
,
define_input_shape
=
False
,
define_input_shape
=
False
,
param_merge
=
False
):
param
s
_merge
=
False
):
# check tensorflow installation and version
# check tensorflow installation and version
try
:
try
:
import
os
import
os
...
@@ -127,10 +127,10 @@ def tf2paddle(model_path,
...
@@ -127,10 +127,10 @@ def tf2paddle(model_path,
optimizer
.
merge_bias
()
optimizer
.
merge_bias
()
optimizer
.
make_nchw_input_output
()
optimizer
.
make_nchw_input_output
()
optimizer
.
remove_transpose
()
optimizer
.
remove_transpose
()
mapper
.
save_inference_model
(
save_dir
,
param_merge
)
mapper
.
save_inference_model
(
save_dir
,
param
s
_merge
)
def
caffe2paddle
(
proto
,
weight
,
save_dir
,
caffe_proto
,
param_merge
=
False
):
def
caffe2paddle
(
proto
,
weight
,
save_dir
,
caffe_proto
,
param
s
_merge
=
False
):
from
x2paddle.decoder.caffe_decoder
import
CaffeDecoder
from
x2paddle.decoder.caffe_decoder
import
CaffeDecoder
from
x2paddle.op_mapper.caffe_op_mapper
import
CaffeOpMapper
from
x2paddle.op_mapper.caffe_op_mapper
import
CaffeOpMapper
from
x2paddle.optimizer.caffe_optimizer
import
CaffeOptimizer
from
x2paddle.optimizer.caffe_optimizer
import
CaffeOptimizer
...
@@ -147,10 +147,10 @@ def caffe2paddle(proto, weight, save_dir, caffe_proto, param_merge=False):
...
@@ -147,10 +147,10 @@ def caffe2paddle(proto, weight, save_dir, caffe_proto, param_merge=False):
optimizer
=
CaffeOptimizer
(
mapper
)
optimizer
=
CaffeOptimizer
(
mapper
)
optimizer
.
merge_bn_scale
()
optimizer
.
merge_bn_scale
()
optimizer
.
merge_op_activation
()
optimizer
.
merge_op_activation
()
mapper
.
save_inference_model
(
save_dir
,
param_merge
)
mapper
.
save_inference_model
(
save_dir
,
param
s
_merge
)
def
onnx2paddle
(
model_path
,
save_dir
,
param_merge
=
False
):
def
onnx2paddle
(
model_path
,
save_dir
,
param
s
_merge
=
False
):
# check onnx installation and version
# check onnx installation and version
try
:
try
:
import
onnx
import
onnx
...
@@ -173,7 +173,7 @@ def onnx2paddle(model_path, save_dir, param_merge=False):
...
@@ -173,7 +173,7 @@ def onnx2paddle(model_path, save_dir, param_merge=False):
optimizer
=
ONNXOptimizer
(
mapper
)
optimizer
=
ONNXOptimizer
(
mapper
)
optimizer
.
delete_redundance_code
()
optimizer
.
delete_redundance_code
()
mapper
.
save_inference_model
(
save_dir
,
param_merge
)
mapper
.
save_inference_model
(
save_dir
,
param
s
_merge
)
def
main
():
def
main
():
...
@@ -208,29 +208,29 @@ def main():
...
@@ -208,29 +208,29 @@ def main():
assert
args
.
model
is
not
None
,
"--model should be defined while translating tensorflow model"
assert
args
.
model
is
not
None
,
"--model should be defined while translating tensorflow model"
without_data_format_optimization
=
False
without_data_format_optimization
=
False
define_input_shape
=
False
define_input_shape
=
False
param_merge
=
False
param
s
_merge
=
False
if
args
.
without_data_format_optimization
:
if
args
.
without_data_format_optimization
:
without_data_format_optimization
=
True
without_data_format_optimization
=
True
if
args
.
define_input_shape
:
if
args
.
define_input_shape
:
define_input_shape
=
True
define_input_shape
=
True
if
args
.
param_merge
:
if
args
.
param
s
_merge
:
param_merge
=
True
param
s
_merge
=
True
tf2paddle
(
args
.
model
,
args
.
save_dir
,
without_data_format_optimization
,
tf2paddle
(
args
.
model
,
args
.
save_dir
,
without_data_format_optimization
,
define_input_shape
,
param_merge
)
define_input_shape
,
param
s
_merge
)
elif
args
.
framework
==
"caffe"
:
elif
args
.
framework
==
"caffe"
:
assert
args
.
prototxt
is
not
None
and
args
.
weight
is
not
None
,
"--prototxt and --weight should be defined while translating caffe model"
assert
args
.
prototxt
is
not
None
and
args
.
weight
is
not
None
,
"--prototxt and --weight should be defined while translating caffe model"
param_merge
=
False
param
s
_merge
=
False
if
args
.
param_merge
:
if
args
.
param
s
_merge
:
param_merge
=
True
param
s
_merge
=
True
caffe2paddle
(
args
.
prototxt
,
args
.
weight
,
args
.
save_dir
,
caffe2paddle
(
args
.
prototxt
,
args
.
weight
,
args
.
save_dir
,
args
.
caffe_proto
,
param_merge
)
args
.
caffe_proto
,
param
s
_merge
)
elif
args
.
framework
==
"onnx"
:
elif
args
.
framework
==
"onnx"
:
assert
args
.
model
is
not
None
,
"--model should be defined while translating onnx model"
assert
args
.
model
is
not
None
,
"--model should be defined while translating onnx model"
param_merge
=
False
param
s
_merge
=
False
if
args
.
param_merge
:
if
args
.
param
s
_merge
:
param_merge
=
True
param
s
_merge
=
True
onnx2paddle
(
args
.
model
,
args
.
save_dir
,
param_merge
)
onnx2paddle
(
args
.
model
,
args
.
save_dir
,
param
s
_merge
)
else
:
else
:
raise
Exception
(
"--framework only support tensorflow/caffe/onnx now"
)
raise
Exception
(
"--framework only support tensorflow/caffe/onnx now"
)
...
...
x2paddle/core/op_mapper.py
浏览文件 @
ea91537b
...
@@ -110,7 +110,7 @@ class OpMapper(object):
...
@@ -110,7 +110,7 @@ class OpMapper(object):
self
.
add_codes
(
"import paddle.fluid as fluid"
)
self
.
add_codes
(
"import paddle.fluid as fluid"
)
self
.
add_codes
(
""
)
self
.
add_codes
(
""
)
def
save_inference_model
(
self
,
save_dir
,
param_merge
):
def
save_inference_model
(
self
,
save_dir
,
param
s
_merge
):
self
.
save_python_model
(
save_dir
)
self
.
save_python_model
(
save_dir
)
import
sys
import
sys
...
@@ -138,7 +138,7 @@ class OpMapper(object):
...
@@ -138,7 +138,7 @@ class OpMapper(object):
py_code_dir
,
py_code_dir
,
fluid
.
default_main_program
(),
fluid
.
default_main_program
(),
predicate
=
if_exist
)
predicate
=
if_exist
)
if
param_merge
:
if
param
s
_merge
:
fluid
.
io
.
save_inference_model
(
dirname
=
os
.
path
.
join
(
fluid
.
io
.
save_inference_model
(
dirname
=
os
.
path
.
join
(
save_dir
,
"inference_model"
),
save_dir
,
"inference_model"
),
feeded_var_names
=
input_names
,
feeded_var_names
=
input_names
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录