Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
X2Paddle
提交
1a3f37c5
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看板
提交
1a3f37c5
编写于
8月 09, 2022
作者:
W
wjj19950828
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fixed reload bug
上级
bdbc0262
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
15 addition
and
7 deletion
+15
-7
tests/onnx/onnxbase.py
tests/onnx/onnxbase.py
+12
-7
x2paddle/core/program.py
x2paddle/core/program.py
+3
-0
未找到文件。
tests/onnx/onnxbase.py
浏览文件 @
1a3f37c5
...
@@ -13,6 +13,8 @@
...
@@ -13,6 +13,8 @@
# limitations under the License.
# limitations under the License.
import
os
import
os
import
sys
import
importlib
import
numpy
as
np
import
numpy
as
np
import
logging
import
logging
import
paddle
import
paddle
...
@@ -187,20 +189,23 @@ class ONNXConverter(object):
...
@@ -187,20 +189,23 @@ class ONNXConverter(object):
make paddle res
make paddle res
"""
"""
# input data
# input data
paddle_numpy_feed
=
list
()
paddle_tensor_feed
=
list
()
paddle_tensor_feed
=
list
()
for
i
in
range
(
len
(
self
.
input_feed
)):
for
i
in
range
(
len
(
self
.
input_feed
)):
paddle_numpy_feed
.
append
(
self
.
input_feed
[
self
.
inputs_name
[
i
]])
paddle_tensor_feed
.
append
(
paddle_tensor_feed
.
append
(
paddle
.
to_tensor
(
self
.
input_feed
[
self
.
inputs_name
[
i
]]))
paddle
.
to_tensor
(
self
.
input_feed
[
self
.
inputs_name
[
i
]]))
if
self
.
run_dynamic
:
if
self
.
run_dynamic
:
paddle_path
=
os
.
path
.
join
(
self
.
pwd
,
self
.
name
,
paddle_path
=
os
.
path
.
join
(
self
.
pwd
,
self
.
name
,
self
.
name
+
'_'
+
str
(
ver
)
+
'_paddle/'
)
self
.
name
+
'_'
+
str
(
ver
)
+
'_paddle/'
)
import
sys
restore
=
paddle
.
load
(
os
.
path
.
join
(
paddle_path
,
"model.pdparams"
))
sys
.
path
.
append
(
paddle_path
)
sys
.
path
.
insert
(
0
,
paddle_path
)
from
x2paddle_code
import
main
import
x2paddle_code
result
=
main
(
*
paddle_tensor_feed
)
# Solve the problem of function overloading caused by traversing the model
importlib
.
reload
(
x2paddle_code
)
model
=
getattr
(
x2paddle_code
,
"ONNXModel"
)()
model
.
set_dict
(
restore
)
model
.
eval
()
result
=
model
(
*
paddle_tensor_feed
)
else
:
else
:
paddle_path
=
os
.
path
.
join
(
paddle_path
=
os
.
path
.
join
(
self
.
pwd
,
self
.
name
,
self
.
pwd
,
self
.
name
,
...
@@ -208,7 +213,7 @@ class ONNXConverter(object):
...
@@ -208,7 +213,7 @@ class ONNXConverter(object):
paddle
.
disable_static
()
paddle
.
disable_static
()
# run
# run
model
=
paddle
.
jit
.
load
(
paddle_path
)
model
=
paddle
.
jit
.
load
(
paddle_path
)
result
=
model
(
*
paddle_
numpy
_feed
)
result
=
model
(
*
paddle_
tensor
_feed
)
# get paddle outputs
# get paddle outputs
if
isinstance
(
result
,
(
tuple
,
list
)):
if
isinstance
(
result
,
(
tuple
,
list
)):
result
=
tuple
(
out
.
numpy
()
for
out
in
result
)
result
=
tuple
(
out
.
numpy
()
for
out
in
result
)
...
...
x2paddle/core/program.py
浏览文件 @
1a3f37c5
...
@@ -21,6 +21,7 @@ import sys
...
@@ -21,6 +21,7 @@ import sys
import
os
import
os
import
six
import
six
import
pickle
import
pickle
import
importlib
from
os
import
path
as
osp
from
os
import
path
as
osp
from
x2paddle.core.util
import
*
from
x2paddle.core.util
import
*
...
@@ -566,6 +567,8 @@ class PaddleGraph(object):
...
@@ -566,6 +567,8 @@ class PaddleGraph(object):
path
=
osp
.
abspath
(
save_dir
)
path
=
osp
.
abspath
(
save_dir
)
sys
.
path
.
insert
(
0
,
save_dir
)
sys
.
path
.
insert
(
0
,
save_dir
)
import
x2paddle_code
import
x2paddle_code
# Solve the problem of function overloading caused by traversing the model
importlib
.
reload
(
x2paddle_code
)
paddle
.
disable_static
()
paddle
.
disable_static
()
restore
=
paddle
.
load
(
osp
.
join
(
save_dir
,
"model.pdparams"
))
restore
=
paddle
.
load
(
osp
.
join
(
save_dir
,
"model.pdparams"
))
model
=
getattr
(
x2paddle_code
,
self
.
name
)()
model
=
getattr
(
x2paddle_code
,
self
.
name
)()
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录