Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
X2Paddle
提交
162d160f
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看板
提交
162d160f
编写于
11月 02, 2020
作者:
S
SunAhong1993
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix the modify
上级
77565629
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
30 addition
and
13 deletion
+30
-13
x2paddle/convert.py
x2paddle/convert.py
+30
-13
未找到文件。
x2paddle/convert.py
浏览文件 @
162d160f
...
@@ -67,8 +67,8 @@ def arg_parser():
...
@@ -67,8 +67,8 @@ def arg_parser():
parser
.
add_argument
(
parser
.
add_argument
(
"--without_data_format_optimization"
,
"--without_data_format_optimization"
,
"-wo"
,
"-wo"
,
action
=
"store_true"
,
type
=
_text_type
,
default
=
False
,
default
=
"True"
,
help
=
"tf model conversion without data format optimization"
)
help
=
"tf model conversion without data format optimization"
)
parser
.
add_argument
(
parser
.
add_argument
(
"--define_input_shape"
,
"--define_input_shape"
,
...
@@ -135,14 +135,21 @@ def tf2paddle(model_path,
...
@@ -135,14 +135,21 @@ def tf2paddle(model_path,
from
x2paddle.decoder.tf_decoder
import
TFDecoder
from
x2paddle.decoder.tf_decoder
import
TFDecoder
from
x2paddle.op_mapper.tf_op_mapper
import
TFOpMapper
from
x2paddle.op_mapper.tf_op_mapper
import
TFOpMapper
from
x2paddle.op_mapper.tf_op_mapper_nhwc
import
TFOpMapperNHWC
from
x2paddle.optimizer.tensorflow.bias
import
BiasOpt
from
x2paddle.optimizer.tf_optimizer
import
TFOptimizer
from
x2paddle.optimizer.tensorflow.transpose
import
TransposeOpt
from
x2paddle.optimizer.tensorflow.batch_norm
import
BatchNormOpt
print
(
"Now translating model from tensorflow to paddle."
)
print
(
"Now translating model from tensorflow to paddle."
)
model
=
TFDecoder
(
model_path
,
define_input_shape
=
define_input_shape
)
model
=
TFDecoder
(
model_path
,
define_input_shape
=
define_input_shape
)
mapper
=
TFOpMapper
NHWC
(
model
)
mapper
=
TFOpMapper
(
model
)
program
.
build
()
program
.
build
()
bias_opt
=
BiasOpt
()
transpose_opt
=
TransposeOpt
()
batch_norm_opt
=
BatchNormOpt
()
bias_opt
.
run
(
program
)
batch_norm_opt
.
run
(
program
)
transpose_opt
.
run
(
program
)
program
.
gen_model
(
save_dir
)
program
.
gen_model
(
save_dir
)
...
@@ -172,8 +179,8 @@ def onnx2paddle(model_path, save_dir, params_merge=False):
...
@@ -172,8 +179,8 @@ def onnx2paddle(model_path, save_dir, params_merge=False):
try
:
try
:
import
onnx
import
onnx
version
=
onnx
.
version
.
version
version
=
onnx
.
version
.
version
if
version
!=
'1.6.0'
:
if
version
<
'1.6.0'
:
print
(
"[ERROR] onnx
=
=1.6.0 is required"
)
print
(
"[ERROR] onnx
>
=1.6.0 is required"
)
return
return
except
:
except
:
print
(
"[ERROR] onnx is not installed, use
\"
pip install onnx==1.6.0
\"
."
)
print
(
"[ERROR] onnx is not installed, use
\"
pip install onnx==1.6.0
\"
."
)
...
@@ -229,11 +236,21 @@ def pytorch2paddle(model_path, save_dir, jit_type, input_files):
...
@@ -229,11 +236,21 @@ def pytorch2paddle(model_path, save_dir, jit_type, input_files):
def
paddle2onnx
(
model_path
,
save_dir
,
opset_version
=
10
):
def
paddle2onnx
(
model_path
,
save_dir
,
opset_version
=
10
):
from
x2paddle.decoder.paddle_decoder
import
PaddleDecoder
import
paddle.fluid
as
fluid
from
x2paddle.op_mapper.paddle2onnx.paddle_op_mapper
import
PaddleOpMapper
try
:
model
=
PaddleDecoder
(
model_path
,
'__model__'
,
'__params__'
)
import
paddle2onnx
mapper
=
PaddleOpMapper
()
except
:
mapper
.
convert
(
model
.
program
,
save_dir
,
opset_number
=
opset_version
)
print
(
"[ERROR] paddle2onnx not installed, use
\"
pip install paddle2onnx
\"
"
)
import
paddle2onnx
as
p2o
model
=
p2o
.
PaddleDecoder
(
model_path
,
'__model__'
,
'__params__'
)
mapper
=
p2o
.
PaddleOpMapper
()
mapper
.
convert
(
model
.
program
,
save_dir
,
scope
=
fluid
.
global_scope
(),
opset_version
=
opset_version
)
def
main
():
def
main
():
...
@@ -304,7 +321,7 @@ def main():
...
@@ -304,7 +321,7 @@ def main():
elif
args
.
framework
==
"paddle2onnx"
:
elif
args
.
framework
==
"paddle2onnx"
:
assert
args
.
model
is
not
None
,
"--model should be defined while translating paddle model to onnx"
assert
args
.
model
is
not
None
,
"--model should be defined while translating paddle model to onnx"
paddle2onnx
(
args
.
model
,
args
.
save_dir
,
args
.
onnx_opset
)
paddle2onnx
(
args
.
model
,
args
.
save_dir
,
opset_version
=
args
.
onnx_opset
)
else
:
else
:
raise
Exception
(
raise
Exception
(
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录