Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
X2Paddle
提交
0edba41b
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看板
提交
0edba41b
编写于
3月 29, 2022
作者:
W
wjj19950828
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
deal with comments
上级
f8666204
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
52 addition
and
24 deletion
+52
-24
README.md
README.md
+1
-1
x2paddle/convert.py
x2paddle/convert.py
+48
-17
x2paddle/utils.py
x2paddle/utils.py
+3
-6
未找到文件。
README.md
浏览文件 @
0edba41b
...
...
@@ -121,7 +121,7 @@ x2paddle --framework=caffe --prototxt=deploy.prototxt --weight=deploy.caffemodel
| --to_lite | **[可选]** 是否使用opt工具转成Paddle-Lite支持格式,默认为False |
| --lite_valid_places | **[可选]** 指定转换类型,可以同时指定多个backend(以逗号分隔),opt将会自动选择最佳方式,默认为arm |
| --lite_model_type | **[可选]** 指定模型转化类型,目前支持两种类型:protobuf和naive_buffer,默认为naive_buffer |
| --disable_feedback | **[可选]** 是否关闭
用户信息反馈,包括转换框架信息、是否转换成功以及用户ip等,默认为False
|
| --disable_feedback | **[可选]** 是否关闭
X2Paddle使用反馈;X2Paddle默认会统计用户在进行模型转换时的成功率,以及转换框架来源等信息,以便于帮忙X2Paddle根据用户需求进行迭代,不会上传用户的模型文件。如若不想参与反馈,可指定此参数为False即可
|
#### X2Paddle API
目前X2Paddle提供API方式转换模型,可参考[X2PaddleAPI](docs/inference_model_convertor/x2paddle_api.md)
...
...
x2paddle/convert.py
浏览文件 @
0edba41b
...
...
@@ -18,6 +18,7 @@ from x2paddle.utils import ConverterCheck
import
argparse
import
sys
import
logging
import
time
def
arg_parser
():
...
...
@@ -98,7 +99,7 @@ def arg_parser():
"--disable_feedback"
,
"-df"
,
default
=
False
,
help
=
"Tu
rn off user info feedback
"
)
help
=
"Tu
ne off feedback of model conversion.
"
)
parser
.
add_argument
(
"--to_lite"
,
"-tl"
,
default
=
False
,
help
=
"convert to Paddle-Lite format"
)
parser
.
add_argument
(
...
...
@@ -138,8 +139,12 @@ def tf2paddle(model_path,
lite_valid_places
=
"arm"
,
lite_model_type
=
"naive_buffer"
,
disable_feedback
=
False
):
# for convert_id
time_info
=
int
(
time
.
time
())
if
not
disable_feedback
:
ConverterCheck
(
task
=
"TensorFlow"
,
convert_state
=
"Start"
).
start
()
ConverterCheck
(
task
=
"TensorFlow"
,
time_info
=
time_info
,
convert_state
=
"Start"
).
start
()
# check tensorflow installation and version
try
:
import
os
...
...
@@ -172,15 +177,21 @@ def tf2paddle(model_path,
mapper
.
paddle_graph
.
gen_model
(
save_dir
)
logging
.
info
(
"Successfully exported Paddle static graph model!"
)
if
not
disable_feedback
:
ConverterCheck
(
task
=
"TensorFlow"
,
convert_state
=
"Success"
).
start
()
ConverterCheck
(
task
=
"TensorFlow"
,
time_info
=
time_info
,
convert_state
=
"Success"
).
start
()
if
convert_to_lite
:
logging
.
info
(
"Now translating model from Paddle to Paddle Lite ..."
)
if
not
disable_feedback
:
ConverterCheck
(
task
=
"TensorFlow"
,
lite_state
=
"Start"
).
start
()
ConverterCheck
(
task
=
"TensorFlow"
,
time_info
=
time_info
,
lite_state
=
"Start"
).
start
()
convert2lite
(
save_dir
,
lite_valid_places
,
lite_model_type
)
logging
.
info
(
"Successfully exported Paddle Lite support model!"
)
if
not
disable_feedback
:
ConverterCheck
(
task
=
"TensorFlow"
,
lite_state
=
"Success"
).
start
()
ConverterCheck
(
task
=
"TensorFlow"
,
time_info
=
time_info
,
lite_state
=
"Success"
).
start
()
def
caffe2paddle
(
proto_file
,
...
...
@@ -191,8 +202,11 @@ def caffe2paddle(proto_file,
lite_valid_places
=
"arm"
,
lite_model_type
=
"naive_buffer"
,
disable_feedback
=
False
):
# for convert_id
time_info
=
int
(
time
.
time
())
if
not
disable_feedback
:
ConverterCheck
(
task
=
"Caffe"
,
convert_state
=
"Start"
).
start
()
ConverterCheck
(
task
=
"Caffe"
,
time_info
=
time_info
,
convert_state
=
"Start"
).
start
()
from
x2paddle.decoder.caffe_decoder
import
CaffeDecoder
from
x2paddle.op_mapper.caffe2paddle.caffe_op_mapper
import
CaffeOpMapper
import
google.protobuf
as
gpb
...
...
@@ -214,15 +228,18 @@ def caffe2paddle(proto_file,
mapper
.
paddle_graph
.
gen_model
(
save_dir
)
logging
.
info
(
"Successfully exported Paddle static graph model!"
)
if
not
disable_feedback
:
ConverterCheck
(
task
=
"Caffe"
,
convert_state
=
"Success"
).
start
()
ConverterCheck
(
task
=
"Caffe"
,
time_info
=
time_info
,
convert_state
=
"Success"
).
start
()
if
convert_to_lite
:
logging
.
info
(
"Now translating model from Paddle to Paddle Lite ..."
)
if
not
disable_feedback
:
ConverterCheck
(
task
=
"Caffe"
,
lite_state
=
"Start"
).
start
()
ConverterCheck
(
task
=
"Caffe"
,
time_info
=
time_info
,
lite_state
=
"Start"
).
start
()
convert2lite
(
save_dir
,
lite_valid_places
,
lite_model_type
)
logging
.
info
(
"Successfully exported Paddle Lite support model!"
)
if
not
disable_feedback
:
ConverterCheck
(
task
=
"Caffe"
,
lite_state
=
"Success"
).
start
()
ConverterCheck
(
task
=
"Caffe"
,
time_info
=
time_info
,
lite_state
=
"Success"
).
start
()
def
onnx2paddle
(
model_path
,
...
...
@@ -231,8 +248,11 @@ def onnx2paddle(model_path,
lite_valid_places
=
"arm"
,
lite_model_type
=
"naive_buffer"
,
disable_feedback
=
False
):
# for convert_id
time_info
=
int
(
time
.
time
())
if
not
disable_feedback
:
ConverterCheck
(
task
=
"ONNX"
,
convert_state
=
"Start"
).
start
()
ConverterCheck
(
task
=
"ONNX"
,
time_info
=
time_info
,
convert_state
=
"Start"
).
start
()
# check onnx installation and version
try
:
import
onnx
...
...
@@ -261,15 +281,18 @@ def onnx2paddle(model_path,
mapper
.
paddle_graph
.
gen_model
(
save_dir
)
logging
.
info
(
"Successfully exported Paddle static graph model!"
)
if
not
disable_feedback
:
ConverterCheck
(
task
=
"ONNX"
,
convert_state
=
"Success"
).
start
()
ConverterCheck
(
task
=
"ONNX"
,
time_info
=
time_info
,
convert_state
=
"Success"
).
start
()
if
convert_to_lite
:
logging
.
info
(
"Now translating model from Paddle to Paddle Lite ..."
)
if
not
disable_feedback
:
ConverterCheck
(
task
=
"ONNX"
,
lite_state
=
"Start"
).
start
()
ConverterCheck
(
task
=
"ONNX"
,
time_info
=
time_info
,
lite_state
=
"Start"
).
start
()
convert2lite
(
save_dir
,
lite_valid_places
,
lite_model_type
)
logging
.
info
(
"Successfully exported Paddle Lite support model!"
)
if
not
disable_feedback
:
ConverterCheck
(
task
=
"ONNX"
,
lite_state
=
"Success"
).
start
()
ConverterCheck
(
task
=
"ONNX"
,
time_info
=
time_info
,
lite_state
=
"Success"
).
start
()
def
pytorch2paddle
(
module
,
...
...
@@ -281,8 +304,11 @@ def pytorch2paddle(module,
lite_valid_places
=
"arm"
,
lite_model_type
=
"naive_buffer"
,
disable_feedback
=
False
):
# for convert_id
time_info
=
int
(
time
.
time
())
if
not
disable_feedback
:
onverterCheck
(
task
=
"PyTorch"
,
convert_state
=
"Start"
).
start
()
ConverterCheck
(
task
=
"PyTorch"
,
time_info
=
time_info
,
convert_state
=
"Start"
).
start
()
# check pytorch installation and version
try
:
import
torch
...
...
@@ -324,15 +350,20 @@ def pytorch2paddle(module,
save_dir
,
jit_type
=
jit_type
,
enable_code_optim
=
enable_code_optim
)
logging
.
info
(
"Successfully exported Paddle static graph model!"
)
if
not
disable_feedback
:
ConverterCheck
(
task
=
"PyTorch"
,
convert_state
=
"Success"
).
start
()
ConverterCheck
(
task
=
"PyTorch"
,
time_info
=
time_info
,
convert_state
=
"Success"
).
start
()
if
convert_to_lite
:
logging
.
info
(
"Now translating model from Paddle to Paddle Lite ..."
)
if
not
disable_feedback
:
ConverterCheck
(
task
=
"PyTorch"
,
lite_state
=
"Start"
).
start
()
ConverterCheck
(
task
=
"PyTorch"
,
time_info
=
time_info
,
lite_state
=
"Start"
).
start
()
convert2lite
(
save_dir
,
lite_valid_places
,
lite_model_type
)
logging
.
info
(
"Successfully exported Paddle Lite support model!"
)
if
not
disable_feedback
:
ConverterCheck
(
task
=
"PyTorch"
,
lite_state
=
"Success"
).
start
()
ConverterCheck
(
task
=
"PyTorch"
,
time_info
=
time_info
,
lite_state
=
"Success"
).
start
()
def
main
():
...
...
x2paddle/utils.py
浏览文件 @
0edba41b
...
...
@@ -18,7 +18,6 @@ import x2paddle
import
hashlib
import
requests
import
threading
import
time
import
uuid
stats_api
=
"http://paddlepaddle.org.cn/paddlehub/stat"
...
...
@@ -53,6 +52,7 @@ class ConverterCheck(threading.Thread):
def
__init__
(
self
,
task
=
"onnx"
,
time_info
=
time_info
,
convert_state
=
None
,
lite_state
=
None
,
extra_info
=
None
):
...
...
@@ -62,9 +62,7 @@ class ConverterCheck(threading.Thread):
self
.
_convert_state
=
convert_state
self
.
_lite_state
=
lite_state
self
.
_extra_info
=
extra_info
self
.
_convert_id
=
_md5
(
str
(
uuid
.
uuid1
())[
-
12
:])
self
.
_hash_flag
=
_md5
(
str
(
uuid
.
uuid1
())[
-
12
:])
+
"-"
+
str
(
int
(
time
.
time
()))
self
.
_convert_id
=
_md5
(
str
(
uuid
.
uuid1
())[
-
12
:])
+
"-"
+
str
(
time_info
)
def
run
(
self
):
params
=
{
...
...
@@ -73,7 +71,6 @@ class ConverterCheck(threading.Thread):
'paddle_version'
:
paddle
.
__version__
,
'convert_state'
:
self
.
_convert_state
,
'convert_id'
:
self
.
_convert_id
,
'cache_info'
:
self
.
_hash_flag
,
'from'
:
'x2paddle'
}
if
self
.
_lite_state
is
not
None
:
...
...
@@ -82,7 +79,7 @@ class ConverterCheck(threading.Thread):
params
.
update
(
self
.
_extra_info
)
try
:
requests
.
get
(
stats_api
,
params
)
requests
.
get
(
stats_api
,
params
,
timeout
=
2
)
except
Exception
:
pass
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录