Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
冰之2023
Mace
提交
9fd509dc
Mace
项目概览
冰之2023
/
Mace
与 Fork 源项目一致
Fork自
Xiaomi / Mace
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Mace
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
9fd509dc
编写于
12月 01, 2017
作者:
W
wuchenghui
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix graph convert
上级
48a038ca
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
54 addition
and
14 deletion
+54
-14
mace/proto/mace.proto
mace/proto/mace.proto
+1
-1
mace/python/tools/tf_converter_lib.py
mace/python/tools/tf_converter_lib.py
+53
-13
未找到文件。
mace/proto/mace.proto
浏览文件 @
9fd509dc
...
@@ -77,7 +77,7 @@ message OperatorDef {
...
@@ -77,7 +77,7 @@ message OperatorDef {
optional
string
name
=
3
;
optional
string
name
=
3
;
optional
string
type
=
4
;
optional
string
type
=
4
;
repeated
Argument
arg
=
5
;
repeated
Argument
arg
=
5
;
optional
OutputShape
output_shape
=
6
;
repeated
OutputShape
output_shape
=
6
;
// Memory optimization: only support one single output op
// Memory optimization: only support one single output op
optional
int32
mem_id
=
10
[
default
=
-
1
];
optional
int32
mem_id
=
10
[
default
=
-
1
];
...
...
mace/python/tools/tf_converter_lib.py
浏览文件 @
9fd509dc
...
@@ -18,15 +18,6 @@ def convert_tensor(op, tensor):
...
@@ -18,15 +18,6 @@ def convert_tensor(op, tensor):
tensor
.
name
=
op
.
outputs
[
0
].
name
tensor
.
name
=
op
.
outputs
[
0
].
name
shape
=
list
(
tf_tensor
.
shape
)
shape
=
list
(
tf_tensor
.
shape
)
if
(
op
.
name
.
find
(
'pointwise_kernel'
)
!=
-
1
or
op
.
name
.
find
(
'depthwise_kernel'
)
!=
-
1
or
op
.
name
.
endswith
(
'weights'
)
or
op
.
name
.
endswith
(
'kernel'
))
\
and
op
.
outputs
[
0
].
consumers
()[
0
].
type
.
find
(
'Conv'
)
!=
-
1
:
if
op
.
outputs
[
0
].
consumers
()[
0
].
get_attr
(
'data_format'
)
==
'NHWC'
:
tf_tensor
=
np
.
transpose
(
tf_tensor
,
axes
=
(
3
,
2
,
0
,
1
))
shape
=
[
shape
[
3
],
shape
[
2
],
shape
[
0
],
shape
[
1
]]
# print (tensor.name, shape)
tensor
.
dims
.
extend
(
shape
)
tensor
.
dims
.
extend
(
shape
)
tf_dt
=
op
.
get_attr
(
'dtype'
)
tf_dt
=
op
.
get_attr
(
'dtype'
)
...
@@ -66,6 +57,12 @@ def convert_ops(unresolved_ops, net_def):
...
@@ -66,6 +57,12 @@ def convert_ops(unresolved_ops, net_def):
op_def
.
type
=
first_op
.
type
op_def
.
type
=
first_op
.
type
op_def
.
input
.
extend
([
input
.
name
for
input
in
first_op
.
inputs
])
op_def
.
input
.
extend
([
input
.
name
for
input
in
first_op
.
inputs
])
op_def
.
output
.
extend
([
output
.
name
for
output
in
first_op
.
outputs
])
op_def
.
output
.
extend
([
output
.
name
for
output
in
first_op
.
outputs
])
output_shapes
=
[]
for
output
in
first_op
.
outputs
:
output_shape
=
mace_pb2
.
OutputShape
()
output_shape
.
dims
.
extend
(
output
.
shape
.
as_list
())
output_shapes
.
append
(
output_shape
)
op_def
.
output_shape
.
extend
(
output_shapes
)
padding_arg
=
op_def
.
arg
.
add
()
padding_arg
=
op_def
.
arg
.
add
()
padding_arg
.
name
=
'padding'
padding_arg
.
name
=
'padding'
padding_arg
.
i
=
padding_mode
[
first_op
.
get_attr
(
'padding'
)]
padding_arg
.
i
=
padding_mode
[
first_op
.
get_attr
(
'padding'
)]
...
@@ -74,7 +71,7 @@ def convert_ops(unresolved_ops, net_def):
...
@@ -74,7 +71,7 @@ def convert_ops(unresolved_ops, net_def):
strides_arg
.
ints
.
extend
(
first_op
.
get_attr
(
'strides'
)[
1
:
3
])
strides_arg
.
ints
.
extend
(
first_op
.
get_attr
(
'strides'
)[
1
:
3
])
data_format_arg
=
op_def
.
arg
.
add
()
data_format_arg
=
op_def
.
arg
.
add
()
data_format_arg
.
name
=
'data_format'
data_format_arg
.
name
=
'data_format'
data_format_arg
.
s
=
'N
CHW
'
data_format_arg
.
s
=
'N
HWC
'
if
ops_count
>=
2
and
unresolved_ops
[
1
].
type
==
'BiasAdd'
:
if
ops_count
>=
2
and
unresolved_ops
[
1
].
type
==
'BiasAdd'
:
bias_add_op
=
unresolved_ops
[
1
]
bias_add_op
=
unresolved_ops
[
1
]
...
@@ -105,6 +102,12 @@ def convert_ops(unresolved_ops, net_def):
...
@@ -105,6 +102,12 @@ def convert_ops(unresolved_ops, net_def):
op_def
.
type
=
'BatchNorm'
op_def
.
type
=
'BatchNorm'
op_def
.
input
.
extend
([
input_name
,
gamma
,
beta
,
mean
,
variance
,
epsilon
])
op_def
.
input
.
extend
([
input_name
,
gamma
,
beta
,
mean
,
variance
,
epsilon
])
op_def
.
output
.
extend
([
output
.
name
for
output
in
add_1_op
.
outputs
])
op_def
.
output
.
extend
([
output
.
name
for
output
in
add_1_op
.
outputs
])
output_shapes
=
[]
for
output
in
add_1_op
.
outputs
:
output_shape
=
mace_pb2
.
OutputShape
()
output_shape
.
dims
.
extend
(
output
.
shape
.
as_list
())
output_shapes
.
append
(
output_shape
)
op_def
.
output_shape
.
extend
(
output_shapes
)
resolved_count
=
7
resolved_count
=
7
elif
first_op
.
type
==
'Relu6'
:
elif
first_op
.
type
==
'Relu6'
:
...
@@ -113,6 +116,12 @@ def convert_ops(unresolved_ops, net_def):
...
@@ -113,6 +116,12 @@ def convert_ops(unresolved_ops, net_def):
op_def
.
type
=
'Relu'
op_def
.
type
=
'Relu'
op_def
.
input
.
extend
([
input
.
name
for
input
in
first_op
.
inputs
])
op_def
.
input
.
extend
([
input
.
name
for
input
in
first_op
.
inputs
])
op_def
.
output
.
extend
([
output
.
name
for
output
in
first_op
.
outputs
])
op_def
.
output
.
extend
([
output
.
name
for
output
in
first_op
.
outputs
])
output_shapes
=
[]
for
output
in
first_op
.
outputs
:
output_shape
=
mace_pb2
.
OutputShape
()
output_shape
.
dims
.
extend
(
output
.
shape
.
as_list
())
output_shapes
.
append
(
output_shape
)
op_def
.
output_shape
.
extend
(
output_shapes
)
max_limit_arg
=
op_def
.
arg
.
add
()
max_limit_arg
=
op_def
.
arg
.
add
()
max_limit_arg
.
name
=
'max_limit'
max_limit_arg
.
name
=
'max_limit'
max_limit_arg
.
f
=
6
max_limit_arg
.
f
=
6
...
@@ -122,6 +131,12 @@ def convert_ops(unresolved_ops, net_def):
...
@@ -122,6 +131,12 @@ def convert_ops(unresolved_ops, net_def):
op_def
.
type
=
'Pooling'
op_def
.
type
=
'Pooling'
op_def
.
input
.
extend
([
input
.
name
for
input
in
first_op
.
inputs
])
op_def
.
input
.
extend
([
input
.
name
for
input
in
first_op
.
inputs
])
op_def
.
output
.
extend
([
output
.
name
for
output
in
first_op
.
outputs
])
op_def
.
output
.
extend
([
output
.
name
for
output
in
first_op
.
outputs
])
output_shapes
=
[]
for
output
in
first_op
.
outputs
:
output_shape
=
mace_pb2
.
OutputShape
()
output_shape
.
dims
.
extend
(
output
.
shape
.
as_list
())
output_shapes
.
append
(
output_shape
)
op_def
.
output_shape
.
extend
(
output_shapes
)
pooling_type_arg
=
op_def
.
arg
.
add
()
pooling_type_arg
=
op_def
.
arg
.
add
()
pooling_type_arg
.
name
=
'pooling_type'
pooling_type_arg
.
name
=
'pooling_type'
pooling_type_arg
.
i
=
pooling_type_mode
[
first_op
.
type
]
pooling_type_arg
.
i
=
pooling_type_mode
[
first_op
.
type
]
...
@@ -136,21 +151,46 @@ def convert_ops(unresolved_ops, net_def):
...
@@ -136,21 +151,46 @@ def convert_ops(unresolved_ops, net_def):
kernels_arg
.
ints
.
extend
(
first_op
.
get_attr
(
'ksize'
)[
1
:
3
])
kernels_arg
.
ints
.
extend
(
first_op
.
get_attr
(
'ksize'
)[
1
:
3
])
data_format_arg
=
op_def
.
arg
.
add
()
data_format_arg
=
op_def
.
arg
.
add
()
data_format_arg
.
name
=
'data_format'
data_format_arg
.
name
=
'data_format'
data_format_arg
.
s
=
'N
CHW
'
data_format_arg
.
s
=
'N
HWC
'
elif
first_op
.
type
==
'Add'
:
elif
first_op
.
type
==
'Add'
:
op_def
=
net_def
.
op
.
add
()
op_def
=
net_def
.
op
.
add
()
op_def
.
name
=
first_op
.
name
op_def
.
name
=
first_op
.
name
op_def
.
type
=
"AddN"
op_def
.
type
=
"AddN"
op_def
.
input
.
extend
([
input
.
name
for
input
in
first_op
.
inputs
])
op_def
.
input
.
extend
([
input
.
name
for
input
in
first_op
.
inputs
])
op_def
.
output
.
extend
([
output
.
name
for
output
in
first_op
.
outputs
])
op_def
.
output
.
extend
([
output
.
name
for
output
in
first_op
.
outputs
])
elif
first_op
.
type
in
[
'Relu'
,
'ResizeBilinear'
,
'SpaceToBatchND'
,
'BatchToSpaceND'
]:
output_shapes
=
[]
for
output
in
first_op
.
outputs
:
output_shape
=
mace_pb2
.
OutputShape
()
output_shape
.
dims
.
extend
(
output
.
shape
.
as_list
())
output_shapes
.
append
(
output_shape
)
op_def
.
output_shape
.
extend
(
output_shapes
)
elif
first_op
.
type
==
'ConcatV2'
:
op_def
=
net_def
.
op
.
add
()
op_def
.
name
=
first_op
.
name
op_def
.
type
=
"Concat"
op_def
.
input
.
extend
([
input
.
name
for
input
in
first_op
.
inputs
])
op_def
.
output
.
extend
([
output
.
name
for
output
in
first_op
.
outputs
])
output_shapes
=
[]
for
output
in
first_op
.
outputs
:
output_shape
=
mace_pb2
.
OutputShape
()
output_shape
.
dims
.
extend
(
output
.
shape
.
as_list
())
output_shapes
.
append
(
output_shape
)
op_def
.
output_shape
.
extend
(
output_shapes
)
elif
first_op
.
type
in
[
'Relu'
,
'ResizeBilinear'
,
'SpaceToBatchND'
,
'BatchToSpaceND'
,
'BiasAdd'
,
'FusedBatchNorm'
]:
op_def
=
net_def
.
op
.
add
()
op_def
=
net_def
.
op
.
add
()
op_def
.
name
=
first_op
.
name
op_def
.
name
=
first_op
.
name
op_def
.
type
=
first_op
.
type
op_def
.
type
=
first_op
.
type
op_def
.
input
.
extend
([
input
.
name
for
input
in
first_op
.
inputs
])
op_def
.
input
.
extend
([
input
.
name
for
input
in
first_op
.
inputs
])
op_def
.
output
.
extend
([
output
.
name
for
output
in
first_op
.
outputs
])
op_def
.
output
.
extend
([
output
.
name
for
output
in
first_op
.
outputs
])
output_shapes
=
[]
for
output
in
first_op
.
outputs
:
output_shape
=
mace_pb2
.
OutputShape
()
output_shape
.
dims
.
extend
(
output
.
shape
.
as_list
())
output_shapes
.
append
(
output_shape
)
op_def
.
output_shape
.
extend
(
output_shapes
)
else
:
else
:
raise
Exception
(
'Unknown Op:
'
+
first_op
.
name
)
raise
Exception
(
'Unknown Op:
%s, type: %s'
%
(
first_op
.
name
,
first_op
.
type
)
)
pass
pass
for
i
in
range
(
resolved_count
):
for
i
in
range
(
resolved_count
):
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录