Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
路上走着呢
X2Paddle
提交
92bd03a5
X
X2Paddle
项目概览
路上走着呢
/
X2Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / X2Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
X
X2Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
92bd03a5
编写于
11月 23, 2020
作者:
S
SunAhong1993
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add develop diff
上级
6cdf2161
变更
13
隐藏空白更改
内联
并排
Showing
13 changed file
with
31 addition
and
43 deletion
+31
-43
README.md
README.md
+5
-3
tools/README.md
tools/README.md
+1
-1
x2paddle/convert.py
x2paddle/convert.py
+8
-33
x2paddle/core/program.py
x2paddle/core/program.py
+1
-0
x2paddle/decoder/caffe_decoder.py
x2paddle/decoder/caffe_decoder.py
+3
-1
x2paddle/decoder/onnx_decoder.py
x2paddle/decoder/onnx_decoder.py
+5
-1
x2paddle/decoder/onnx_shape_inference.py
x2paddle/decoder/onnx_shape_inference.py
+2
-2
x2paddle/op_mapper/dygraph/pytorch2paddle/aten.py
x2paddle/op_mapper/dygraph/pytorch2paddle/aten.py
+1
-0
x2paddle/op_mapper/dygraph/pytorch2paddle/prim.py
x2paddle/op_mapper/dygraph/pytorch2paddle/prim.py
+1
-0
x2paddle/op_mapper/dygraph/pytorch2paddle/prim2code.py
x2paddle/op_mapper/dygraph/pytorch2paddle/prim2code.py
+1
-0
x2paddle/op_mapper/dygraph/pytorch2paddle/pytorch_op_mapper.py
...dle/op_mapper/dygraph/pytorch2paddle/pytorch_op_mapper.py
+1
-0
x2paddle/op_mapper/dygraph/tf2paddle/tf_op_mapper.py
x2paddle/op_mapper/dygraph/tf2paddle/tf_op_mapper.py
+1
-1
x2paddle/op_mapper/static/tf2paddle/tf_op_mapper.py
x2paddle/op_mapper/static/tf2paddle/tf_op_mapper.py
+1
-1
未找到文件。
README.md
浏览文件 @
92bd03a5
...
...
@@ -10,7 +10,7 @@ X2Paddle在多个主流的CV模型上,测试过TensorFlow/Caffe/ONNX模型的
## 环境依赖
python == 2.7 | python >= 3.5
paddlepaddle >=
1.8
.0
paddlepaddle >=
2.0
.0
**按需安装以下依赖**
tensorflow : tensorflow == 1.14.0
...
...
@@ -49,11 +49,14 @@ x2paddle --framework=onnx --model=onnx_model.onnx --save_dir=pd_model
### PyTorch
> PyTorch不支持命令行使用方式,详见[PyTorch2Paddle](pytorch2paddle.md)
### Paddle2ONNX
> Paddle2ONNX功能已迁移至新的github: https://github.com/PaddlePaddle/paddle2onnx, 欢迎大家去新的代码仓库查看详细介绍以及新功能。
### 参数选项
| 参数 | |
|----------|--------------|
|--framework | 源模型类型 (tensorflow、caffe、onnx
、paddle2onnx
) |
|--framework | 源模型类型 (tensorflow、caffe、onnx) |
|--prototxt | 当framework为caffe时,该参数指定caffe模型的proto文件路径 |
|--weight | 当framework为caffe时,该参数指定caffe模型的参数文件路径 |
|--save_dir | 指定转换后的模型保存目录路径 |
...
...
@@ -61,7 +64,6 @@ x2paddle --framework=onnx --model=onnx_model.onnx --save_dir=pd_model
|--caffe_proto |
**[可选]**
由caffe.proto编译成caffe_pb2.py文件的存放路径,当存在自定义Layer时使用,默认为None |
|--define_input_shape |
**[可选]**
For TensorFlow, 当指定该参数时,强制用户输入每个Placeholder的shape,见
[
文档Q2
](
FAQ.md
)
|
|--params_merge |
**[可选]**
当指定该参数时,转换完成后,inference_model中的所有模型参数将合并保存为一个文件__params__ |
|--onnx_opset |
**[可选]**
当framework为paddle2onnx时,该参数可设置转换为ONNX的OpSet版本,目前支持9、10、11,默认为10 |
...
...
tools/README.md
浏览文件 @
92bd03a5
...
...
@@ -4,7 +4,7 @@
```
python tools/check_for_lite.py paddle_model/inference_model/__model__
```
> 附:check_for_lite工具并不能完全判断模型是否被支持,PaddleLite详细支持的算子请参考[PaddleLite支持算子集](https://github.com/PaddlePaddle/Paddle-Lite/blob/develop/docs/introduction/support_operation_list.md)
### 二、模型参数合并
X2Paddle转换后产出的路径下包括两个目录,
...
...
x2paddle/convert.py
浏览文件 @
92bd03a5
...
...
@@ -64,24 +64,12 @@ def arg_parser():
action
=
"store_true"
,
default
=
False
,
help
=
"get version of x2paddle"
)
parser
.
add_argument
(
"--without_data_format_optimization"
,
"-wo"
,
type
=
_text_type
,
default
=
"True"
,
help
=
"tf model conversion without data format optimization"
)
parser
.
add_argument
(
"--define_input_shape"
,
"-d"
,
action
=
"store_true"
,
default
=
False
,
help
=
"define input shape for tf model"
)
parser
.
add_argument
(
"--onnx_opset"
,
"-oo"
,
type
=
int
,
default
=
10
,
help
=
"when paddle2onnx set onnx opset version to export"
)
parser
.
add_argument
(
"--params_merge"
,
"-pm"
,
...
...
@@ -95,6 +83,12 @@ def arg_parser():
default
=
"dygraph"
,
help
=
"define the paddle model type after converting(dygraph/static)"
)
parser
.
add_argument
(
"--without_data_format_optimization"
,
"-wo"
,
type
=
_text_type
,
default
=
"True"
,
help
=
"tf model conversion without data format optimization"
)
return
parser
...
...
@@ -246,24 +240,6 @@ def pytorch2paddle(module, save_dir, jit_type="trace", input_examples=None):
mapper
.
paddle_graph
.
gen_model
(
save_dir
,
jit_type
=
jit_type
)
def
paddle2onnx
(
model_path
,
save_dir
,
opset_version
=
10
):
import
paddle.fluid
as
fluid
try
:
import
paddle2onnx
except
:
print
(
"[ERROR] paddle2onnx not installed, use
\"
pip install paddle2onnx
\"
"
)
import
paddle2onnx
as
p2o
model
=
p2o
.
PaddleDecoder
(
model_path
,
'__model__'
,
'__params__'
)
mapper
=
p2o
.
PaddleOpMapper
()
mapper
.
convert
(
model
.
program
,
save_dir
,
scope
=
fluid
.
global_scope
(),
opset_version
=
opset_version
)
def
main
():
if
len
(
sys
.
argv
)
<
2
:
print
(
"Use
\"
x2paddle -h
\"
to print the help information"
)
...
...
@@ -328,12 +304,11 @@ def main():
params_merge
=
True
onnx2paddle
(
args
.
model
,
args
.
save_dir
,
args
.
paddle_type
,
params_merge
)
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
,
opset_version
=
args
.
onnx_opset
)
print
(
"Paddle to ONNX tool has been migrated to the new github: https://github.com/PaddlePaddle/paddle2onnx"
)
else
:
raise
Exception
(
"--framework only support tensorflow/caffe/onnx
/paddle2onnx
now"
)
"--framework only support tensorflow/caffe/onnx now"
)
if
__name__
==
"__main__"
:
...
...
x2paddle/core/program.py
浏览文件 @
92bd03a5
# -*- coding:UTF-8 -*-
# Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"
...
...
x2paddle/decoder/caffe_decoder.py
浏览文件 @
92bd03a5
...
...
@@ -110,6 +110,8 @@ class CaffeGraph(Graph):
if
not
exclude
:
filtered_layers
.
append
(
layer
)
# Guard against dupes.
if
layer
.
name
in
filtered_layer_names
:
layer
.
name
+=
"_0"
assert
layer
.
name
not
in
filtered_layer_names
filtered_layer_names
.
add
(
layer
.
name
)
else
:
...
...
@@ -230,7 +232,7 @@ class CaffeGraph(Graph):
assert
input_node_name
in
self
.
node_map
,
'The {} isn
\'
t a valid node'
.
format
(
name
)
input_node
=
self
.
node_map
[
input_node_name
]
if
len
(
input_node
.
layer
.
top
)
>
1
:
if
len
(
input_node
.
layer
.
top
)
>
1
and
input_node
.
layer_type
!=
"Input"
:
need_idx
=
list
(
input_node
.
layer
.
top
).
index
(
node
.
layer
.
bottom
[
idx
])
name
=
input_node_name
+
':'
+
str
(
need_idx
)
else
:
...
...
x2paddle/decoder/onnx_decoder.py
浏览文件 @
92bd03a5
...
...
@@ -18,7 +18,7 @@ from x2paddle.decoder.onnx_shape_inference import SymbolicShapeInference
from
onnx.checker
import
ValidationError
from
onnx.checker
import
check_model
from
onnx.utils
import
polish_model
from
onnx
import
helper
from
onnx
import
helper
,
shape_inference
from
onnx.helper
import
get_attribute_value
,
make_attribute
from
onnx.shape_inference
import
infer_shapes
from
onnx.mapping
import
TENSOR_TYPE_TO_NP_TYPE
...
...
@@ -141,6 +141,10 @@ class ONNXGraph(Graph):
print
(
"shape inferencing ..."
)
self
.
graph
=
SymbolicShapeInference
.
infer_shapes
(
onnx_model
,
fixed_input_shape
=
self
.
fixed_input_shape
)
if
self
.
graph
is
None
:
print
(
'[WARNING] Shape inference by ONNX offical interface.'
)
onnx_model
=
shape_inference
.
infer_shapes
(
onnx_model
)
self
.
graph
=
onnx_model
.
graph
print
(
"shape inferenced."
)
self
.
build
()
self
.
collect_value_infos
()
...
...
x2paddle/decoder/onnx_shape_inference.py
浏览文件 @
92bd03a5
...
...
@@ -1588,7 +1588,7 @@ class SymbolicShapeInference:
assert
version
.
parse
(
onnx
.
__version__
)
>=
version
.
parse
(
"1.5.0"
)
onnx_opset
=
get_opset
(
in_mp
)
if
not
onnx_opset
or
onnx_opset
<
7
:
print
(
'
O
nly support models of onnx opset 7 and above.'
)
print
(
'
[WARNING] Symbolic shape inference o
nly support models of onnx opset 7 and above.'
)
return
symbolic_shape_inference
=
SymbolicShapeInference
(
int_max
,
auto_merge
,
guess_output_rank
,
verbose
)
...
...
@@ -1605,7 +1605,7 @@ class SymbolicShapeInference:
symbolic_shape_inference
.
out_mp_
=
shape_inference
.
infer_shapes
(
symbolic_shape_inference
.
out_mp_
)
except
:
print
(
'
Stopping at i
ncomplete symbolic shape inference'
)
print
(
'
[WARNING] I
ncomplete symbolic shape inference'
)
symbolic_shape_inference
.
out_mp_
=
shape_inference
.
infer_shapes
(
symbolic_shape_inference
.
out_mp_
)
return
symbolic_shape_inference
.
out_mp_
.
graph
x2paddle/op_mapper/dygraph/pytorch2paddle/aten.py
浏览文件 @
92bd03a5
# -*- coding:UTF-8 -*-
# Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"
...
...
x2paddle/op_mapper/dygraph/pytorch2paddle/prim.py
浏览文件 @
92bd03a5
# -*- coding:UTF-8 -*-
# Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"
...
...
x2paddle/op_mapper/dygraph/pytorch2paddle/prim2code.py
浏览文件 @
92bd03a5
# -*- coding:UTF-8 -*-
# Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"
...
...
x2paddle/op_mapper/dygraph/pytorch2paddle/pytorch_op_mapper.py
浏览文件 @
92bd03a5
# -*- coding:UTF-8 -*-
# Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"
...
...
x2paddle/op_mapper/dygraph/tf2paddle/tf_op_mapper.py
浏览文件 @
92bd03a5
...
...
@@ -561,7 +561,7 @@ class TFOpMapper(OpMapper):
self
.
paddle_graph
.
add_layer
(
kernel
=
"paddle.nn.functional.pad"
,
inputs
=
{
"
input
"
:
input
.
name
},
inputs
=
{
"
x
"
:
input
.
name
},
outputs
=
[
node
.
name
],
pad
=
paddings
)
...
...
x2paddle/op_mapper/static/tf2paddle/tf_op_mapper.py
浏览文件 @
92bd03a5
...
...
@@ -546,7 +546,7 @@ class TFOpMapper(OpMapper):
self
.
paddle_graph
.
add_layer
(
kernel
=
"fluid.layers.pad"
,
inputs
=
{
"
input
"
:
input
.
name
},
inputs
=
{
"
x
"
:
input
.
name
},
outputs
=
[
node
.
name
],
paddings
=
paddings
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录