Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
未来在这儿
X2Paddle
提交
07a87999
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,发现更多精彩内容 >>
提交
07a87999
编写于
3月 23, 2022
作者:
W
wjj19950828
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update logging info
上级
a834dd82
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
25 addition
and
11 deletion
+25
-11
README.md
README.md
+2
-2
x2paddle/convert.py
x2paddle/convert.py
+23
-9
未找到文件。
README.md
浏览文件 @
07a87999
...
...
@@ -50,11 +50,11 @@ X2Paddle是飞桨生态下的模型转换工具,致力于帮助其它深度学
### 环境依赖
-
python >= 3.5
-
paddlepaddle >= 2.
0.0
-
paddlepaddle >= 2.
2.2
-
tensorflow == 1.14 (如需转换TensorFlow模型)
-
onnx >= 1.6.0 (如需转换ONNX模型)
-
torch >= 1.5.0 (如需转换PyTorch模型)
-
paddlelite
== 2.9.0 (如需一键转换成Paddle-Lite支持格式
)
-
paddlelite
>= 2.9.0 (如需一键转换成Paddle-Lite支持格式,推荐最新版本
)
### pip安装(推荐)
...
...
x2paddle/convert.py
浏览文件 @
07a87999
...
...
@@ -139,28 +139,33 @@ def tf2paddle(model_path,
version
=
tf
.
__version__
if
version
>=
'2.0.0'
or
version
<
'1.0.0'
:
logging
.
info
(
"[ERROR] 1.0.0<=
tensorf
low<2.0.0 is required, and v1.14.0 is recommended"
"[ERROR] 1.0.0<=
TensorF
low<2.0.0 is required, and v1.14.0 is recommended"
)
return
except
:
logging
.
info
(
"[ERROR] Tensor
flow is not installed, use
\"
pip install tensorf
low
\"
."
"[ERROR] Tensor
Flow is not installed, use
\"
pip install TensorF
low
\"
."
)
return
from
x2paddle.decoder.tf_decoder
import
TFDecoder
from
x2paddle.op_mapper.tf2paddle.tf_op_mapper
import
TFOpMapper
logging
.
info
(
"Now translating model from
tensorflow to p
addle."
)
logging
.
info
(
"Now translating model from
TensorFlow to P
addle."
)
model
=
TFDecoder
(
model_path
,
define_input_shape
=
define_input_shape
)
mapper
=
TFOpMapper
(
model
)
mapper
.
paddle_graph
.
build
()
logging
.
info
(
"Model optimizing ..."
)
from
x2paddle.optimizer.optimizer
import
GraphOptimizer
graph_opt
=
GraphOptimizer
(
source_frame
=
"tf"
)
graph_opt
.
optimize
(
mapper
.
paddle_graph
)
logging
.
info
(
"Model optimized!"
)
mapper
.
paddle_graph
.
gen_model
(
save_dir
)
logging
.
info
(
"Successfully exported Paddle static graph model!"
)
if
convert_to_lite
:
logging
.
info
(
"Now translating model from Paddle to Paddle lite ..."
)
convert2lite
(
save_dir
,
lite_valid_places
,
lite_model_type
)
logging
.
info
(
"Successfully exported Paddle Lite support model!"
)
def
caffe2paddle
(
proto_file
,
...
...
@@ -187,10 +192,13 @@ def caffe2paddle(proto_file,
from
x2paddle.optimizer.optimizer
import
GraphOptimizer
graph_opt
=
GraphOptimizer
(
source_frame
=
"caffe"
)
graph_opt
.
optimize
(
mapper
.
paddle_graph
)
logging
.
info
(
"Model optimized
.
"
)
logging
.
info
(
"Model optimized
!
"
)
mapper
.
paddle_graph
.
gen_model
(
save_dir
)
logging
.
info
(
"Successfully exported Paddle static graph model!"
)
if
convert_to_lite
:
logging
.
info
(
"Now translating model from Paddle to Paddle lite ..."
)
convert2lite
(
save_dir
,
lite_valid_places
,
lite_model_type
)
logging
.
info
(
"Successfully exported Paddle Lite support model!"
)
def
onnx2paddle
(
model_path
,
...
...
@@ -219,8 +227,11 @@ def onnx2paddle(model_path,
mapper
=
ONNXOpMapper
(
model
)
mapper
.
paddle_graph
.
build
()
mapper
.
paddle_graph
.
gen_model
(
save_dir
)
logging
.
info
(
"Successfully exported Paddle static graph model!"
)
if
convert_to_lite
:
logging
.
info
(
"Now translating model from Paddle to Paddle lite ..."
)
convert2lite
(
save_dir
,
lite_valid_places
,
lite_model_type
)
logging
.
info
(
"Successfully exported Paddle Lite support model!"
)
def
pytorch2paddle
(
module
,
...
...
@@ -242,17 +253,17 @@ def pytorch2paddle(module,
version_sum
=
int
(
v0
)
*
100
+
int
(
v1
)
*
10
+
int
(
v2
)
if
version_sum
<
150
:
logging
.
info
(
"[ERROR]
pyt
orch>=1.5.0 is required, 1.6.0 is the most recommended"
"[ERROR]
PyT
orch>=1.5.0 is required, 1.6.0 is the most recommended"
)
return
if
version_sum
>
160
:
logging
.
info
(
"[WARNING]
pyt
orch==1.6.0 is recommended"
)
logging
.
info
(
"[WARNING]
PyT
orch==1.6.0 is recommended"
)
except
:
logging
.
info
(
"[ERROR] Py
t
orch is not installed, use
\"
pip install torch==1.6.0 torchvision
\"
."
"[ERROR] Py
T
orch is not installed, use
\"
pip install torch==1.6.0 torchvision
\"
."
)
return
logging
.
info
(
"Now translating model from
pytorch to p
addle."
)
logging
.
info
(
"Now translating model from
PyTorch to P
addle."
)
from
x2paddle.decoder.pytorch_decoder
import
ScriptDecoder
,
TraceDecoder
from
x2paddle.op_mapper.pytorch2paddle.pytorch_op_mapper
import
PyTorchOpMapper
...
...
@@ -267,11 +278,14 @@ def pytorch2paddle(module,
from
x2paddle.optimizer.optimizer
import
GraphOptimizer
graph_opt
=
GraphOptimizer
(
source_frame
=
"pytorch"
,
jit_type
=
jit_type
)
graph_opt
.
optimize
(
mapper
.
paddle_graph
)
logging
.
info
(
"Model optimized
.
"
)
logging
.
info
(
"Model optimized
!
"
)
mapper
.
paddle_graph
.
gen_model
(
save_dir
,
jit_type
=
jit_type
,
enable_code_optim
=
enable_code_optim
)
logging
.
info
(
"Successfully exported Paddle static graph model!"
)
if
convert_to_lite
:
logging
.
info
(
"Now translating model from Paddle to Paddle lite ..."
)
convert2lite
(
save_dir
,
lite_valid_places
,
lite_model_type
)
logging
.
info
(
"Successfully exported Paddle Lite support model!"
)
def
main
():
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录