Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle-Lite
提交
b35beb05
P
Paddle-Lite
项目概览
PaddlePaddle
/
Paddle-Lite
通知
332
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看板
提交
b35beb05
编写于
9月 18, 2018
作者:
xiebaiyuan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add attrs
上级
051a168e
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
242 addition
and
42 deletion
+242
-42
python/tools/mdl2fluid/mdl2fluid.py
python/tools/mdl2fluid/mdl2fluid.py
+142
-36
python/tools/mdl2fluid/op_types.py
python/tools/mdl2fluid/op_types.py
+100
-6
未找到文件。
python/tools/mdl2fluid/mdl2fluid.py
浏览文件 @
b35beb05
...
...
@@ -47,47 +47,153 @@ class Converter:
if
'name'
in
layer
:
l_name
=
layer
[
'name'
]
if
'type'
in
layer
:
l_type
=
layer
[
'type'
]
# print l_type
# print mdl2fluid_op_layer_dict.get(l_type)
desc_ops_add
.
type
=
types
.
mdl2fluid_op_layer_dict
.
get
(
l_type
)
self
.
package_ops_type
(
desc_ops_add
,
layer
)
if
'weight'
in
layer
:
l_weights
=
layer
[
'weight'
]
op_tup
=
types
.
op_io_dict
.
get
(
desc_ops_add
.
type
).
get
(
types
.
mdl_weight_key
)
# print len(op_tup)
for
i
,
val
in
enumerate
(
op_tup
):
print
i
print
val
inputs_add
=
desc_ops_add
.
inputs
.
add
()
# print w
inputs_add
.
parameter
=
op_tup
[
i
]
inputs_add
.
arguments
.
append
(
l_weights
[
i
])
# for w in l_weights:
# inputs_add = desc_ops_add.inputs.add()
# # print w
# inputs_add.parameter = op_tup[0]
# inputs_add.arguments.append(w)
if
'param'
in
layer
:
l_params
=
layer
[
'param'
]
self
.
package_ops_weight2inputs
(
desc_ops_add
,
layer
)
if
'output'
in
layer
:
l_outputs
=
layer
[
'output'
]
for
o
in
l_outputs
:
# print o
outputs_add
=
desc_ops_add
.
outputs
.
add
()
outputs_add
.
parameter
=
types
.
op_io_dict
.
get
(
desc_ops_add
.
type
).
get
(
types
.
mdl_outputs_key
)
outputs_add
.
arguments
.
append
(
o
)
self
.
package_ops_outputs
(
desc_ops_add
,
layer
)
if
'input'
in
layer
:
l_inputs
=
layer
[
'input'
]
for
i
in
l_inputs
:
inputs_add
=
desc_ops_add
.
inputs
.
add
()
# print i
inputs_add
.
parameter
=
types
.
op_io_dict
.
get
(
desc_ops_add
.
type
).
get
(
types
.
mdl_inputs_key
)
inputs_add
.
arguments
.
append
(
i
)
self
.
package_ops_inputs
(
desc_ops_add
,
layer
)
self
.
package_ops_attrs
(
desc_ops_add
,
layer
)
@
staticmethod
def
package_ops_attrs
(
desc_ops_add
,
layer
):
# print l_params
# print desc_ops_add.type
if
desc_ops_add
.
type
==
types
.
op_fluid_fusion_conv_add
:
Converter
.
pack_fusion_conv_add_attr
(
desc_ops_add
,
layer
)
elif
desc_ops_add
.
type
==
types
.
op_fluid_relu
:
# fusion_conv_add : attrs
attrs_add
=
desc_ops_add
.
attrs
.
add
()
attrs_add
.
name
=
'use_mkldnn'
# boolean
attrs_add
.
type
=
6
attrs_add
.
b
=
0
@
staticmethod
def
pack_fusion_conv_add_attr
(
desc_ops_add
,
layer
):
# fusion_conv_add : attrs
attrs_add
=
desc_ops_add
.
attrs
.
add
()
attrs_add
.
name
=
'workspace_size_MB'
# 0-->INT
attrs_add
.
type
=
0
attrs_add
.
i
=
4096
attrs_add
=
desc_ops_add
.
attrs
.
add
()
attrs_add
.
name
=
'data_format'
# 2-->STRING
attrs_add
.
type
=
2
attrs_add
.
s
=
'AnyLayout'
attrs_add
=
desc_ops_add
.
attrs
.
add
()
attrs_add
.
name
=
'use_mkldnn'
# boolean
attrs_add
.
type
=
6
attrs_add
.
b
=
0
attrs_add
=
desc_ops_add
.
attrs
.
add
()
attrs_add
.
name
=
'use_cudnn'
# boolean
attrs_add
.
type
=
6
attrs_add
.
b
=
1
attrs_add
=
desc_ops_add
.
attrs
.
add
()
attrs_add
.
name
=
'dilations'
# ints
attrs_add
.
type
=
3
attrs_add
.
ints
.
append
(
1
)
attrs_add
.
ints
.
append
(
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
.
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
.
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'
)])
attrs_add
=
desc_ops_add
.
attrs
.
add
()
attrs_add
.
name
=
'groups'
# int
attrs_add
.
type
=
0
attrs_add
.
i
=
l_params
[
types
.
fusion_conv_add_attrs_dict
.
get
(
'groups'
)]
#
# op_attrs_tupl = types.op_io_dict.get(desc_ops_add.type) \
# .get(types.mdl_attrs_key)
#
#
#
#
# # group stride padding
# print '----------------------'
# for i, val in enumerate(op_attrs_tupl):
# attrs_add = desc_ops_add.attrs.add()
# attr_name = op_attrs_tupl[i]
# print attr_name
# attrs_add.name = attr_name
# attrs_add.type = types.fluid_attrs_type_dict.get(attr_name)
# attrs_add.
# print l_params[types.fusion_conv_add_attrs_dict.get(attr_name)]
# for p in l_params:
# attrs_add = desc_ops_add.attrs.add()
@
staticmethod
def
package_ops_inputs
(
desc_ops_add
,
layer
):
l_inputs
=
layer
[
'input'
]
for
i
in
l_inputs
:
inputs_add
=
desc_ops_add
.
inputs
.
add
()
# print i
inputs_add
.
parameter
=
types
.
op_io_dict
.
get
(
desc_ops_add
.
type
).
get
(
types
.
mdl_inputs_key
)
inputs_add
.
arguments
.
append
(
i
)
@
staticmethod
def
package_ops_outputs
(
desc_ops_add
,
layer
):
l_outputs
=
layer
[
'output'
]
for
o
in
l_outputs
:
# print o
outputs_add
=
desc_ops_add
.
outputs
.
add
()
outputs_add
.
parameter
=
types
.
op_io_dict
.
get
(
desc_ops_add
.
type
).
get
(
types
.
mdl_outputs_key
)
outputs_add
.
arguments
.
append
(
o
)
@
staticmethod
def
package_ops_weight2inputs
(
desc_ops_add
,
layer
):
l_weights
=
layer
[
'weight'
]
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
):
# print i
# print val
inputs_add
=
desc_ops_add
.
inputs
.
add
()
# print w
inputs_add
.
parameter
=
op_weight_tup
[
i
]
inputs_add
.
arguments
.
append
(
l_weights
[
i
])
# for w in l_weights:
# inputs_add = desc_ops_add.inputs.add()
# # print w
# inputs_add.parameter = op_weight_tup[0]
# inputs_add.arguments.append(w)
@
staticmethod
def
package_ops_type
(
desc_ops_add
,
layer
):
l_type
=
layer
[
'type'
]
# print l_type
# print mdl2fluid_op_layer_dict.get(l_type)
desc_ops_add
.
type
=
types
.
mdl2fluid_op_layer_dict
.
get
(
l_type
)
# print mdl_path
...
...
python/tools/mdl2fluid/op_types.py
浏览文件 @
b35beb05
# coding=utf-8
# mdl layers
layer_mdl_conv
=
'ConvolutionLayer'
layer_mdl_deepwise_conv
=
'DepthwiseConvolutionLayer'
layer_mdl_relu
=
'ReluLayer'
layer_mdl_pointwise_add
=
'PointwiseConvolutionLayer'
# fluid ops
op_fluid_fusion_conv_add
=
'fusion_conv_add'
op_fluid_relu
=
'relu'
# dict mdk layer --- fluid op
mdl2fluid_op_layer_dict
=
{
'ConvolutionLayer'
:
'fusion_conv_add'
,
'DepthwiseConvolutionLayer'
:
'fusion_conv_add'
,
'ReluLayer'
:
'relu'
,
'PointwiseConvolutionLayer'
:
'fusion_conv_add'
layer_mdl_conv
:
op_fluid_fusion_conv_add
,
layer_mdl_deepwise_conv
:
op_fluid_fusion_conv_add
,
layer_mdl_relu
:
op_fluid_relu
,
layer_mdl_pointwise_add
:
op_fluid_fusion_conv_add
}
mdl_outputs_key
=
"outputs"
mdl_inputs_key
=
"inputs"
mdl_weight_key
=
"weights"
# inputs_key = "input
s"
mdl_attrs_key
=
"param
s"
# dict of mdl-input _out param to fluid input out attrs
fusion_conv_add_dict
=
{
mdl_inputs_key
:
'Input'
,
mdl_outputs_key
:
'Out'
,
mdl_weight_key
:
(
'Filter'
,
'Y'
)
mdl_weight_key
:
(
'Filter'
,
'Y'
),
mdl_attrs_key
:
(
# 'workspace_size_MB', 'use_mkldnn', 'use_cudnn', 'data_format','dilations',
# dilations = [1,1]
'groups'
,
'paddings'
,
'strides'
# 'axis'
)
}
relu_dict
=
{
...
...
@@ -22,8 +42,82 @@ relu_dict = {
mdl_weight_key
:
()
}
# mdl layers --- fluid ops
op_io_dict
=
{
'fusion_conv_add'
:
fusion_conv_add_dict
,
'relu'
:
relu_dict
}
# fluid attr key --- mdl params key
fusion_conv_add_attrs_dict
=
{
'paddings'
:
'pad'
,
'strides'
:
'stride'
,
'groups'
:
'group'
}
# fluid attr key --- mdl params key
fluid_attrs_type_dict
=
{
'paddings'
:
0
,
'strides'
:
6
,
'groups'
:
6
}
# '': "bias_term", 是不是要add 目前 yolo的模型都是 bias_term = 1
# attrs {
# name: "axis"
# type: INT
# i: 1
# }
# attrs_name = {
# 'name': "workspace_size_MB",
# 'type': 'INT',
# 'i': '4096'
# }
# attrs
# {
# name: "data_format"
# type: STRING
# s: "AnyLayout"
# }
# attrs
# {
# name: "use_mkldnn"
# type: BOOLEAN
# b: false
# }
# attrs
# {
# name: "use_cudnn"
# type: BOOLEAN
# b: true
# }
# attrs
# {
# name: "dilations"
# type: INTS
# ints: 1
# ints: 1
# }
# attrs
# {
# name: "groups"
# type: INT
# i: 1
# }
# attrs
# {
# name: "paddings"
# type: INTS
# ints: 0
# ints: 0
# }
# attrs
# {
# name: "strides"
# type: INTS
# ints: 1
# ints: 1
# }
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录