Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
X2Paddle
提交
a7d14023
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看板
未验证
提交
a7d14023
编写于
4月 23, 2021
作者:
S
SunAhong1993
提交者:
GitHub
4月 23, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix readme and converter.py (#551)
上级
54ca1dbb
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
25 addition
and
30 deletion
+25
-30
README.md
README.md
+7
-6
x2paddle/convert.py
x2paddle/convert.py
+18
-24
未找到文件。
README.md
浏览文件 @
a7d14023
...
@@ -21,14 +21,14 @@ X2Paddle的架构设计着重考虑了对多深度学习框架的的支持以及
...
@@ -21,14 +21,14 @@ X2Paddle的架构设计着重考虑了对多深度学习框架的的支持以及
## 环境依赖
## 环境依赖
python >= 3.5
>
python >= 3.5
paddlepaddle 2.0.0-rc1 或者 develop
> paddlepaddle 2.0.0+
**按需安装以下依赖**
**按需安装以下依赖**
tensorflow : tensorflow == 1.14.0
>
tensorflow : tensorflow == 1.14.0
caffe : 无
>
caffe : 无
onnx : onnx >= 1.6.0
> onnx : onnx >= 1.6.0
pytorch:torch >=1.5.0 (script方式暂不支持1.7.0)
>
pytorch:torch >=1.5.0 (script方式暂不支持1.7.0)
## 安装
## 安装
### 方式一:源码安装(推荐)
### 方式一:源码安装(推荐)
...
@@ -90,6 +90,7 @@ X2Paddle提供了工具解决如下问题,详见[tools/README.md](tools/README
...
@@ -90,6 +90,7 @@ X2Paddle提供了工具解决如下问题,详见[tools/README.md](tools/README
3.
[
PyTorch模型导出为ONNX模型
](
./docs/user_guides/pytorch2onnx.md
)
3.
[
PyTorch模型导出为ONNX模型
](
./docs/user_guides/pytorch2onnx.md
)
4.
[
X2Paddle添加内置的Caffe自定义层
](
./docs/user_guides/add_caffe_custom_layer.md
)
4.
[
X2Paddle添加内置的Caffe自定义层
](
./docs/user_guides/add_caffe_custom_layer.md
)
5.
[
转换后PaddlePaddle预测模型简介
](
./docs/user_guides/pd_folder_introduction.py
)
5.
[
转换后PaddlePaddle预测模型简介
](
./docs/user_guides/pd_folder_introduction.py
)
6.
[
Paddle到ONNX的转换
](
https://github.com/PaddlePaddle/Paddle2ONNX
)
## 支持列表文档
## 支持列表文档
1.
[
X2Paddle测试模型库
](
./docs/introduction/x2paddle_model_zoo.md
)
1.
[
X2Paddle测试模型库
](
./docs/introduction/x2paddle_model_zoo.md
)
...
...
x2paddle/convert.py
浏览文件 @
a7d14023
...
@@ -41,16 +41,15 @@ def arg_parser():
...
@@ -41,16 +41,15 @@ def arg_parser():
parser
.
add_argument
(
parser
.
add_argument
(
"--save_dir"
,
"--save_dir"
,
"-s"
,
"-s"
,
required
=
True
,
type
=
_text_type
,
type
=
_text_type
,
default
=
None
,
default
=
None
,
help
=
"path to save translated model"
)
help
=
"path to save translated model"
)
parser
.
add_argument
(
parser
.
add_argument
(
"--framework"
,
"--framework"
,
"-f"
,
"-f"
,
type
=
_text_type
,
choices
=
[
'tensorflow'
,
'caffe'
,
'onnx'
],
default
=
None
,
help
=
"define which deeplearning framework(tensorflow/caffe/onnx)"
)
help
=
"define which deeplearning framework(tensorflow/caffe/onnx/paddle2onnx)"
)
parser
.
add_argument
(
parser
.
add_argument
(
"--caffe_proto"
,
"--caffe_proto"
,
"-c"
,
"-c"
,
...
@@ -73,11 +72,10 @@ def arg_parser():
...
@@ -73,11 +72,10 @@ def arg_parser():
parser
.
add_argument
(
parser
.
add_argument
(
"--paddle_type"
,
"--paddle_type"
,
"-pt"
,
"-pt"
,
type
=
_text_type
,
choices
=
[
'dygraph'
,
'static'
]
,
default
=
"dygraph"
,
default
=
"dygraph"
,
help
=
"define the paddle model type after converting(dygraph/static)"
help
=
"define the paddle model type after converting(dygraph/static)"
)
)
return
parser
return
parser
...
@@ -101,14 +99,13 @@ def tf2paddle(model_path,
...
@@ -101,14 +99,13 @@ def tf2paddle(model_path,
"[ERROR] Tensorflow is not installed, use
\"
pip install tensorflow
\"
."
"[ERROR] Tensorflow is not installed, use
\"
pip install tensorflow
\"
."
)
)
return
return
from
x2paddle.decoder.tf_decoder
import
TFDecoder
from
x2paddle.decoder.tf_decoder
import
TFDecoder
if
paddle_type
==
"dygraph"
:
if
paddle_type
==
"dygraph"
:
from
x2paddle.op_mapper.dygraph.tf2paddle.tf_op_mapper
import
TFOpMapper
from
x2paddle.op_mapper.dygraph.tf2paddle.tf_op_mapper
import
TFOpMapper
else
:
else
:
from
x2paddle.op_mapper.static.tf2paddle.tf_op_mapper
import
TFOpMapper
from
x2paddle.op_mapper.static.tf2paddle.tf_op_mapper
import
TFOpMapper
print
(
"Now translating model from tensorflow to paddle."
)
print
(
"Now translating model from tensorflow to paddle."
)
model
=
TFDecoder
(
model_path
,
define_input_shape
=
define_input_shape
)
model
=
TFDecoder
(
model_path
,
define_input_shape
=
define_input_shape
)
mapper
=
TFOpMapper
(
model
)
mapper
=
TFOpMapper
(
model
)
...
@@ -122,7 +119,6 @@ def tf2paddle(model_path,
...
@@ -122,7 +119,6 @@ def tf2paddle(model_path,
graph_opt
=
GraphOptimizer
(
source_frame
=
"tf"
,
paddle_type
=
paddle_type
)
graph_opt
=
GraphOptimizer
(
source_frame
=
"tf"
,
paddle_type
=
paddle_type
)
graph_opt
.
optimize
(
mapper
.
paddle_graph
)
graph_opt
.
optimize
(
mapper
.
paddle_graph
)
mapper
.
paddle_graph
.
gen_model
(
save_dir
)
mapper
.
paddle_graph
.
gen_model
(
save_dir
)
def
caffe2paddle
(
proto
,
weight
,
save_dir
,
caffe_proto
,
paddle_type
):
def
caffe2paddle
(
proto
,
weight
,
save_dir
,
caffe_proto
,
paddle_type
):
...
@@ -190,7 +186,7 @@ def pytorch2paddle(module, save_dir, jit_type="trace", input_examples=None):
...
@@ -190,7 +186,7 @@ def pytorch2paddle(module, save_dir, jit_type="trace", input_examples=None):
)
)
return
return
print
(
"Now translating model from pytorch to paddle."
)
print
(
"Now translating model from pytorch to paddle."
)
from
x2paddle.decoder.pytorch_decoder
import
ScriptDecoder
,
TraceDecoder
from
x2paddle.decoder.pytorch_decoder
import
ScriptDecoder
,
TraceDecoder
from
x2paddle.op_mapper.dygraph.pytorch2paddle.pytorch_op_mapper
import
PyTorchOpMapper
from
x2paddle.op_mapper.dygraph.pytorch2paddle.pytorch_op_mapper
import
PyTorchOpMapper
...
@@ -202,7 +198,8 @@ def pytorch2paddle(module, save_dir, jit_type="trace", input_examples=None):
...
@@ -202,7 +198,8 @@ def pytorch2paddle(module, save_dir, jit_type="trace", input_examples=None):
mapper
.
paddle_graph
.
build
()
mapper
.
paddle_graph
.
build
()
print
(
"Model optimizing ..."
)
print
(
"Model optimizing ..."
)
from
x2paddle.optimizer.optimizer
import
GraphOptimizer
from
x2paddle.optimizer.optimizer
import
GraphOptimizer
graph_opt
=
GraphOptimizer
(
source_frame
=
"pytorch"
,
paddle_type
=
"dygraph"
,
jit_type
=
jit_type
)
graph_opt
=
GraphOptimizer
(
source_frame
=
"pytorch"
,
paddle_type
=
"dygraph"
,
jit_type
=
jit_type
)
graph_opt
.
optimize
(
mapper
.
paddle_graph
)
graph_opt
.
optimize
(
mapper
.
paddle_graph
)
print
(
"Model optimized."
)
print
(
"Model optimized."
)
mapper
.
paddle_graph
.
gen_model
(
save_dir
,
jit_type
=
jit_type
)
mapper
.
paddle_graph
.
gen_model
(
save_dir
,
jit_type
=
jit_type
)
...
@@ -224,14 +221,10 @@ def main():
...
@@ -224,14 +221,10 @@ def main():
x2paddle
.
__version__
))
x2paddle
.
__version__
))
return
return
assert
args
.
framework
is
not
None
,
"--framework is not defined(support tensorflow/caffe/onnx)"
assert
args
.
save_dir
is
not
None
,
"--save_dir is not defined"
assert
args
.
paddle_type
in
[
"dygraph"
,
"static"
],
"--paddle_type must be 'dygraph' or 'static'"
try
:
try
:
import
platform
import
platform
v0
,
v1
,
v2
=
platform
.
python_version
().
split
(
'.'
)
v0
,
v1
,
v2
=
platform
.
python_version
().
split
(
'.'
)
if
not
(
int
(
v0
)
>=
3
and
int
(
v1
)
>=
5
):
if
not
(
int
(
v0
)
>=
3
and
int
(
v1
)
>=
5
):
print
(
"[ERROR] python>=3.5 is required"
)
print
(
"[ERROR] python>=3.5 is required"
)
return
return
import
paddle
import
paddle
...
@@ -252,8 +245,8 @@ def main():
...
@@ -252,8 +245,8 @@ def main():
define_input_shape
=
False
define_input_shape
=
False
if
args
.
define_input_shape
:
if
args
.
define_input_shape
:
define_input_shape
=
True
define_input_shape
=
True
tf2paddle
(
args
.
model
,
args
.
save_dir
,
tf2paddle
(
args
.
model
,
args
.
save_dir
,
define_input_shape
,
define_input_shape
,
args
.
paddle_type
)
args
.
paddle_type
)
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"
...
@@ -263,11 +256,12 @@ def main():
...
@@ -263,11 +256,12 @@ def main():
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"
onnx2paddle
(
args
.
model
,
args
.
save_dir
,
args
.
paddle_type
)
onnx2paddle
(
args
.
model
,
args
.
save_dir
,
args
.
paddle_type
)
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"
)
else
:
else
:
raise
Exception
(
raise
Exception
(
"--framework only support tensorflow/caffe/onnx now"
)
"--framework only support tensorflow/caffe/onnx now"
)
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录