Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
闹闹不闹!
Mace
提交
8217088f
Mace
项目概览
闹闹不闹!
/
Mace
与 Fork 源项目一致
Fork自
Xiaomi / Mace
通知
1
Star
1
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,发现更多精彩内容 >>
提交
8217088f
编写于
12月 25, 2018
作者:
李
李滨
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'shuffle' into 'master'
Support TF shufflenet v2 See merge request !925
上级
6f7f230e
0b257940
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
49 addition
and
3 deletion
+49
-3
mace/ops/split.cc
mace/ops/split.cc
+2
-2
mace/python/tools/converter_tool/base_converter.py
mace/python/tools/converter_tool/base_converter.py
+2
-0
mace/python/tools/converter_tool/transformer.py
mace/python/tools/converter_tool/transformer.py
+45
-1
未找到文件。
mace/ops/split.cc
浏览文件 @
8217088f
...
...
@@ -75,8 +75,8 @@ class SplitOp<DeviceType::CPU, T> : public Operation {
#pragma omp parallel for
for
(
int
outer_idx
=
0
;
outer_idx
<
outer_size
;
++
outer_idx
)
{
int
input_idx
=
outer_idx
*
input_channels
*
inner_size
;
int
output_idx
=
outer_idx
*
output_channels
*
inner_size
;
in
dex_
t
input_idx
=
outer_idx
*
input_channels
*
inner_size
;
in
dex_
t
output_idx
=
outer_idx
*
output_channels
*
inner_size
;
for
(
size_t
i
=
0
;
i
<
outputs_count
;
++
i
)
{
if
(
DataTypeCanUseMemcpy
(
DataTypeToEnum
<
T
>::
v
()))
{
memcpy
(
output_ptrs
[
i
]
+
output_idx
,
input_ptr
+
input_idx
,
...
...
mace/python/tools/converter_tool/base_converter.py
浏览文件 @
8217088f
...
...
@@ -257,6 +257,7 @@ class TransformerRule(Enum):
FOLD_EMBEDDING_LOOKUP
=
35
TRANSPOSE_CAFFE_RESHAPE_AND_FLATTEN
=
36
FOLD_FC_RESHAPE
=
37
TRANSFORM_CHANNEL_SHUFFLE
=
38
class
ConverterInterface
(
object
):
...
...
@@ -463,6 +464,7 @@ class ConverterOption(object):
TransformerRule
.
TRANSFORM_GLOBAL_CONV_TO_FC
,
TransformerRule
.
RESHAPE_FC_WEIGHT
,
TransformerRule
.
FOLD_FC_RESHAPE
,
TransformerRule
.
TRANSFORM_CHANNEL_SHUFFLE
,
# Model data format related transformation
TransformerRule
.
TRANSPOSE_FILTERS
,
TransformerRule
.
TRANSPOSE_DATA_FORMAT
,
...
...
mace/python/tools/converter_tool/transformer.py
浏览文件 @
8217088f
...
...
@@ -100,6 +100,8 @@ class Transformer(base_converter.ConverterInterface):
self
.
check_quantize_info
,
TransformerRule
.
TRANSPOSE_CAFFE_RESHAPE_AND_FLATTEN
:
self
.
transform_caffe_reshape_and_flatten
,
TransformerRule
.
TRANSFORM_CHANNEL_SHUFFLE
:
self
.
transform_channel_shuffle
,
}
self
.
_option
=
option
...
...
@@ -231,7 +233,7 @@ class Transformer(base_converter.ConverterInterface):
# that the op is identity op and its input is a tensor.
mace_check
(
len
(
op
.
output
)
==
1
and
len
(
op
.
input
)
==
1
,
"cannot remove op that w/o replace op specified"
" and input/output length > 1"
+
str
(
op
))
" and input/output length > 1
\n
"
+
str
(
op
))
for
consumer_op
in
self
.
_consumers
.
get
(
op
.
output
[
0
],
[]):
self
.
replace
(
consumer_op
.
input
,
op
.
output
[
0
],
op
.
input
[
0
])
...
...
@@ -1789,3 +1791,45 @@ class Transformer(base_converter.ConverterInterface):
self
.
safe_remove_node
(
consumer
,
None
)
return
True
return
False
def
transform_channel_shuffle
(
self
):
net
=
self
.
_model
for
op
in
net
.
op
:
if
op
.
type
==
MaceOp
.
Transpose
.
name
and
\
len
(
op
.
output_shape
[
0
].
dims
)
==
5
:
perm
=
ConverterUtil
.
get_arg
(
op
,
MaceKeyword
.
mace_dims_str
).
ints
if
[
0
,
1
,
2
,
4
,
3
]
==
list
(
perm
):
# Remove the following Reshape op
reshape_op
=
self
.
_consumers
.
get
(
op
.
output
[
0
],
None
)
if
(
reshape_op
and
len
(
reshape_op
)
==
1
and
reshape_op
[
0
].
type
==
MaceOp
.
Reshape
.
name
and
len
(
reshape_op
[
0
].
output_shape
[
0
].
dims
)
==
4
):
print
(
"Transform channel shuffle"
)
output_shape
=
reshape_op
[
0
].
output_shape
[
0
].
dims
self
.
safe_remove_node
(
reshape_op
[
0
],
op
,
remove_input_tensor
=
True
)
else
:
return
False
# Change Transpose op to ChannelShuffle
op
.
type
=
MaceOp
.
ChannelShuffle
.
name
del
op
.
arg
[:]
group_arg
=
op
.
arg
.
add
()
group_arg
.
name
=
MaceKeyword
.
mace_group_str
group_arg
.
i
=
op
.
output_shape
[
0
].
dims
[
4
]
op
.
output_shape
[
0
].
dims
[:]
=
output_shape
# Remove previous Reshape op
producer_op
=
self
.
_producer
.
get
(
op
.
input
[
0
],
None
)
if
producer_op
:
if
producer_op
.
type
==
MaceOp
.
Reshape
.
name
:
self
.
safe_remove_node
(
producer_op
,
None
)
elif
producer_op
.
type
==
MaceOp
.
Stack
.
name
:
print
(
"Change channel shuffle stack to concat"
)
# Change previous Stack op to Concat if any
producer_op
.
type
=
MaceOp
.
Concat
.
name
producer_op
.
output_shape
[
0
].
dims
[:]
=
output_shape
return
True
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录