Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
X2Paddle
提交
9b8cd312
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看板
未验证
提交
9b8cd312
编写于
7月 28, 2020
作者:
J
Jason
提交者:
GitHub
7月 28, 2020
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #328 from Channingss/scope
support custom Scope
上级
735be2f1
a10ad9c2
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
20 addition
and
15 deletion
+20
-15
x2paddle/convert.py
x2paddle/convert.py
+7
-2
x2paddle/op_mapper/paddle2onnx/opset9/opset.py
x2paddle/op_mapper/paddle2onnx/opset9/opset.py
+2
-2
x2paddle/op_mapper/paddle2onnx/paddle_op_mapper.py
x2paddle/op_mapper/paddle2onnx/paddle_op_mapper.py
+11
-11
未找到文件。
x2paddle/convert.py
浏览文件 @
9b8cd312
...
...
@@ -195,9 +195,14 @@ def onnx2paddle(model_path, save_dir, params_merge=False):
def
paddle2onnx
(
model_path
,
save_dir
,
opset_version
=
10
):
from
x2paddle.decoder.paddle_decoder
import
PaddleDecoder
from
x2paddle.op_mapper.paddle2onnx.paddle_op_mapper
import
PaddleOpMapper
import
paddle.fluid
as
fluid
model
=
PaddleDecoder
(
model_path
,
'__model__'
,
'__params__'
)
mapper
=
PaddleOpMapper
()
mapper
.
convert
(
model
.
program
,
save_dir
,
opset_number
=
opset_version
)
mapper
.
convert
(
model
.
program
,
save_dir
,
scope
=
fluid
.
global_scope
(),
opset_version
=
opset_version
)
def
main
():
...
...
@@ -264,7 +269,7 @@ def main():
elif
args
.
framework
==
"paddle2onnx"
:
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
:
raise
Exception
(
...
...
x2paddle/op_mapper/paddle2onnx/opset9/opset.py
浏览文件 @
9b8cd312
...
...
@@ -59,7 +59,7 @@ class OpSet9(object):
'Constant'
,
inputs
=
[],
outputs
=
[
name
],
value
=
tensor
)
return
node
def
convert_weights
(
self
,
program
):
def
convert_weights
(
self
,
program
,
scope
=
None
):
var_names
=
program
.
global_block
().
vars
nodes
=
list
()
for
name
in
var_names
:
...
...
@@ -68,7 +68,7 @@ class OpSet9(object):
continue
if
not
var
.
persistable
:
continue
weight
=
np
.
array
(
fluid
.
global_scope
()
.
find_var
(
name
).
get_tensor
())
weight
=
np
.
array
(
scope
.
find_var
(
name
).
get_tensor
())
tensor
=
helper
.
make_tensor
(
name
=
name
,
dims
=
var
.
shape
,
...
...
x2paddle/op_mapper/paddle2onnx/paddle_op_mapper.py
浏览文件 @
9b8cd312
...
...
@@ -33,9 +33,9 @@ class PaddleOpMapper(object):
self
.
name_counter
=
dict
()
self
.
op_set
=
None
def
convert
(
self
,
program
,
save_dir
,
opset_number
=
10
):
self
.
op_set
=
self
.
create_opset
(
opset_
number
)
weight_nodes
=
self
.
op_set
.
convert_weights
(
program
)
def
convert
(
self
,
program
,
save_dir
,
scope
=
None
,
opset_version
=
10
):
self
.
op_set
=
self
.
create_opset
(
opset_
version
)
weight_nodes
=
self
.
op_set
.
convert_weights
(
program
,
scope
=
scope
)
op_nodes
=
list
()
input_nodes
=
list
()
output_nodes
=
list
()
...
...
@@ -77,7 +77,7 @@ class PaddleOpMapper(object):
initializer
=
[],
inputs
=
input_nodes
,
outputs
=
output_nodes
)
opset_imports
=
[
helper
.
make_opsetid
(
""
,
opset_
number
)]
opset_imports
=
[
helper
.
make_opsetid
(
""
,
opset_
version
)]
model
=
helper
.
make_model
(
graph
,
producer_name
=
'X2Paddle'
,
opset_imports
=
opset_imports
)
onnx
.
checker
.
check_model
(
model
)
...
...
@@ -89,20 +89,20 @@ class PaddleOpMapper(object):
print
(
"
\n
Translated model saved in {}"
.
format
(
os
.
path
.
join
(
save_dir
,
'x2paddle_model.onnx'
)))
def
create_opset
(
self
,
opset_
number
):
def
create_opset
(
self
,
opset_
version
=
10
):
run_opset
=
self
.
default_opset
opset
=
''
if
opset_
number
in
self
.
support_opsets
:
run_opset
=
opset_
number
if
opset_
version
in
self
.
support_opsets
:
run_opset
=
opset_
version
else
:
for
support_opset_
number
in
self
.
support_opsets
:
if
support_opset_
number
<
opset_number
:
run_opset
=
support_opset_
number
for
support_opset_
version
in
self
.
support_opsets
:
if
support_opset_
version
<
opset_version
:
run_opset
=
support_opset_
version
else
:
break
print
(
'Now, onnx2paddle support convert onnx model opset_verison {},'
'opset_verison of your onnx model is {}, automatically treated as op_set: {}.'
.
format
(
self
.
support_opsets
,
opset_
number
,
run_opset
))
.
format
(
self
.
support_opsets
,
opset_
version
,
run_opset
))
opset
=
'OpSet'
+
str
(
run_opset
)
return
eval
(
opset
)()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录