Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
X2Paddle
提交
e9354ecc
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看板
提交
e9354ecc
编写于
3月 28, 2022
作者:
W
wjj19950828
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add convert states statistics
上级
f44f5071
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
60 addition
and
0 deletion
+60
-0
x2paddle/convert.py
x2paddle/convert.py
+17
-0
x2paddle/utils.py
x2paddle/utils.py
+43
-0
未找到文件。
x2paddle/convert.py
浏览文件 @
e9354ecc
...
...
@@ -14,6 +14,7 @@
from
six
import
text_type
as
_text_type
from
x2paddle
import
program
from
utils
import
ConverterCheck
import
argparse
import
sys
import
logging
...
...
@@ -131,6 +132,7 @@ def tf2paddle(model_path,
convert_to_lite
=
False
,
lite_valid_places
=
"arm"
,
lite_model_type
=
"naive_buffer"
):
ConverterCheck
(
task
=
"TensorFlow"
,
convert_state
=
"Start"
).
start
()
# check tensorflow installation and version
try
:
import
os
...
...
@@ -159,8 +161,11 @@ def tf2paddle(model_path,
graph_opt
=
GraphOptimizer
(
source_frame
=
"tf"
)
graph_opt
.
optimize
(
mapper
.
paddle_graph
)
mapper
.
paddle_graph
.
gen_model
(
save_dir
)
ConverterCheck
(
task
=
"TensorFlow"
,
convert_state
=
"Success"
).
start
()
if
convert_to_lite
:
ConverterCheck
(
task
=
"TensorFlow"
,
lite_state
=
"Start"
).
start
()
convert2lite
(
save_dir
,
lite_valid_places
,
lite_model_type
)
ConverterCheck
(
task
=
"TensorFlow"
,
lite_state
=
"Success"
).
start
()
def
caffe2paddle
(
proto_file
,
...
...
@@ -170,6 +175,7 @@ def caffe2paddle(proto_file,
convert_to_lite
=
False
,
lite_valid_places
=
"arm"
,
lite_model_type
=
"naive_buffer"
):
ConverterCheck
(
task
=
"Caffe"
,
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
...
...
@@ -189,8 +195,11 @@ def caffe2paddle(proto_file,
graph_opt
.
optimize
(
mapper
.
paddle_graph
)
logging
.
info
(
"Model optimized."
)
mapper
.
paddle_graph
.
gen_model
(
save_dir
)
ConverterCheck
(
task
=
"Caffe"
,
convert_state
=
"Success"
).
start
()
if
convert_to_lite
:
ConverterCheck
(
task
=
"Caffe"
,
lite_state
=
"Start"
).
start
()
convert2lite
(
save_dir
,
lite_valid_places
,
lite_model_type
)
ConverterCheck
(
task
=
"Caffe"
,
lite_state
=
"Success"
).
start
()
def
onnx2paddle
(
model_path
,
...
...
@@ -198,6 +207,7 @@ def onnx2paddle(model_path,
convert_to_lite
=
False
,
lite_valid_places
=
"arm"
,
lite_model_type
=
"naive_buffer"
):
ConverterCheck
(
task
=
"ONNX"
,
convert_state
=
"Start"
).
start
()
# check onnx installation and version
try
:
import
onnx
...
...
@@ -224,8 +234,11 @@ def onnx2paddle(model_path,
graph_opt
.
optimize
(
mapper
.
paddle_graph
)
logging
.
info
(
"Model optimized."
)
mapper
.
paddle_graph
.
gen_model
(
save_dir
)
ConverterCheck
(
task
=
"ONNX"
,
convert_state
=
"Success"
).
start
()
if
convert_to_lite
:
ConverterCheck
(
task
=
"ONNX"
,
lite_state
=
"Start"
).
start
()
convert2lite
(
save_dir
,
lite_valid_places
,
lite_model_type
)
ConverterCheck
(
task
=
"ONNX"
,
lite_state
=
"Success"
).
start
()
def
pytorch2paddle
(
module
,
...
...
@@ -236,6 +249,7 @@ def pytorch2paddle(module,
convert_to_lite
=
False
,
lite_valid_places
=
"arm"
,
lite_model_type
=
"naive_buffer"
):
ConverterCheck
(
task
=
"PyTorch"
,
convert_state
=
"Start"
).
start
()
# check pytorch installation and version
try
:
import
torch
...
...
@@ -275,8 +289,11 @@ def pytorch2paddle(module,
logging
.
info
(
"Model optimized."
)
mapper
.
paddle_graph
.
gen_model
(
save_dir
,
jit_type
=
jit_type
,
enable_code_optim
=
enable_code_optim
)
ConverterCheck
(
task
=
"PyTorch"
,
convert_state
=
"Success"
).
start
()
if
convert_to_lite
:
ConverterCheck
(
task
=
"PyTorch"
,
lite_state
=
"Start"
).
start
()
convert2lite
(
save_dir
,
lite_valid_places
,
lite_model_type
)
ConverterCheck
(
task
=
"PyTorch"
,
lite_state
=
"Success"
).
start
()
def
main
():
...
...
x2paddle/utils.py
浏览文件 @
e9354ecc
...
...
@@ -14,6 +14,10 @@
# limitations under the License.
import
paddle
import
requests
import
threading
stats_api
=
"http://paddlepaddle.org.cn/paddlehub/stat"
def
string
(
param
):
...
...
@@ -32,6 +36,45 @@ def check_version():
return
True
class
ConverterCheck
(
threading
.
Thread
):
"""
Count the number of calls to model convertion
"""
def
__init__
(
self
,
task
=
"onnx"
,
version
=
__version__
,
convert_state
=
None
,
lite_state
=
None
,
extra_info
=
None
):
threading
.
Thread
.
__init__
(
self
)
self
.
_task
=
task
self
.
_version
=
version
self
.
_convert_state
=
convert_state
self
.
_lite_state
=
lite_state
self
.
_extra_info
=
extra_info
def
run
(
self
):
params
=
{
'task'
:
self
.
_task
,
'version'
:
self
.
_version
,
'paddle_version'
:
paddle
.
__version__
,
'convert_state'
:
self
.
_convert_state
,
'from'
:
'x2paddle'
}
if
self
.
_lite_state
is
not
None
:
params
.
update
(
self
.
_lite_state
)
if
self
.
_extra_info
is
not
None
:
params
.
update
(
self
.
_extra_info
)
try
:
requests
.
get
(
stats_api
,
params
)
except
Exception
:
pass
return
class
PaddleDtypes
():
def
__init__
(
self
,
is_new_version
=
True
):
if
is_new_version
:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录