Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
X2Paddle
提交
94b08167
X
X2Paddle
项目概览
PaddlePaddle
/
X2Paddle
大约 2 年 前同步成功
通知
329
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看板
提交
94b08167
编写于
4月 02, 2019
作者:
M
Macrobull
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix install script
上级
2bc2b26b
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
63 addition
and
30 deletion
+63
-30
onnx2fluid/README.md
onnx2fluid/README.md
+37
-17
onnx2fluid/examples/gen_some_samples.py
onnx2fluid/examples/gen_some_samples.py
+22
-9
onnx2fluid/onnx2fluid/validation.py
onnx2fluid/onnx2fluid/validation.py
+1
-1
onnx2fluid/onnx2fluid/writer.py
onnx2fluid/onnx2fluid/writer.py
+1
-1
onnx2fluid/setup.cfg
onnx2fluid/setup.cfg
+2
-2
未找到文件。
onnx2fluid/README.md
浏览文件 @
94b08167
# onnx2fluid
# onnx2fluid
[

](LICENSE)
[

](LICENSE)
onnx2fluid支持将onnx模型转换为PaddlePaddle模型,并用于预测。
onnx2fluid支持将onnx模型转换为PaddlePaddle模型,并用于预测
,用户也可以通过将Pytorch模型导出为ONNX格式模型,再使用onnx2fluid将模型转为PaddlePaddle模型
。
## 环境安装
## 环境安装
工具开发过程中,我们在如下环境配置中测试模型转换
,建议使用
[
anaconda
](
https://docs.anaconda.com/anaconda/install
)
工具开发过程中,我们在如下环境配置中测试模型转换
:
> python2 & python3
*
python3.5+ (python2 working in progress)
*
onnx == 1.4.0
*
paddlepaddle == 1.3.0
> onnx == 1.4.0
建议使用
[
anaconda
](
https://docs.anaconda.com/anaconda/install
)
:
> paddlepaddle == 1.3.0
```
shell
```
shell
# 安装onnx
# 安装onnx
...
@@ -20,18 +20,38 @@ onnx2fluid支持将onnx模型转换为PaddlePaddle模型,并用于预测。
...
@@ -20,18 +20,38 @@ onnx2fluid支持将onnx模型转换为PaddlePaddle模型,并用于预测。
conda
install
-c
conda-forge onnx
conda
install
-c
conda-forge onnx
```
```
## Get started
Test with pretrained models from ONNX repositories:
```
shell
python setup.py
install
cd
examples
sh onnx_model_zoo.sh
```
Try exporting from PyTorch to Paddle fluid:
```
shell
python setup.py
install
cd
examples
python gen_some_samples.py
onnx2fluid sample_1.onnx
-t
sample_1.npz
```
## 使用说明
## 使用说明
```
shell
```
shell
python
-m
onnx2fluid
-e
-o
/path/to/export/model /path/of/onnx/model
onnx2fluid
[
-dexy
]
-o
/path/to/export_dir/ /path/of/onnx/model.onnx
optional arguments:
--embed_params
,
-e
try to embed parameters
for
trainable Paddle fluid layers
--no-pedantic
,
-x
process non-standard ONNX ops
--skip-version-conversion
,
-y
skip ONNX op version conversion, workaround
for
RumtimeErrors
--archive
[
ARCHIVE],
-z
[
ARCHIVE]
compress outputs to ZIP file
if
conversion successed
```
```
**VGG19转换**
```
shell
# 下载并解压onnx模型vgg19
wget https://s3.amazonaws.com/download.onnx/models/opset_9/vgg19.tar.gz
tar
xzvf vgg19.tar.gz
# 转换为PaddlePaddle模型
python
-m
onnx2fluid
-e
-o
paddle_model vgg19/model.onnx
```
转换后的PaddlePaddle模型加载可参考文档
[
加载预测模型
](
http://www.paddlepaddle.org/documentation/docs/zh/1.3/api_guides/low_level/inference.html#id4
)
转换后的PaddlePaddle模型加载可参考文档
[
加载预测模型
](
http://www.paddlepaddle.org/documentation/docs/zh/1.3/api_guides/low_level/inference.html#id4
)
onnx2fluid/examples/gen_some_samples.py
浏览文件 @
94b08167
...
@@ -18,6 +18,7 @@ import torch.nn.functional as F
...
@@ -18,6 +18,7 @@ import torch.nn.functional as F
from
onnx2fluid.torch_export_helper
import
export_onnx_with_validation
from
onnx2fluid.torch_export_helper
import
export_onnx_with_validation
prefix
=
'sample_'
idx
=
0
idx
=
0
######### example: RNN ########
######### example: RNN ########
...
@@ -38,7 +39,7 @@ idx = 0
...
@@ -38,7 +39,7 @@ idx = 0
#yp = model(xb)
#yp = model(xb)
#idx += 1
#idx += 1
#print('index: ', idx)
#print('index: ', idx)
#export_onnx_with_validation(model, (xb, ),
't'
+ str(idx),
#export_onnx_with_validation(model, (xb, ),
prefix
+ str(idx),
# ['x'], ['y'],
# ['x'], ['y'],
# verbose=True, training=False)
# verbose=True, training=False)
...
@@ -59,7 +60,7 @@ idx = 0
...
@@ -59,7 +60,7 @@ idx = 0
#yp = model(xb)
#yp = model(xb)
#idx += 1
#idx += 1
#print('index: ', idx)
#print('index: ', idx)
#export_onnx_with_validation(model, (xb, ),
't'
+ str(idx),
#export_onnx_with_validation(model, (xb, ),
prefix
+ str(idx),
# ['x'], ['y'],
# ['x'], ['y'],
# verbose=True, training=False)
# verbose=True, training=False)
...
@@ -83,7 +84,10 @@ yp = model(xb)
...
@@ -83,7 +84,10 @@ yp = model(xb)
idx
+=
1
idx
+=
1
print
(
'index: '
,
idx
)
print
(
'index: '
,
idx
)
export_onnx_with_validation
(
export_onnx_with_validation
(
model
,
(
xb
,
),
't'
+
str
(
idx
),
[
'x'
],
[
'y'
],
verbose
=
True
,
training
=
False
)
model
,
(
xb
,
),
prefix
+
str
(
idx
),
[
'x'
],
[
'y'
],
verbose
=
True
,
training
=
False
)
######## example: compare ########
######## example: compare ########
...
@@ -108,7 +112,7 @@ idx += 1
...
@@ -108,7 +112,7 @@ idx += 1
print
(
'index: '
,
idx
)
print
(
'index: '
,
idx
)
export_onnx_with_validation
(
export_onnx_with_validation
(
model
,
(
xb0
,
xb1
),
model
,
(
xb0
,
xb1
),
't'
+
str
(
idx
),
[
'x0'
,
'x1'
],
[
'ya'
,
'yb'
,
'yc'
],
prefix
+
str
(
idx
),
[
'x0'
,
'x1'
],
[
'ya'
,
'yb'
,
'yc'
],
verbose
=
True
,
verbose
=
True
,
training
=
False
)
training
=
False
)
...
@@ -131,7 +135,7 @@ idx += 1
...
@@ -131,7 +135,7 @@ idx += 1
print
(
'index: '
,
idx
)
print
(
'index: '
,
idx
)
export_onnx_with_validation
(
export_onnx_with_validation
(
model
,
(
theta
,
),
model
,
(
theta
,
),
't'
+
str
(
idx
),
[
'theta'
],
[
'grid'
],
prefix
+
str
(
idx
),
[
'theta'
],
[
'grid'
],
verbose
=
True
,
verbose
=
True
,
training
=
False
)
training
=
False
)
...
@@ -157,7 +161,10 @@ yp = model(xb)
...
@@ -157,7 +161,10 @@ yp = model(xb)
idx
+=
1
idx
+=
1
print
(
'index: '
,
idx
)
print
(
'index: '
,
idx
)
export_onnx_with_validation
(
export_onnx_with_validation
(
model
,
(
xb
,
),
't'
+
str
(
idx
),
[
'x'
],
[
'y'
],
verbose
=
True
,
training
=
False
)
model
,
(
xb
,
),
prefix
+
str
(
idx
),
[
'x'
],
[
'y'
],
verbose
=
True
,
training
=
False
)
######## example: conv2d ########
######## example: conv2d ########
...
@@ -183,7 +190,10 @@ yp = model(xb)
...
@@ -183,7 +190,10 @@ yp = model(xb)
idx
+=
1
idx
+=
1
print
(
'index: '
,
idx
)
print
(
'index: '
,
idx
)
export_onnx_with_validation
(
export_onnx_with_validation
(
model
,
(
xb
,
),
't'
+
str
(
idx
),
[
'x'
],
[
'y'
],
verbose
=
True
,
training
=
False
)
model
,
(
xb
,
),
prefix
+
str
(
idx
),
[
'x'
],
[
'y'
],
verbose
=
True
,
training
=
False
)
######### example: conv1d ########
######### example: conv1d ########
#
#
...
@@ -203,7 +213,7 @@ export_onnx_with_validation(
...
@@ -203,7 +213,7 @@ export_onnx_with_validation(
#yp = model(xb)
#yp = model(xb)
#idx += 1
#idx += 1
#print('index: ', idx)
#print('index: ', idx)
#export_onnx_with_validation(model, (xb, ),
't'
+ str(idx),
#export_onnx_with_validation(model, (xb, ),
prefix
+ str(idx),
# ['x'], ['y'],
# ['x'], ['y'],
# verbose=True, training=False)
# verbose=True, training=False)
...
@@ -224,4 +234,7 @@ yp = model(xb)
...
@@ -224,4 +234,7 @@ yp = model(xb)
idx
+=
1
idx
+=
1
print
(
'index: '
,
idx
)
print
(
'index: '
,
idx
)
export_onnx_with_validation
(
export_onnx_with_validation
(
model
,
(
xb
,
),
't'
+
str
(
idx
),
[
'y'
],
[
'y'
],
verbose
=
True
,
training
=
False
)
model
,
(
xb
,
),
prefix
+
str
(
idx
),
[
'y'
],
[
'y'
],
verbose
=
True
,
training
=
False
)
onnx2fluid/onnx2fluid/validation.py
浏览文件 @
94b08167
...
@@ -86,7 +86,7 @@ def validate(fluid_model_filename,
...
@@ -86,7 +86,7 @@ def validate(fluid_model_filename,
executor
=
exe
,
dirname
=
fluid_model_dir
,
main_program
=
prog
)
executor
=
exe
,
dirname
=
fluid_model_dir
,
main_program
=
prog
)
logger
.
info
(
'weight load passed'
)
logger
.
info
(
'weight load passed'
)
else
:
else
:
raise
ValueError
(
'unsupported Paddle fluid model'
)
raise
ValueError
(
'unsupported Paddle fluid model
filename
'
)
# load data
# load data
logger
.
info
(
'using golden data %s'
,
golden_data_filename
)
logger
.
info
(
'using golden data %s'
,
golden_data_filename
)
...
...
onnx2fluid/onnx2fluid/writer.py
浏览文件 @
94b08167
...
@@ -251,7 +251,7 @@ class Program(object):
...
@@ -251,7 +251,7 @@ class Program(object):
def
IntermediateOp
(
self
,
domain
,
op_type
,
*
args
,
**
kwargs
):
def
IntermediateOp
(
self
,
domain
,
op_type
,
*
args
,
**
kwargs
):
"""
"""
convert an intermediate ONNX op declaring
just desc
only
convert an intermediate ONNX op declaring
in desc program
only
"""
"""
code_mutable
=
self
.
code_mutable
code_mutable
=
self
.
code_mutable
...
...
onnx2fluid/setup.cfg
浏览文件 @
94b08167
...
@@ -48,12 +48,12 @@ install_requires =
...
@@ -48,12 +48,12 @@ install_requires =
# 自动添加被版本控制的数据文件
# 自动添加被版本控制的数据文件
include_package_data = True
include_package_data = True
# 项目是纯py项目,可以直接执行zip源码包
# 项目是纯py项目,可以直接执行zip源码包
zip_safe =
Fals
e
zip_safe =
Tru
e
# 可以通过以下配置将指定的函数变成命令行工具,允许用户直接执行
# 可以通过以下配置将指定的函数变成命令行工具,允许用户直接执行
[options.entry_points]
[options.entry_points]
console_scripts =
console_scripts =
onnx2fluid = onnx2fluid.
cmdline:main
onnx2fluid = onnx2fluid.
__main__
# 可以通过以下配置向包中添加conf或data等非py文件,安装时会一同安装到site-packages目录下
# 可以通过以下配置向包中添加conf或data等非py文件,安装时会一同安装到site-packages目录下
# 仅支持文件,不支持目录,但可以使用通配
# 仅支持文件,不支持目录,但可以使用通配
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录