Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
项目经理老王
Mace
提交
997b06f7
Mace
项目概览
项目经理老王
/
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,发现更多精彩内容 >>
提交
997b06f7
编写于
12月 04, 2018
作者:
Y
yejianwu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix fold bn to conv, deconv and depthwise
上级
bfbe1a30
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
69 addition
and
19 deletion
+69
-19
mace/core/runtime/opencl/opencl_allocator.cc
mace/core/runtime/opencl/opencl_allocator.cc
+1
-1
mace/python/tools/converter_tool/base_converter.py
mace/python/tools/converter_tool/base_converter.py
+2
-2
mace/python/tools/converter_tool/transformer.py
mace/python/tools/converter_tool/transformer.py
+66
-16
未找到文件。
mace/core/runtime/opencl/opencl_allocator.cc
浏览文件 @
997b06f7
...
...
@@ -91,7 +91,7 @@ MaceStatus OpenCLAllocator::NewImage(const std::vector<size_t> &image_shape,
if
(
error
!=
CL_SUCCESS
)
{
LOG
(
WARNING
)
<<
"Allocate OpenCL image with shape: ["
<<
image_shape
[
0
]
<<
", "
<<
image_shape
[
1
]
<<
"] failed because of"
<<
"] failed because of
"
<<
OpenCLErrorToString
(
error
);
delete
cl_image
;
*
result
=
nullptr
;
...
...
mace/python/tools/converter_tool/base_converter.py
浏览文件 @
997b06f7
...
...
@@ -415,12 +415,12 @@ class ConverterOption(object):
TransformerRule
.
FOLD_RESHAPE
,
TransformerRule
.
TRANSFORM_MATMUL_TO_FC
,
TransformerRule
.
FOLD_BATCHNORM
,
TransformerRule
.
TRANSFORM_ADD_TO_BIASADD
,
TransformerRule
.
FOLD_BIASADD
,
TransformerRule
.
FOLD_CONV_AND_BN
,
TransformerRule
.
FOLD_DECONV_AND_BN
,
TransformerRule
.
FOLD_DEPTHWISE_CONV_AND_BN
,
TransformerRule
.
TRANSFORM_ADD_TO_BIASADD
,
TransformerRule
.
REARRANGE_BATCH_TO_SPACE
,
TransformerRule
.
FOLD_BIASADD
,
TransformerRule
.
FLATTEN_ATROUS_CONV
,
TransformerRule
.
FOLD_ACTIVATION
,
TransformerRule
.
FOLD_SQRDIFF_MEAN
,
...
...
mace/python/tools/converter_tool/transformer.py
浏览文件 @
997b06f7
...
...
@@ -57,6 +57,7 @@ class Transformer(base_converter.ConverterInterface):
TransformerRule
.
TRANSFORM_MATMUL_TO_FC
:
self
.
transform_matmul_to_fc
,
TransformerRule
.
FOLD_BATCHNORM
:
self
.
fold_batchnorm
,
TransformerRule
.
FOLD_BIASADD
:
self
.
fold_biasadd
,
TransformerRule
.
FOLD_CONV_AND_BN
:
self
.
fold_conv_and_bn
,
# data_format related
TransformerRule
.
FOLD_DECONV_AND_BN
:
...
...
@@ -67,7 +68,6 @@ class Transformer(base_converter.ConverterInterface):
self
.
transform_add_to_biasadd
,
TransformerRule
.
REARRANGE_BATCH_TO_SPACE
:
self
.
rearrange_batch_to_space
,
TransformerRule
.
FOLD_BIASADD
:
self
.
fold_biasadd
,
TransformerRule
.
FLATTEN_ATROUS_CONV
:
self
.
flatten_atrous_conv
,
TransformerRule
.
FOLD_ACTIVATION
:
self
.
fold_activation
,
TransformerRule
.
FOLD_SQRDIFF_MEAN
:
self
.
fold_squared_diff_mean
,
...
...
@@ -546,10 +546,14 @@ class Transformer(base_converter.ConverterInterface):
if
(
op
.
type
==
MaceOp
.
Conv2D
.
name
)
\
and
self
.
consumer_count
(
op
.
output
[
0
])
==
1
:
consumer_op
=
self
.
_consumers
[
op
.
output
[
0
]][
0
]
if
consumer_op
.
type
==
MaceOp
.
BatchNorm
.
name
:
input_len
=
len
(
op
.
input
)
if
consumer_op
.
type
==
MaceOp
.
BatchNorm
.
name
and
\
(
input_len
==
2
or
(
input_len
==
3
and
op
.
input
[
-
1
]
in
self
.
_consts
)):
print
(
"Fold conv and bn: %s(%s)"
%
(
op
.
name
,
op
.
type
))
filter
=
self
.
_consts
[
op
.
input
[
1
]]
scale
=
self
.
_consts
[
consumer_op
.
input
[
1
]]
offset
=
self
.
_consts
[
consumer_op
.
input
[
2
]]
idx
=
0
filter_format
=
self
.
filter_format
()
if
filter_format
==
FilterFormat
.
HWIO
:
...
...
@@ -570,12 +574,20 @@ class Transformer(base_converter.ConverterInterface):
mace_check
(
False
,
"filter format %s not supported"
%
filter_format
)
# change BN to BiasAdd
consumer_op
.
type
=
MaceOp
.
BiasAdd
.
name
del
consumer_op
.
input
[
1
]
if
len
(
op
.
input
)
==
3
:
conv_bias
=
self
.
_consts
[
op
.
input
[
2
]]
for
c
in
six
.
moves
.
range
(
conv_bias
.
dims
[
0
]):
conv_bias
.
float_data
[
c
]
*=
scale
.
float_data
[
c
]
conv_bias
.
float_data
[
c
]
+=
offset
.
float_data
[
c
]
net
.
tensors
.
remove
(
offset
)
else
:
op
.
input
.
extend
([
consumer_op
.
input
[
2
]])
# remove scale tensor
# remove bn
del
consumer_op
.
input
[:]
net
.
tensors
.
remove
(
scale
)
self
.
safe_remove_node
(
consumer_op
,
op
)
return
True
return
False
...
...
@@ -586,10 +598,21 @@ class Transformer(base_converter.ConverterInterface):
if
(
op
.
type
in
[
MaceOp
.
Deconv2D
.
name
,
MaceOp
.
DepthwiseDeconv2d
])
\
and
self
.
consumer_count
(
op
.
output
[
0
])
==
1
:
consumer_op
=
self
.
_consumers
[
op
.
output
[
0
]][
0
]
if
consumer_op
.
type
==
MaceOp
.
BatchNorm
.
name
:
framework
=
ConverterUtil
.
get_arg
(
op
,
MaceKeyword
.
mace_framework_type_str
).
i
input_len
=
len
(
op
.
input
)
if
consumer_op
.
type
==
MaceOp
.
BatchNorm
.
name
and
\
(
framework
==
FrameworkType
.
CAFFE
.
value
and
(
input_len
==
2
or
(
input_len
==
3
and
op
.
input
[
-
1
]
in
self
.
_consts
)))
or
\
(
framework
==
FrameworkType
.
TENSORFLOW
.
value
and
(
input_len
==
3
or
(
input_len
==
4
and
op
.
input
[
-
1
]
in
self
.
_consts
))):
print
(
"Fold deconv and bn: %s(%s)"
%
(
op
.
name
,
op
.
type
))
filter
=
self
.
_consts
[
op
.
input
[
1
]]
scale
=
self
.
_consts
[
consumer_op
.
input
[
1
]]
offset
=
self
.
_consts
[
consumer_op
.
input
[
2
]]
idx
=
0
filter_format
=
self
.
filter_format
()
# in deconv op O and I channel is switched
...
...
@@ -613,12 +636,27 @@ class Transformer(base_converter.ConverterInterface):
mace_check
(
False
,
"filter format %s not supported"
%
filter_format
)
# change BN to BiasAdd
consumer_op
.
type
=
MaceOp
.
BiasAdd
.
name
del
consumer_op
.
input
[
1
]
bias_dim
=
-
1
if
framework
==
FrameworkType
.
CAFFE
.
value
\
and
len
(
op
.
input
)
==
3
:
bias_dim
=
2
if
framework
==
FrameworkType
.
TENSORFLOW
.
value
\
and
len
(
op
.
input
)
==
4
:
bias_dim
=
3
if
bias_dim
!=
-
1
:
conv_bias
=
self
.
_consts
[
op
.
input
[
bias_dim
]]
for
c
in
six
.
moves
.
range
(
conv_bias
.
dims
[
0
]):
conv_bias
.
float_data
[
c
]
*=
scale
.
float_data
[
c
]
conv_bias
.
float_data
[
c
]
+=
offset
.
float_data
[
c
]
net
.
tensors
.
remove
(
offset
)
else
:
op
.
input
.
extend
([
consumer_op
.
input
[
2
]])
# remove scale tensor
del
consumer_op
.
input
[:]
net
.
tensors
.
remove
(
scale
)
self
.
safe_remove_node
(
consumer_op
,
op
)
return
True
return
False
...
...
@@ -629,11 +667,15 @@ class Transformer(base_converter.ConverterInterface):
if
op
.
type
==
MaceOp
.
DepthwiseConv2d
.
name
\
and
self
.
consumer_count
(
op
.
output
[
0
])
==
1
:
consumer_op
=
self
.
_consumers
[
op
.
output
[
0
]][
0
]
if
consumer_op
.
type
==
MaceOp
.
BatchNorm
.
name
:
input_len
=
len
(
op
.
input
)
if
consumer_op
.
type
==
MaceOp
.
BatchNorm
.
name
and
\
(
input_len
==
2
or
(
input_len
==
3
and
op
.
input
[
-
1
]
in
self
.
_consts
)):
print
(
"Fold depthwise conv and bn: %s(%s)"
%
(
op
.
name
,
op
.
type
))
filter
=
self
.
_consts
[
op
.
input
[
1
]]
scale
=
self
.
_consts
[
consumer_op
.
input
[
1
]]
offset
=
self
.
_consts
[
consumer_op
.
input
[
2
]]
idx
=
0
filter_format
=
self
.
filter_format
()
...
...
@@ -657,12 +699,20 @@ class Transformer(base_converter.ConverterInterface):
mace_check
(
False
,
"filter format %s not supported"
%
filter_format
)
# change BN to BiasAdd
consumer_op
.
type
=
MaceOp
.
BiasAdd
.
name
del
consumer_op
.
input
[
1
]
if
len
(
op
.
input
)
==
3
:
conv_bias
=
self
.
_consts
[
op
.
input
[
2
]]
for
c
in
six
.
moves
.
range
(
conv_bias
.
dims
[
0
]):
conv_bias
.
float_data
[
c
]
*=
scale
.
float_data
[
c
]
conv_bias
.
float_data
[
c
]
+=
offset
.
float_data
[
c
]
net
.
tensors
.
remove
(
offset
)
else
:
op
.
input
.
extend
([
consumer_op
.
input
[
2
]])
# remove scale tensor
# remove bn
del
consumer_op
.
input
[:]
net
.
tensors
.
remove
(
scale
)
self
.
safe_remove_node
(
consumer_op
,
op
)
return
True
return
False
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录