Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle-Lite
提交
ed5a5afd
P
Paddle-Lite
项目概览
PaddlePaddle
/
Paddle-Lite
通知
331
Star
4
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
271
列表
看板
标记
里程碑
合并请求
78
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle-Lite
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
271
Issue
271
列表
看板
标记
里程碑
合并请求
78
合并请求
78
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
ed5a5afd
编写于
9月 19, 2018
作者:
xiebaiyuan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
run success mdl to fluid 4 yolo
上级
64de944f
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
31 addition
and
11 deletion
+31
-11
python/tools/mdl2fluid/mdl2fluid.py
python/tools/mdl2fluid/mdl2fluid.py
+29
-9
python/tools/mdl2fluid/swicher.py
python/tools/mdl2fluid/swicher.py
+2
-2
未找到文件。
python/tools/mdl2fluid/mdl2fluid.py
浏览文件 @
ed5a5afd
...
...
@@ -22,6 +22,7 @@ class Converter:
self
.
mdl_json
=
load_mdl
(
self
.
mdl_json_path
)
self
.
program_desc
=
framework_pb2
.
ProgramDesc
()
self
.
weight_list_
=
[]
self
.
deepwise_weight_list_
=
[]
# print(json_dick)
# layers = (json_dick['layer'])
# for layer in layers:
...
...
@@ -46,7 +47,6 @@ class Converter:
f
.
write
(
desc_serialize_to_string
)
f
.
close
()
def
package_ops
(
self
,
block_desc
):
self
.
add_op_feed
(
block_desc
)
...
...
@@ -63,7 +63,6 @@ class Converter:
# print i
if
'name'
in
layer
:
l_name
=
layer
[
'name'
]
if
'type'
in
layer
:
self
.
package_ops_type
(
desc_ops_add
,
layer
)
...
...
@@ -159,20 +158,26 @@ class Converter:
attrs_add
.
ints
.
append
(
1
)
attrs_add
.
ints
.
append
(
1
)
attrs_add
=
desc_ops_add
.
attrs
.
add
()
attrs_add
.
name
=
'axis'
# int
attrs_add
.
type
=
0
attrs_add
.
i
=
1
if
'param'
in
layer
:
l_params
=
layer
[
'param'
]
attrs_add
=
desc_ops_add
.
attrs
.
add
()
attrs_add
.
name
=
'paddings'
# ints
attrs_add
.
type
=
6
attrs_add
.
type
=
3
attrs_add
.
ints
.
append
(
l_params
[
types
.
fusion_conv_add_attrs_dict
.
get
(
'paddings'
)])
attrs_add
.
ints
.
append
(
l_params
[
types
.
fusion_conv_add_attrs_dict
.
get
(
'paddings'
)])
attrs_add
=
desc_ops_add
.
attrs
.
add
()
attrs_add
.
name
=
'strides'
# ints
attrs_add
.
type
=
6
attrs_add
.
type
=
3
attrs_add
.
ints
.
append
(
l_params
[
types
.
fusion_conv_add_attrs_dict
.
get
(
'strides'
)])
attrs_add
.
ints
.
append
(
l_params
[
types
.
fusion_conv_add_attrs_dict
.
get
(
'strides'
)])
...
...
@@ -181,6 +186,7 @@ class Converter:
# int
attrs_add
.
type
=
0
attrs_add
.
i
=
l_params
[
types
.
fusion_conv_add_attrs_dict
.
get
(
'groups'
)]
# attrs_add.i = 1
#
# op_attrs_tupl = types.op_io_dict.get(desc_ops_add.type) \
...
...
@@ -225,6 +231,11 @@ class Converter:
l_weights
=
layer
[
'weight'
]
for
w
in
l_weights
:
self
.
weight_list_
.
append
(
w
)
if
layer
[
'type'
]
==
'DepthwiseConvolutionLayer'
:
# print l_weights[0]
self
.
deepwise_weight_list_
.
append
(
l_weights
[
0
])
op_weight_tup
=
types
.
op_io_dict
.
get
(
desc_ops_add
.
type
).
get
(
types
.
mdl_weight_key
)
# print len(op_weight_tup)
for
i
,
val
in
enumerate
(
op_weight_tup
):
...
...
@@ -264,7 +275,7 @@ class Converter:
vars_add
=
block_desc
.
vars
.
add
()
vars_add
.
name
=
j
vars_add
.
type
.
type
=
7
# 7 is lodtensor
print
j
#
print j
tensor
=
vars_add
.
type
.
lod_tensor
.
tensor
tensor
.
data_type
=
5
# 5 is FP32
...
...
@@ -280,13 +291,22 @@ class Converter:
# tensor.dims.append(dims_of_matrix[1]) # H
# tensor.dims.append(dims_of_matrix[2]) # W
# else:
# issues in mdl model filter swich n and c
if
j
in
self
.
deepwise_weight_list_
and
len
(
dims_of_matrix
)
==
4
:
print
j
tensor
.
dims
.
append
(
dims_of_matrix
[
1
])
tensor
.
dims
.
append
(
dims_of_matrix
[
0
])
tensor
.
dims
.
append
(
dims_of_matrix
[
2
])
tensor
.
dims
.
append
(
dims_of_matrix
[
3
])
print
tensor
.
dims
else
:
for
dims
in
dims_of_matrix
:
# print dims
tensor
.
dims
.
append
(
dims
)
if
j
in
self
.
weight_list_
:
vars_add
.
persistable
=
1
# todo parweight channel
dims_size
=
len
(
dims_of_matrix
)
# print dims_size
if
dims_size
==
4
:
...
...
python/tools/mdl2fluid/swicher.py
浏览文件 @
ed5a5afd
...
...
@@ -67,9 +67,9 @@ class Swichter:
def
read_head
(
self
,
head_file
):
from_file
=
open
(
head_file
,
"rb"
)
read
=
from_file
.
read
(
20
)
print
read
#
print read
from_file
.
close
()
print
read
#
print read
return
read
def
copy_add_head
(
self
,
from_file_name
,
to_file_name
,
tmp_file_name
):
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录