提交 94b08167 编写于 作者: M Macrobull

fix install script

上级 2bc2b26b
# onnx2fluid # onnx2fluid
[![License](https://img.shields.io/badge/license-Apache%202-blue.svg)](LICENSE)
[![License](https://img.shields.io/badge/license-Apache%202-blue.svg)](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)
...@@ -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)
...@@ -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)
......
...@@ -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
......
...@@ -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 = False zip_safe = True
# 可以通过以下配置将指定的函数变成命令行工具,允许用户直接执行 # 可以通过以下配置将指定的函数变成命令行工具,允许用户直接执行
[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.
先完成此消息的编辑!
想要评论请 注册