Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle-Lite
提交
34e0bd57
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看板
提交
34e0bd57
编写于
9月 18, 2018
作者:
xiebaiyuan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add persistable params
上级
02c76ee2
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
38 addition
and
6 deletion
+38
-6
python/tools/mdl2fluid/mdl2fluid.py
python/tools/mdl2fluid/mdl2fluid.py
+37
-5
python/tools/mdl2fluid/model_reader.py
python/tools/mdl2fluid/model_reader.py
+1
-1
未找到文件。
python/tools/mdl2fluid/mdl2fluid.py
浏览文件 @
34e0bd57
...
@@ -17,7 +17,7 @@ class Converter:
...
@@ -17,7 +17,7 @@ class Converter:
print
mdl_json_path
print
mdl_json_path
self
.
mdl_json
=
load_mdl
(
self
.
mdl_json_path
)
self
.
mdl_json
=
load_mdl
(
self
.
mdl_json_path
)
self
.
program_desc
=
framework_pb2
.
ProgramDesc
()
self
.
program_desc
=
framework_pb2
.
ProgramDesc
()
self
.
weight_list_
=
[]
# print(json_dick)
# print(json_dick)
# layers = (json_dick['layer'])
# layers = (json_dick['layer'])
# for layer in layers:
# for layer in layers:
...
@@ -33,6 +33,12 @@ class Converter:
...
@@ -33,6 +33,12 @@ class Converter:
self
.
package_vars
(
block_desc
)
self
.
package_vars
(
block_desc
)
print
'blocks: '
print
'blocks: '
print
self
.
program_desc
.
blocks
print
self
.
program_desc
.
blocks
print
'convert end.....'
desc_serialize_to_string
=
self
.
program_desc
.
SerializeToString
()
f
=
open
(
"newyolo/__model__"
,
"wb"
)
f
.
write
(
desc_serialize_to_string
)
f
.
close
()
def
package_ops
(
self
,
block_desc
):
def
package_ops
(
self
,
block_desc
):
...
@@ -50,8 +56,10 @@ class Converter:
...
@@ -50,8 +56,10 @@ class Converter:
# print i
# print i
if
'name'
in
layer
:
if
'name'
in
layer
:
l_name
=
layer
[
'name'
]
l_name
=
layer
[
'name'
]
if
'type'
in
layer
:
if
'type'
in
layer
:
self
.
package_ops_type
(
desc_ops_add
,
layer
)
self
.
package_ops_type
(
desc_ops_add
,
layer
)
if
'weight'
in
layer
:
if
'weight'
in
layer
:
self
.
package_ops_weight2inputs
(
desc_ops_add
,
layer
)
self
.
package_ops_weight2inputs
(
desc_ops_add
,
layer
)
...
@@ -62,6 +70,7 @@ class Converter:
...
@@ -62,6 +70,7 @@ class Converter:
self
.
package_ops_inputs
(
desc_ops_add
,
layer
)
self
.
package_ops_inputs
(
desc_ops_add
,
layer
)
self
.
package_ops_attrs
(
desc_ops_add
,
layer
)
self
.
package_ops_attrs
(
desc_ops_add
,
layer
)
self
.
add_op_fetch
(
block_desc
)
self
.
add_op_fetch
(
block_desc
)
def
add_op_feed
(
self
,
block_desc
):
def
add_op_feed
(
self
,
block_desc
):
...
@@ -205,18 +214,19 @@ class Converter:
...
@@ -205,18 +214,19 @@ class Converter:
outputs_add
.
parameter
=
types
.
op_io_dict
.
get
(
desc_ops_add
.
type
).
get
(
types
.
mdl_outputs_key
)
outputs_add
.
parameter
=
types
.
op_io_dict
.
get
(
desc_ops_add
.
type
).
get
(
types
.
mdl_outputs_key
)
outputs_add
.
arguments
.
append
(
o
)
outputs_add
.
arguments
.
append
(
o
)
@
staticmethod
def
package_ops_weight2inputs
(
self
,
desc_ops_add
,
layer
):
def
package_ops_weight2inputs
(
desc_ops_add
,
layer
):
l_weights
=
layer
[
'weight'
]
l_weights
=
layer
[
'weight'
]
for
w
in
l_weights
:
self
.
weight_list_
.
append
(
w
)
op_weight_tup
=
types
.
op_io_dict
.
get
(
desc_ops_add
.
type
).
get
(
types
.
mdl_weight_key
)
op_weight_tup
=
types
.
op_io_dict
.
get
(
desc_ops_add
.
type
).
get
(
types
.
mdl_weight_key
)
# print len(op_weight_tup)
# print len(op_weight_tup)
for
i
,
val
in
enumerate
(
op_weight_tup
):
for
i
,
val
in
enumerate
(
op_weight_tup
):
# print i
# print i
# print val
# print val
inputs_add
=
desc_ops_add
.
inputs
.
add
()
inputs_add
=
desc_ops_add
.
inputs
.
add
()
# print w
inputs_add
.
parameter
=
op_weight_tup
[
i
]
inputs_add
.
parameter
=
op_weight_tup
[
i
]
inputs_add
.
arguments
.
append
(
l_weights
[
i
])
inputs_add
.
arguments
.
append
(
l_weights
[
i
])
# for w in l_weights:
# for w in l_weights:
# inputs_add = desc_ops_add.inputs.add()
# inputs_add = desc_ops_add.inputs.add()
# # print w
# # print w
...
@@ -231,6 +241,25 @@ class Converter:
...
@@ -231,6 +241,25 @@ class Converter:
desc_ops_add
.
type
=
types
.
mdl2fluid_op_layer_dict
.
get
(
l_type
)
desc_ops_add
.
type
=
types
.
mdl2fluid_op_layer_dict
.
get
(
l_type
)
def
package_vars
(
self
,
block_desc
):
def
package_vars
(
self
,
block_desc
):
# feed
# vars
# {
# name: "feed"
# type {
# type: FEED_MINIBATCH
# }
# persistable: true
# }
vars_add
=
block_desc
.
vars
.
add
()
vars_add
.
name
=
'feed'
vars_add
.
type
.
type
=
9
# 9 is FEED_MINIBATCH
vars_add
.
persistable
=
1
# fetch
vars_add
=
block_desc
.
vars
.
add
()
vars_add
.
name
=
'fetch'
vars_add
.
type
.
type
=
10
# 10 is fetch list
vars_add
.
persistable
=
1
json_matrix_
=
self
.
mdl_json
[
'matrix'
]
json_matrix_
=
self
.
mdl_json
[
'matrix'
]
# print json_matrix_
# print json_matrix_
for
j
in
json_matrix_
:
for
j
in
json_matrix_
:
...
@@ -242,7 +271,10 @@ class Converter:
...
@@ -242,7 +271,10 @@ class Converter:
tensor
.
data_type
=
5
# 5 is FP32
tensor
.
data_type
=
5
# 5 is FP32
for
dims
in
json_matrix_
.
get
(
j
):
for
dims
in
json_matrix_
.
get
(
j
):
tensor
.
dims
.
append
(
dims
)
tensor
.
dims
.
append
(
dims
)
pass
if
j
in
self
.
weight_list_
:
vars_add
.
persistable
=
1
else
:
vars_add
.
persistable
=
0
# print mdl_path
# print mdl_path
...
...
python/tools/mdl2fluid/model_reader.py
浏览文件 @
34e0bd57
...
@@ -26,5 +26,5 @@ def get_file_size(file_path):
...
@@ -26,5 +26,5 @@ def get_file_size(file_path):
return
round
(
fsize
,
2
)
return
round
(
fsize
,
2
)
path
=
"
/Users/xiebaiyuan/PaddleProject/paddle-mobile/python/tools/mdl2fluid/
yolo/__model__"
path
=
"
new
yolo/__model__"
read_model
(
path
)
read_model
(
path
)
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录