Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle-Lite
提交
e6ac5a2a
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看板
提交
e6ac5a2a
编写于
9月 18, 2018
作者:
xiebaiyuan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add mdl loader and paddle loader
todo convert
上级
2cada5ed
变更
6
展开全部
隐藏空白更改
内联
并排
Showing
6 changed file
with
1493 addition
and
0 deletion
+1493
-0
python/tools/mdl2fluid/framework.proto
python/tools/mdl2fluid/framework.proto
+176
-0
python/tools/mdl2fluid/framework_pb2.py
python/tools/mdl2fluid/framework_pb2.py
+1141
-0
python/tools/mdl2fluid/loader.py
python/tools/mdl2fluid/loader.py
+18
-0
python/tools/mdl2fluid/mdl2fluid.py
python/tools/mdl2fluid/mdl2fluid.py
+112
-0
python/tools/mdl2fluid/model_reader.py
python/tools/mdl2fluid/model_reader.py
+30
-0
python/tools/mdl2fluid/op_types.py
python/tools/mdl2fluid/op_types.py
+16
-0
未找到文件。
python/tools/mdl2fluid/framework.proto
0 → 100644
浏览文件 @
e6ac5a2a
/* Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. */
syntax
=
"proto2"
;
option
optimize_for
=
LITE_RUNTIME
;
package
paddle_mobile
.
framework.proto
;
enum
AttrType
{
INT
=
0
;
FLOAT
=
1
;
STRING
=
2
;
INTS
=
3
;
FLOATS
=
4
;
STRINGS
=
5
;
BOOLEAN
=
6
;
BOOLEANS
=
7
;
BLOCK
=
8
;
LONG
=
9
;
}
// OpDesc describes an instance of a C++ framework::OperatorBase
// derived class type.
message
OpDesc
{
message
Attr
{
required
string
name
=
1
;
required
AttrType
type
=
2
;
optional
int32
i
=
3
;
optional
float
f
=
4
;
optional
string
s
=
5
;
repeated
int32
ints
=
6
;
repeated
float
floats
=
7
;
repeated
string
strings
=
8
;
optional
bool
b
=
10
;
repeated
bool
bools
=
11
;
optional
int32
block_idx
=
12
;
optional
int64
l
=
13
;
};
message
Var
{
required
string
parameter
=
1
;
repeated
string
arguments
=
2
;
};
required
string
type
=
3
;
repeated
Var
inputs
=
1
;
repeated
Var
outputs
=
2
;
repeated
Attr
attrs
=
4
;
optional
bool
is_target
=
5
[
default
=
false
];
};
// OpProto describes a C++ framework::OperatorBase derived class.
message
OpProto
{
// VarProto describes the C++ type framework::Variable.
message
Var
{
required
string
name
=
1
;
required
string
comment
=
2
;
optional
bool
duplicable
=
3
[
default
=
false
];
optional
bool
intermediate
=
4
[
default
=
false
];
optional
bool
dispensable
=
5
[
default
=
false
];
}
// AttrProto describes the C++ type Attribute.
message
Attr
{
required
string
name
=
1
;
required
AttrType
type
=
2
;
required
string
comment
=
3
;
// If that attribute is generated, it means the Paddle third
// language binding has responsibility to fill that
// attribute. End-User should not set that attribute.
optional
bool
generated
=
4
[
default
=
false
];
}
required
string
type
=
1
;
repeated
Var
inputs
=
2
;
repeated
Var
outputs
=
3
;
repeated
Attr
attrs
=
4
;
required
string
comment
=
5
;
}
message
VarType
{
enum
Type
{
// Pod Types
BOOL
=
0
;
INT16
=
1
;
INT32
=
2
;
INT64
=
3
;
FP16
=
4
;
FP32
=
5
;
FP64
=
6
;
// Other types that may need additional descriptions
LOD_TENSOR
=
7
;
SELECTED_ROWS
=
8
;
FEED_MINIBATCH
=
9
;
FETCH_LIST
=
10
;
STEP_SCOPES
=
11
;
LOD_RANK_TABLE
=
12
;
LOD_TENSOR_ARRAY
=
13
;
PLACE_LIST
=
14
;
READER
=
15
;
CHANNEL
=
16
;
// Any runtime decided variable type is raw
// raw variables should manage their own allocations
// in operators like nccl_op
RAW
=
17
;
TUPLE
=
18
;
}
required
Type
type
=
1
;
message
TensorDesc
{
// Should only be PODType. Is enforced in C++
required
Type
data_type
=
1
;
repeated
int64
dims
=
2
;
// [UNK, 640, 480] is saved as [-1, 640, 480]
}
optional
TensorDesc
selected_rows
=
2
;
message
LoDTensorDesc
{
required
TensorDesc
tensor
=
1
;
optional
int32
lod_level
=
2
[
default
=
0
];
}
optional
LoDTensorDesc
lod_tensor
=
3
;
message
LoDTensorArrayDesc
{
required
TensorDesc
tensor
=
1
;
optional
int32
lod_level
=
2
[
default
=
0
];
}
optional
LoDTensorArrayDesc
tensor_array
=
4
;
message
ReaderDesc
{
repeated
LoDTensorDesc
lod_tensor
=
1
;
}
optional
ReaderDesc
reader
=
5
;
message
ChannelDesc
{
required
Type
data_type
=
1
;
required
int64
capacity
=
2
;
}
optional
ChannelDesc
channel
=
6
;
message
Tuple
{
repeated
Type
element_type
=
1
;
}
optional
Tuple
tuple
=
7
;
}
message
VarDesc
{
required
string
name
=
1
;
required
VarType
type
=
2
;
optional
bool
persistable
=
3
[
default
=
false
];
}
message
BlockDesc
{
required
int32
idx
=
1
;
required
int32
parent_idx
=
2
;
repeated
VarDesc
vars
=
3
;
repeated
OpDesc
ops
=
4
;
optional
int32
forward_block_idx
=
5
[
default
=
-
1
];
}
// Please refer to
// https://github.com/PaddlePaddle/Paddle/blob/develop/doc/design/program.md
// for more details.
// TODO(panyx0718): A model can have multiple programs. Need a
// way to distinguish them. Maybe ID or name?
message
ProgramDesc
{
repeated
BlockDesc
blocks
=
1
;
}
python/tools/mdl2fluid/framework_pb2.py
0 → 100644
浏览文件 @
e6ac5a2a
此差异已折叠。
点击以展开。
python/tools/mdl2fluid/loader.py
0 → 100644
浏览文件 @
e6ac5a2a
import
datetime
import
json
import
os
import
google.protobuf
as
pbg
import
framework_pb2
as
framework_pb2
def
loadmdl
(
json_path
):
print
(
'mdl json path : '
+
json_path
)
with
open
(
json_path
,
'r'
)
as
f
:
json_dick
=
json
.
load
(
f
)
# print(json_dick)
layers
=
(
json_dick
[
'layer'
])
for
layer
in
layers
:
print
(
layer
)
python/tools/mdl2fluid/mdl2fluid.py
0 → 100644
浏览文件 @
e6ac5a2a
import
json
import
framework_pb2
as
framework_pb2
import
op_types
as
types
def
load_mdl
(
mdl_json_path
):
# print('mdl json path : ' + mdl_json_path)
with
open
(
mdl_json_path
,
'r'
)
as
f
:
return
json
.
load
(
f
)
class
Converter
:
'convert mdlmodel to fluidmodel'
def
__init__
(
self
,
mdl_json_path
):
self
.
mdl_json_path
=
mdl_json_path
self
.
mdl_json
=
load_mdl
(
self
.
mdl_json_path
)
self
.
program_desc
=
framework_pb2
.
ProgramDesc
()
# print(json_dick)
# layers = (json_dick['layer'])
# for layer in layers:
# print(layer)
def
convert
(
self
):
print
'convert begin.....'
# add block_desc
block_desc
=
self
.
program_desc
.
blocks
.
add
()
block_desc
.
idx
=
0
block_desc
.
parent_idx
=
-
1
self
.
package_ops
(
block_desc
)
print
'blocks: '
print
self
.
program_desc
.
blocks
def
package_ops
(
self
,
block_desc
):
# add ops with layer
if
'layer'
in
self
.
mdl_json
:
layers_
=
self
.
mdl_json
[
'layer'
]
for
layer
in
layers_
:
desc_ops
=
block_desc
.
ops
.
add
()
# print layer
# for i in layer:
# print i
if
'name'
in
layer
:
l_name
=
layer
[
'name'
]
if
'weight'
in
layer
:
l_weights
=
layer
[
'weight'
]
if
'param'
in
layer
:
l_params
=
layer
[
'param'
]
if
'output'
in
layer
:
l_outputs
=
layer
[
'output'
]
if
'input'
in
layer
:
l_inputs
=
layer
[
'input'
]
inputs_add
=
desc_ops
.
inputs
.
add
()
for
i
in
l_inputs
:
# print i
inputs_add
.
parameter
=
''
inputs_add
.
arguments
.
append
(
i
)
if
'type'
in
layer
:
l_type
=
layer
[
'type'
]
# print l_type
# print mdl2fluid_op_layer_dict.get(l_type)
desc_ops
.
type
=
types
.
mdl2fluid_op_layer_dict
.
get
(
l_type
)
mdl_path
=
"multiobjects/YOLO_Universal.json"
# print mdl_path
# # model
# mdl_model = load_mdl(mdl_path)
# for key in mdl_model:
# print key
#
# # layer
# layers = mdl_model['layer']
# print layers
#
# for layer in layers:
# print layer
# for i in layer:
# print i
# if 'name' in layer:
# l_name = layer['name']
#
# if 'weight' in layer:
# l_weights = layer['weight']
#
# if 'param' in layer:
# l_params = layer['param']
#
# if 'output' in layer:
# l_outputs = layer['output']
#
# if 'input' in layer:
# l_inputs = layer['input']
#
# if 'type' in layer:
# l_type = layer['type']
#
# print mdl_model['matrix']
#
# package()
converter
=
Converter
(
mdl_path
)
converter
.
convert
()
python/tools/mdl2fluid/model_reader.py
0 → 100644
浏览文件 @
e6ac5a2a
import
os
import
framework_pb2
as
framework_pb2
def
read_model
(
model_path
):
print
(
'read_model.'
)
path_8
=
unicode
(
model_path
,
'utf8'
)
try
:
with
open
(
path_8
,
"rb"
)
as
f_model
:
print
get_file_size
(
model_path
)
desc
=
framework_pb2
.
ProgramDesc
()
desc
.
ParseFromString
(
f_model
.
read
())
print
desc
# print desc.blocks
except
IOError
:
print
": File not found. Creating a new file."
def
get_file_size
(
file_path
):
file_path
=
unicode
(
file_path
,
'utf8'
)
fsize
=
os
.
path
.
getsize
(
file_path
)
fsize
=
fsize
/
float
(
1024
*
1024
)
return
round
(
fsize
,
2
)
path
=
"/Users/xiebaiyuan/PaddleProject/paddle-mobile/python/tools/mdl2fluid/yolo/__model__"
read_model
(
path
)
python/tools/mdl2fluid/op_types.py
0 → 100644
浏览文件 @
e6ac5a2a
mdl2fluid_op_layer_dict
=
{
'ConvolutionLayer'
:
'fusion_conv_add'
,
'DepthwiseConvolutionLayer'
:
'fusion_conv_add'
,
'ReluLayer'
:
'relu'
,
'PointwiseConvolutionLayer'
:
'fusion_conv_add'
}
fusion_conv_add_dict
=
{
'inputs'
:
'Input'
,
'outputs'
:
'Out'
}
relu_dict
=
{
'inputs'
:
'X'
,
'outputs'
:
'Out'
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录