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的架构设计着重考虑了对多深度学习框架的的支持以及
## 环境依赖
python >= 3.5
paddlepaddle 2.0.0-rc1 或者 develop
>
python >= 3.5
> paddlepaddle 2.0.0+
**按需安装以下依赖**
tensorflow : tensorflow == 1.14.0
caffe : 无
onnx : onnx >= 1.6.0
pytorch:torch >=1.5.0 (script方式暂不支持1.7.0)
>
tensorflow : tensorflow == 1.14.0
>
caffe : 无
> onnx : onnx >= 1.6.0
>
pytorch:torch >=1.5.0 (script方式暂不支持1.7.0)
## 安装
### 方式一:源码安装(推荐)
...
...
@@ -90,6 +90,7 @@ X2Paddle提供了工具解决如下问题,详见[tools/README.md](tools/README
3.
[
PyTorch模型导出为ONNX模型
](
./docs/user_guides/pytorch2onnx.md
)
4.
[
X2Paddle添加内置的Caffe自定义层
](
./docs/user_guides/add_caffe_custom_layer.md
)
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
)
...
...
x2paddle/convert.py
浏览文件 @
a7d14023
...
...
@@ -41,16 +41,15 @@ def arg_parser():
parser
.
add_argument
(
"--save_dir"
,
"-s"
,
required
=
True
,
type
=
_text_type
,
default
=
None
,
help
=
"path to save translated model"
)
parser
.
add_argument
(
"--framework"
,
"-f"
,
type
=
_text_type
,
default
=
None
,
help
=
"define which deeplearning framework(tensorflow/caffe/onnx/paddle2onnx)"
)
choices
=
[
'tensorflow'
,
'caffe'
,
'onnx'
],
help
=
"define which deeplearning framework(tensorflow/caffe/onnx)"
)
parser
.
add_argument
(
"--caffe_proto"
,
"-c"
,
...
...
@@ -73,11 +72,10 @@ def arg_parser():
parser
.
add_argument
(
"--paddle_type"
,
"-pt"
,
type
=
_text_type
,
choices
=
[
'dygraph'
,
'static'
]
,
default
=
"dygraph"
,
help
=
"define the paddle model type after converting(dygraph/static)"
)
help
=
"define the paddle model type after converting(dygraph/static)"
)
return
parser
...
...
@@ -101,14 +99,13 @@ def tf2paddle(model_path,
"[ERROR] Tensorflow is not installed, use
\"
pip install tensorflow
\"
."
)
return
from
x2paddle.decoder.tf_decoder
import
TFDecoder
if
paddle_type
==
"dygraph"
:
from
x2paddle.op_mapper.dygraph.tf2paddle.tf_op_mapper
import
TFOpMapper
else
:
from
x2paddle.op_mapper.static.tf2paddle.tf_op_mapper
import
TFOpMapper
print
(
"Now translating model from tensorflow to paddle."
)
model
=
TFDecoder
(
model_path
,
define_input_shape
=
define_input_shape
)
mapper
=
TFOpMapper
(
model
)
...
...
@@ -122,7 +119,6 @@ def tf2paddle(model_path,
graph_opt
=
GraphOptimizer
(
source_frame
=
"tf"
,
paddle_type
=
paddle_type
)
graph_opt
.
optimize
(
mapper
.
paddle_graph
)
mapper
.
paddle_graph
.
gen_model
(
save_dir
)
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):
)
return
print
(
"Now translating model from pytorch to paddle."
)
from
x2paddle.decoder.pytorch_decoder
import
ScriptDecoder
,
TraceDecoder
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):
mapper
.
paddle_graph
.
build
()
print
(
"Model optimizing ..."
)
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
)
print
(
"Model optimized."
)
mapper
.
paddle_graph
.
gen_model
(
save_dir
,
jit_type
=
jit_type
)
...
...
@@ -224,14 +221,10 @@ def main():
x2paddle
.
__version__
))
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
:
import
platform
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"
)
return
import
paddle
...
...
@@ -252,8 +245,8 @@ def main():
define_input_shape
=
False
if
args
.
define_input_shape
:
define_input_shape
=
True
tf2paddle
(
args
.
model
,
args
.
save_dir
,
define_input_shape
,
args
.
paddle_type
)
tf2paddle
(
args
.
model
,
args
.
save_dir
,
define_input_shape
,
args
.
paddle_type
)
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"
...
...
@@ -263,11 +256,12 @@ def main():
assert
args
.
model
is
not
None
,
"--model should be defined while translating onnx model"
onnx2paddle
(
args
.
model
,
args
.
save_dir
,
args
.
paddle_type
)
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
:
raise
Exception
(
"--framework only support tensorflow/caffe/onnx now"
)
raise
Exception
(
"--framework only support tensorflow/caffe/onnx now"
)
if
__name__
==
"__main__"
:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录