Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
X2Paddle
提交
b7baa928
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看板
提交
b7baa928
编写于
1月 20, 2021
作者:
S
SunAhong1993
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix the command
上级
3822ac80
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
23 addition
and
56 deletion
+23
-56
README.md
README.md
+0
-1
docs/introduction/op_list.md
docs/introduction/op_list.md
+9
-4
x2paddle/convert.py
x2paddle/convert.py
+7
-36
x2paddle/core/program.py
x2paddle/core/program.py
+7
-15
未找到文件。
README.md
浏览文件 @
b7baa928
...
@@ -63,7 +63,6 @@ x2paddle --framework=onnx --model=onnx_model.onnx --save_dir=pd_model --paddle_t
...
@@ -63,7 +63,6 @@ x2paddle --framework=onnx --model=onnx_model.onnx --save_dir=pd_model --paddle_t
|--model | 当framework为tensorflow/onnx时,该参数指定tensorflow的pb模型文件或onnx模型路径 |
|--model | 当framework为tensorflow/onnx时,该参数指定tensorflow的pb模型文件或onnx模型路径 |
|--caffe_proto |
**[可选]**
由caffe.proto编译成caffe_pb2.py文件的存放路径,当存在自定义Layer时使用,默认为None |
|--caffe_proto |
**[可选]**
由caffe.proto编译成caffe_pb2.py文件的存放路径,当存在自定义Layer时使用,默认为None |
|--define_input_shape |
**[可选]**
For TensorFlow, 当指定该参数时,强制用户输入每个Placeholder的shape,见
[
文档Q2
](
./docs/user_guides/FAQ.md
)
|
|--define_input_shape |
**[可选]**
For TensorFlow, 当指定该参数时,强制用户输入每个Placeholder的shape,见
[
文档Q2
](
./docs/user_guides/FAQ.md
)
|
|--params_merge |
**[可选]**
当指定该参数时,转换完成后,inference_model中的所有模型参数将合并保存为一个文件__params__ |
|--paddle_type |
**[可选]**
该参数指定转换为动态图代码(dygraph)或者静态图代码(static),默认为dygraph|
|--paddle_type |
**[可选]**
该参数指定转换为动态图代码(dygraph)或者静态图代码(static),默认为dygraph|
...
...
docs/introduction/op_list.md
浏览文件 @
b7baa928
# X2Paddle支持OP列表
# X2Paddle支持OP列表
> 目前X2Paddle支持
70+的TensorFlow OP,30+的Caffe Layer,
覆盖了大部分CV分类模型常用的操作。我们在如下列表中给出了目前X2Paddle支持的全部OP。
> 目前X2Paddle支持
80+的TensorFlow OP,30+的Caffe Layer,60+的ONNX OP,110+的PyTorch Aten,10+的PyTorch Prim
覆盖了大部分CV分类模型常用的操作。我们在如下列表中给出了目前X2Paddle支持的全部OP。
**注:**
目前,部分OP暂未支持,如您在转换过程中出现OP不支持的情况,可自行添加或反馈给我们。欢迎通过
[
ISSUE反馈
](
https://github.com/PaddlePaddle/X2Paddle/issues/new
)
的方式告知我们(模型名,代码实现或模型获取方式),我们会及时跟进:)
**注:**
目前,部分OP暂未支持,如您在转换过程中出现OP不支持的情况,可自行添加或反馈给我们。欢迎通过
[
ISSUE反馈
](
https://github.com/PaddlePaddle/X2Paddle/issues/new
)
的方式告知我们(模型名,代码实现或模型获取方式),我们会及时跟进:)
...
@@ -28,7 +28,7 @@
...
@@ -28,7 +28,7 @@
| 73 | Greater | 74 | FloorMod | 75 | LogicalAdd | 76 | Prod |
| 73 | Greater | 74 | FloorMod | 75 | LogicalAdd | 76 | Prod |
| 77 | Equal | 78 | Conv3D | 79 | Ceil | 80 | AddN |
| 77 | Equal | 78 | Conv3D | 79 | Ceil | 80 | AddN |
| 81 | DivNoNan | 82 | Where | 83 | MirrorPad | 84 | Size |
| 81 | DivNoNan | 82 | Where | 83 | MirrorPad | 84 | Size |
| 85 | TopKv2 |
|
| | | | |
| 85 | TopKv2 |
86 | SplitV
| | | | |
## Caffe
## Caffe
...
@@ -42,7 +42,7 @@
...
@@ -42,7 +42,7 @@
| 21 | Axpy | 22 | ROIPolling | 23 | Permute | 24 | DetectionOutput |
| 21 | Axpy | 22 | ROIPolling | 23 | Permute | 24 | DetectionOutput |
| 25 | Normalize | 26 | Select | 27 | ShuffleChannel | 28 | ConvolutionDepthwise |
| 25 | Normalize | 26 | Select | 27 | ShuffleChannel | 28 | ConvolutionDepthwise |
| 29 | ReLU | 30 | AbsVal | 31 | Sigmoid | 32 | TanH |
| 29 | ReLU | 30 | AbsVal | 31 | Sigmoid | 32 | TanH |
| 33 | ReLU6 | 34 | Upsample |
| 33 | ReLU6 | 34 | Upsample |
| | | |
## ONNX
## ONNX
...
@@ -61,7 +61,11 @@
...
@@ -61,7 +61,11 @@
| 41 | MatMul | 42 | Sum | 43 | Transpose | 44 | BatchNormalization |
| 41 | MatMul | 42 | Sum | 43 | Transpose | 44 | BatchNormalization |
| 45 | Squeeze | 46 | Equal | 47 | Identity | 48 | GlobalAveragePool |
| 45 | Squeeze | 46 | Equal | 47 | Identity | 48 | GlobalAveragePool |
| 49 | MaxPool | 50 | Conv | 51 | Gemm | 52 | NonZero |
| 49 | MaxPool | 50 | Conv | 51 | Gemm | 52 | NonZero |
| 53 | Abs | 54 | Floor | 52 | ArgMax |
| 53 | Abs | 54 | Floor | 56 | ArgMax | 57 | Sign |
| 58 | Reciprocal | 59 | Size | 60 | OneHot | 61 | ReduceProd |
| 62 | LogSoftmax | 63 | LSTM | | | | |
## PyTorch
## PyTorch
Aten:
Aten:
...
@@ -95,6 +99,7 @@ Aten:
...
@@ -95,6 +99,7 @@ Aten:
| 101 | aten::upsample
\_
bilinear2d | 102 | aten::values |103|aten::view|104|aten::warn|
| 101 | aten::upsample
\_
bilinear2d | 102 | aten::values |103|aten::view|104|aten::warn|
| 105 | aten::where | 106 | aten::zeros |107|aten::zeros
\_
like|108|aten::bmm|
| 105 | aten::where | 106 | aten::zeros |107|aten::zeros
\_
like|108|aten::bmm|
| 109 | aten::sub
\_
| 110 | aten:erf |111|aten::lstm|112|aten::gather|
| 109 | aten::sub
\_
| 110 | aten:erf |111|aten::lstm|112|aten::gather|
| 113 | aten::upsample
\_
nearest2d || |||||
Prim:
Prim:
| 序号 | OP | 序号 | OP | 序号 | OP | 序号 | OP |
| 序号 | OP | 序号 | OP | 序号 | OP | 序号 | OP |
...
...
x2paddle/convert.py
浏览文件 @
b7baa928
...
@@ -70,12 +70,6 @@ def arg_parser():
...
@@ -70,12 +70,6 @@ def arg_parser():
action
=
"store_true"
,
action
=
"store_true"
,
default
=
False
,
default
=
False
,
help
=
"define input shape for tf model"
)
help
=
"define input shape for tf model"
)
parser
.
add_argument
(
"--params_merge"
,
"-pm"
,
action
=
"store_true"
,
default
=
False
,
help
=
"define whether merge the params"
)
parser
.
add_argument
(
parser
.
add_argument
(
"--paddle_type"
,
"--paddle_type"
,
"-pt"
,
"-pt"
,
...
@@ -83,22 +77,14 @@ def arg_parser():
...
@@ -83,22 +77,14 @@ def arg_parser():
default
=
"dygraph"
,
default
=
"dygraph"
,
help
=
"define the paddle model type after converting(dygraph/static)"
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
return
parser
def
tf2paddle
(
model_path
,
def
tf2paddle
(
model_path
,
save_dir
,
save_dir
,
without_data_format_optimization
=
False
,
define_input_shape
=
False
,
define_input_shape
=
False
,
paddle_type
=
"dygraph"
,
paddle_type
=
"dygraph"
):
params_merge
=
False
):
# check tensorflow installation and version
# check tensorflow installation and version
try
:
try
:
import
os
import
os
...
@@ -139,8 +125,7 @@ def tf2paddle(model_path,
...
@@ -139,8 +125,7 @@ def tf2paddle(model_path,
def
caffe2paddle
(
proto
,
weight
,
save_dir
,
caffe_proto
,
def
caffe2paddle
(
proto
,
weight
,
save_dir
,
caffe_proto
,
paddle_type
):
paddle_type
,
params_merge
=
False
):
from
x2paddle.decoder.caffe_decoder
import
CaffeDecoder
from
x2paddle.decoder.caffe_decoder
import
CaffeDecoder
if
paddle_type
==
"dygraph"
:
if
paddle_type
==
"dygraph"
:
from
x2paddle.op_mapper.dygraph.caffe2paddle.caffe_op_mapper
import
CaffeOpMapper
from
x2paddle.op_mapper.dygraph.caffe2paddle.caffe_op_mapper
import
CaffeOpMapper
...
@@ -165,7 +150,7 @@ def caffe2paddle(proto, weight, save_dir, caffe_proto,
...
@@ -165,7 +150,7 @@ def caffe2paddle(proto, weight, save_dir, caffe_proto,
mapper
.
paddle_graph
.
gen_model
(
save_dir
)
mapper
.
paddle_graph
.
gen_model
(
save_dir
)
def
onnx2paddle
(
model_path
,
save_dir
,
paddle_type
,
params_merge
=
False
):
def
onnx2paddle
(
model_path
,
save_dir
,
paddle_type
):
# check onnx installation and version
# check onnx installation and version
try
:
try
:
import
onnx
import
onnx
...
@@ -259,33 +244,19 @@ def main():
...
@@ -259,33 +244,19 @@ def main():
if
args
.
framework
==
"tensorflow"
:
if
args
.
framework
==
"tensorflow"
:
assert
args
.
model
is
not
None
,
"--model should be defined while translating tensorflow model"
assert
args
.
model
is
not
None
,
"--model should be defined while translating tensorflow model"
assert
args
.
without_data_format_optimization
in
[
"True"
,
"False"
],
"--the param without_data_format_optimization should be defined True or False"
define_input_shape
=
False
define_input_shape
=
False
params_merge
=
False
without_data_format_optimization
=
True
if
args
.
without_data_format_optimization
==
"True"
else
False
if
args
.
define_input_shape
:
if
args
.
define_input_shape
:
define_input_shape
=
True
define_input_shape
=
True
if
args
.
params_merge
:
tf2paddle
(
args
.
model
,
args
.
save_dir
,
params_merge
=
True
define_input_shape
,
args
.
paddle_type
)
tf2paddle
(
args
.
model
,
args
.
save_dir
,
without_data_format_optimization
,
define_input_shape
,
args
.
paddle_type
,
params_merge
)
elif
args
.
framework
==
"caffe"
:
elif
args
.
framework
==
"caffe"
:
assert
args
.
prototxt
is
not
None
and
args
.
weight
is
not
None
,
"--prototxt and --weight should be defined while translating caffe model"
assert
args
.
prototxt
is
not
None
and
args
.
weight
is
not
None
,
"--prototxt and --weight should be defined while translating caffe model"
params_merge
=
False
if
args
.
params_merge
:
params_merge
=
True
caffe2paddle
(
args
.
prototxt
,
args
.
weight
,
args
.
save_dir
,
caffe2paddle
(
args
.
prototxt
,
args
.
weight
,
args
.
save_dir
,
args
.
caffe_proto
,
args
.
paddle_type
,
params_merge
)
args
.
caffe_proto
,
args
.
paddle_type
)
elif
args
.
framework
==
"onnx"
:
elif
args
.
framework
==
"onnx"
:
assert
args
.
model
is
not
None
,
"--model should be defined while translating onnx model"
assert
args
.
model
is
not
None
,
"--model should be defined while translating onnx model"
params_merge
=
False
onnx2paddle
(
args
.
model
,
args
.
save_dir
,
args
.
paddle_type
)
if
args
.
params_merge
:
params_merge
=
True
onnx2paddle
(
args
.
model
,
args
.
save_dir
,
args
.
paddle_type
,
params_merge
)
elif
args
.
framework
==
"paddle2onnx"
:
elif
args
.
framework
==
"paddle2onnx"
:
print
(
"Paddle to ONNX tool has been migrated to the new github: https://github.com/PaddlePaddle/paddle2onnx"
)
print
(
"Paddle to ONNX tool has been migrated to the new github: https://github.com/PaddlePaddle/paddle2onnx"
)
...
...
x2paddle/core/program.py
浏览文件 @
b7baa928
...
@@ -15,7 +15,6 @@
...
@@ -15,7 +15,6 @@
from
__future__
import
print_function
from
__future__
import
print_function
from
__future__
import
division
from
__future__
import
division
import
paddle.fluid
as
fluid
import
paddle
import
paddle
from
paddle.fluid.proto
import
framework_pb2
from
paddle.fluid.proto
import
framework_pb2
import
collections
import
collections
...
@@ -258,22 +257,17 @@ class PaddleGraph(object):
...
@@ -258,22 +257,17 @@ class PaddleGraph(object):
with
paddle
.
static
.
scope_guard
(
scope
):
with
paddle
.
static
.
scope_guard
(
scope
):
with
paddle
.
static
.
program_guard
(
main_program
,
startup_program
):
with
paddle
.
static
.
program_guard
(
main_program
,
startup_program
):
inputs
,
outputs
=
x2paddle_model
.
x2paddle_net
()
inputs
,
outputs
=
x2paddle_model
.
x2paddle_net
()
exe
=
fluid
.
Executor
(
fluid
.
CPUPlace
())
exe
=
paddle
.
static
.
Executor
(
paddle
.
CPUPlace
())
exe
.
run
(
startup_program
)
exe
.
run
(
startup_program
)
param_dir
=
osp
.
join
(
code_dir
,
'weights'
)
param_dir
=
osp
.
join
(
code_dir
,
'weights'
)
for
k
,
v
in
self
.
parameters
.
items
():
for
k
,
v
in
self
.
parameters
.
items
():
if
scope
.
find_var
(
k
):
if
scope
.
find_var
(
k
):
self
.
dump_parameter
(
k
,
v
,
param_dir
)
self
.
dump_parameter
(
k
,
v
,
param_dir
)
def
if_exist
(
var
):
paddle
.
static
.
load
(
main_program
,
param_dir
,
exe
)
b
=
osp
.
exists
(
paddle
.
static
.
save_inference_model
(
osp
.
join
(
osp
.
join
(
param_dir
,
var
.
name
)))
path_prefix
=
osp
.
join
(
infer_dir
,
"model"
),
return
b
feed_vars
=
[
i
for
i
in
inputs
],
fluid
.
io
.
load_vars
(
fetch_vars
=
outputs
,
exe
,
param_dir
,
main_program
,
predicate
=
if_exist
)
fluid
.
io
.
save_inference_model
(
dirname
=
infer_dir
,
feeded_var_names
=
[
i
.
name
for
i
in
inputs
],
target_vars
=
outputs
,
executor
=
exe
)
executor
=
exe
)
def
gen_dygraph_model
(
self
,
save_dir
,
jit_type
=
None
):
def
gen_dygraph_model
(
self
,
save_dir
,
jit_type
=
None
):
...
@@ -562,8 +556,7 @@ class PaddleGraph(object):
...
@@ -562,8 +556,7 @@ class PaddleGraph(object):
remove_default_attrs
(
layer
.
kernel
,
layer
.
attrs
)
remove_default_attrs
(
layer
.
kernel
,
layer
.
attrs
)
if
(
"paddle.nn"
in
layer
.
kernel
and
"functional"
not
in
layer
.
kernel
if
(
"paddle.nn"
in
layer
.
kernel
and
"functional"
not
in
layer
.
kernel
)
or
layer
.
kernel
==
"paddle.to_tensor"
or
\
)
or
layer
.
kernel
==
"paddle.to_tensor"
or
\
layer
.
kernel
.
startswith
(
"custom_layer"
)
or
\
layer
.
kernel
.
startswith
(
"custom_layer"
):
layer
.
kernel
.
startswith
(
"paddle.fluid.dygraph"
):
line
=
"{}"
.
format
(
line
=
"{}"
.
format
(
layer
.
outputs
[
0
]
layer
.
outputs
[
0
]
)
if
layer
.
kernel
==
"paddle.to_tensor"
and
not
layer
.
attrs
[
)
if
layer
.
kernel
==
"paddle.to_tensor"
and
not
layer
.
attrs
[
...
@@ -660,7 +653,6 @@ class PaddleGraph(object):
...
@@ -660,7 +653,6 @@ class PaddleGraph(object):
paddle
.
save
(
self
.
parameters
,
save_path
)
paddle
.
save
(
self
.
parameters
,
save_path
)
def
dygraph2static
(
self
,
save_dir
,
input_shapes
=
[],
input_types
=
[]):
def
dygraph2static
(
self
,
save_dir
,
input_shapes
=
[],
input_types
=
[]):
from
paddle.fluid.dygraph.jit
import
declarative
sepc_list
=
list
()
sepc_list
=
list
()
for
i
,
name
in
enumerate
(
self
.
inputs
):
for
i
,
name
in
enumerate
(
self
.
inputs
):
sepc_list
.
append
(
sepc_list
.
append
(
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录