Skip to content

Commit 3171997

Browse files
authored
Merge pull request #142 from Channingss/exporter/v0.5.1
change onnx_pb2.py generated by protobuf>3.12.0 to lower version protobuf depended onnx_pb.py
2 parents b0ca4a7 + 65693dc commit 3171997

File tree

9 files changed

+689
-859
lines changed

9 files changed

+689
-859
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ paddle2onnx is a toolkit for converting trained model to **ONNX** from **PaddleP
4545
## 使用方式
4646
### 静态图模型导出
4747

48-
paddle2onnx --model_dir paddle_model --save_file onnx_file --onnx_opset 10 --enable_onnx_checker True
48+
paddle2onnx --model_dir paddle_model --save_file onnx_file --opset_version 10 --enable_onnx_checker True
4949

5050
### 动态图模型导出
5151

@@ -56,14 +56,14 @@ paddle2onnx is a toolkit for converting trained model to **ONNX** from **PaddleP
5656
|----------|--------------|
5757
|--model_dir | 指定包含Paddle模型'\_\_model\_\_'和参数'\_\_params\_\_'的路径, 由`paddle.fluid.io.save_inference_model`保存得到|
5858
|--save_file | 指定转换后的模型保存目录路径 |
59-
|--onnx_opset | **[可选]** 该参数可设置转换为ONNX的OpSet版本,目前比较稳定地支持9、10、11三个版本,默认为10 |
59+
|--opset_version | **[可选]** 该参数可设置转换为ONNX的OpSet版本,目前比较稳定地支持9、10、11三个版本,默认为9 |
6060
|--enable_onnx_checker| **[可选]** 是否检查导出为ONNX模型的正确性, 建议打开此开关。若指定为True,需要安装 pip install onnx==1.7.0, 默认为False|
6161
|--version |**[可选]** 查看paddle2onnx版本 |
6262

6363
## 相关文档
6464

6565
- [paddle2onnx测试模型库](docs/model_zoo.md)
66-
- [paddle2onnx支持准换算子列表](docs/op_list.md)
66+
- [paddle2onnx支持转换算子列表](docs/op_list.md)
6767

6868

6969
## License

paddle2onnx/command.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,16 @@ def program2onnx(model_dir,
6464
enable_onnx_checker=False):
6565
try:
6666
import paddle
67-
v0, v1, v2 = paddle.__version__.split('.')
68-
if v0 == '0' and v1 == '0' and v2 == '0':
69-
logging.warning("You are use develop version of paddlepaddle")
70-
elif int(v0) != 1 or int(v1) < 8:
71-
raise ImportError("paddlepaddle>=1.8.0 is required")
7267
except:
7368
logging.error(
7469
"paddlepaddle not installed, use \"pip install paddlepaddle\"")
70+
71+
v0, v1, v2 = paddle.__version__.split('.')
72+
if v0 == '0' and v1 == '0' and v2 == '0':
73+
logging.warning("You are use develop version of paddlepaddle")
74+
elif int(v0) <= 1 and int(v1) < 8:
75+
raise ImportError("paddlepaddle>=1.8.0 is required")
76+
7577
import paddle2onnx as p2o
7678
# convert model save with 'paddle.fluid.io.save_inference_model'
7779
if hasattr(paddle, 'enable_static'):
@@ -107,7 +109,7 @@ def main():
107109
format(paddle2onnx.__version__))
108110
return
109111

110-
assert args.model_dir is not None, "--model should be defined while translating paddle model to onnx"
112+
assert args.model_dir is not None, "--model_dir should be defined while translating paddle model to onnx"
111113
assert args.save_file is not None, "--save_file should be defined while translating paddle model to onnx"
112114
program2onnx(
113115
args.model_dir,

paddle2onnx/constant/dtypes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import numpy as np
1616
import paddle.fluid.core as core
1717
from paddle2onnx.onnx_helper import helper
18-
from paddle2onnx.onnx_helper.onnx_pb2 import TensorProto
18+
from paddle2onnx.onnx_helper.onnx_pb import TensorProto
1919

2020
ONNX = TensorProto
2121

paddle2onnx/onnx_helper/helper.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
from six import text_type, integer_types, binary_type
2626

2727
import google.protobuf.message
28-
from .onnx_pb2 import TensorProto, SparseTensorProto, AttributeProto, ValueInfoProto, TensorShapeProto, \
28+
from .onnx_pb import TensorProto, SparseTensorProto, AttributeProto, ValueInfoProto, TensorShapeProto, \
2929
NodeProto, ModelProto, GraphProto, OperatorSetIdProto, TypeProto, IR_VERSION
3030
from paddle2onnx.onnx_helper import mapping
3131
from .mapping import STORAGE_TENSOR_TYPE_TO_FIELD

paddle2onnx/onnx_helper/mapping.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
from __future__ import print_function
2121
from __future__ import unicode_literals
2222

23-
from .onnx_pb2 import TensorProto
23+
from .onnx_pb import TensorProto
2424
#from typing import Text, Any
2525
import numpy as np # type: ignore
2626

paddle2onnx/onnx_helper/onnx_pb2.py renamed to paddle2onnx/onnx_helper/onnx_ONNX_REL_1_7_ml_pb2.py

Lines changed: 646 additions & 843 deletions
Large diffs are not rendered by default.

paddle2onnx/onnx_helper/onnx_pb.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# Copyright (c) ONNX Project Contributors.
16+
# Licensed under the MIT license.
17+
18+
# This file is generated by setup.py. DO NOT EDIT!
19+
20+
from __future__ import absolute_import
21+
from __future__ import division
22+
from __future__ import print_function
23+
from __future__ import unicode_literals
24+
25+
from .onnx_ONNX_REL_1_7_ml_pb2 import * # noqa

paddle2onnx/op_mapper/detection/multiclass_nms.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ def opset_10(cls, graph, node, **kw):
3434
if normalized == False:
3535
logging.warn(
3636
"The parameter normalized of multiclass_nms OP of Paddle is False, which has diff with ONNX." \
37-
" Please set normalized=True in multiclass_nms of Paddle, see doc Q4 in" \
38-
" https://github.com/PaddlePaddle/X2Paddle/blob/develop/FAQ.md")
37+
" Please set normalized=True in multiclass_nms of Paddle, see doc Q1 in" \
38+
" https://github.com/PaddlePaddle/paddle2onnx/blob/develop/FAQ.md")
3939

4040
#convert the paddle attribute to onnx tensor
4141
node_score_threshold = graph.make_node(

paddle2onnx/op_mapper/detection/yolo_box.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ def is_static_shape(shape):
2626
if len(shape) > 1 and shape.count(-1) > 1:
2727
raise Exception(
2828
"Converting this model to ONNX need with static input shape," \
29-
" please fix input shape of this model, see doc Q5 in" \
30-
" https://github.com/PaddlePaddle/X2Paddle/blob/develop/FAQ.md."
29+
" please fix input shape of this model, see doc Q2 in" \
30+
" https://github.com/PaddlePaddle/paddle2onnx/blob/develop/FAQ.md."
3131
)
3232

3333

0 commit comments

Comments
 (0)