Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
冰之2023
Mace
提交
875ed7a5
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,体验更适合开发者的 AI 搜索 >>
提交
875ed7a5
编写于
3月 28, 2018
作者:
L
liuqi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Caffe converter support depthwise convolution.
上级
a1c6ba92
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
25 addition
and
12 deletion
+25
-12
mace/python/tools/caffe_converter_lib.py
mace/python/tools/caffe_converter_lib.py
+23
-11
mace/python/tools/tf_converter_lib.py
mace/python/tools/tf_converter_lib.py
+2
-1
未找到文件。
mace/python/tools/caffe_converter_lib.py
浏览文件 @
875ed7a5
...
@@ -333,8 +333,18 @@ class CaffeConverter(object):
...
@@ -333,8 +333,18 @@ class CaffeConverter(object):
return
pad
,
stride
,
kernel
return
pad
,
stride
,
kernel
def
convert_conv2d
(
self
,
op
):
def
convert_conv2d
(
self
,
op
):
op_def
=
self
.
CommonConvert
(
op
,
'Conv2D'
)
param
=
op
.
layer
.
convolution_param
param
=
op
.
layer
.
convolution_param
is_depthwise
=
False
if
param
.
HasField
(
'group'
):
if
param
.
group
==
op
.
data
[
0
].
shape
[
0
]
and
op
.
data
[
0
].
shape
[
1
]
==
1
:
is_depthwise
=
True
else
:
raise
Exception
(
"Mace do not support group convolution yet"
)
if
is_depthwise
:
op_def
=
self
.
CommonConvert
(
op
,
'DepthwiseConv2d'
)
else
:
op_def
=
self
.
CommonConvert
(
op
,
'Conv2D'
)
# Add filter
# Add filter
weight_tensor_name
=
op
.
name
+
'_weight:0'
weight_tensor_name
=
op
.
name
+
'_weight:0'
...
@@ -342,7 +352,7 @@ class CaffeConverter(object):
...
@@ -342,7 +352,7 @@ class CaffeConverter(object):
self
.
add_tensor
(
weight_tensor_name
,
weight_data
)
self
.
add_tensor
(
weight_tensor_name
,
weight_data
)
if
self
.
device
==
'gpu'
:
if
self
.
device
==
'gpu'
:
buffer_type
=
"CONV2D_FILTER"
buffer_type
=
"
DW_CONV2D_FILTER"
if
is_depthwise
else
"
CONV2D_FILTER"
output_name
=
self
.
add_buffer_to_image
(
weight_tensor_name
,
buffer_type
)
output_name
=
self
.
add_buffer_to_image
(
weight_tensor_name
,
buffer_type
)
op_def
.
input
.
extend
([
output_name
])
op_def
.
input
.
extend
([
output_name
])
else
:
else
:
...
@@ -381,6 +391,7 @@ class CaffeConverter(object):
...
@@ -381,6 +391,7 @@ class CaffeConverter(object):
if
len
(
self
.
ops_map
[
final_op
.
name
].
children
)
==
1
\
if
len
(
self
.
ops_map
[
final_op
.
name
].
children
)
==
1
\
and
self
.
ops_map
[
final_op
.
name
].
children
[
0
].
type
in
activation_name_map
:
and
self
.
ops_map
[
final_op
.
name
].
children
[
0
].
type
in
activation_name_map
:
activation_op
=
self
.
ops_map
[
final_op
.
name
].
children
[
0
]
activation_op
=
self
.
ops_map
[
final_op
.
name
].
children
[
0
]
if
not
is_depthwise
:
op_def
.
type
=
"FusedConv2D"
op_def
.
type
=
"FusedConv2D"
fused_act_arg
=
op_def
.
arg
.
add
()
fused_act_arg
=
op_def
.
arg
.
add
()
fused_act_arg
.
name
=
'activation'
fused_act_arg
.
name
=
'activation'
...
@@ -412,7 +423,7 @@ class CaffeConverter(object):
...
@@ -412,7 +423,7 @@ class CaffeConverter(object):
width
=
output_shape
[
0
]
*
((
output_shape
[
1
]
+
1
)
/
2
)
*
((
output_shape
[
2
]
+
1
)
/
2
)
width
=
output_shape
[
0
]
*
((
output_shape
[
1
]
+
1
)
/
2
)
*
((
output_shape
[
2
]
+
1
)
/
2
)
return
self
.
winograd
and
self
.
device
==
'gpu'
and
\
return
self
.
winograd
and
self
.
device
==
'gpu'
and
\
filter_shape
[
0
]
==
3
and
(
filter_shape
[
0
]
==
filter_shape
[
1
])
and
\
filter_shape
[
0
]
==
3
and
(
filter_shape
[
0
]
==
filter_shape
[
1
])
and
\
dilations
[
0
]
==
1
and
(
dilations
[
0
]
==
dilations
[
1
])
and
\
dilations
[
0
]
==
1
and
(
dilations
[
0
]
==
dilations
[
1
])
and
\
(
strides
[
0
]
==
1
)
and
(
strides
[
0
]
==
strides
[
1
])
and
\
(
strides
[
0
]
==
1
)
and
(
strides
[
0
]
==
strides
[
1
])
and
\
(
16
*
filter_shape
[
2
]
<
OPENCL_IMAGE_MAX_SIZE
)
and
\
(
16
*
filter_shape
[
2
]
<
OPENCL_IMAGE_MAX_SIZE
)
and
\
(
16
*
filter_shape
[
3
]
<
OPENCL_IMAGE_MAX_SIZE
)
and
\
(
16
*
filter_shape
[
3
]
<
OPENCL_IMAGE_MAX_SIZE
)
and
\
...
@@ -966,3 +977,4 @@ def convert_to_mace_pb(model_file, weight_file, input_node_str, input_shape_str,
...
@@ -966,3 +977,4 @@ def convert_to_mace_pb(model_file, weight_file, input_node_str, input_shape_str,
print
"Memory optimization done."
print
"Memory optimization done."
return
net_def
return
net_def
mace/python/tools/tf_converter_lib.py
浏览文件 @
875ed7a5
...
@@ -362,6 +362,7 @@ class TFConverter(object):
...
@@ -362,6 +362,7 @@ class TFConverter(object):
if
len
(
self
.
tf_graph
.
get
(
final_op
.
name
,
[]))
==
1
\
if
len
(
self
.
tf_graph
.
get
(
final_op
.
name
,
[]))
==
1
\
and
self
.
tf_graph
[
final_op
.
name
][
0
].
type
in
activation_name_map
:
and
self
.
tf_graph
[
final_op
.
name
][
0
].
type
in
activation_name_map
:
activation_op
=
self
.
tf_graph
[
final_op
.
name
][
0
]
activation_op
=
self
.
tf_graph
[
final_op
.
name
][
0
]
if
op_def
.
type
==
"Conv2D"
:
op_def
.
type
=
"FusedConv2D"
op_def
.
type
=
"FusedConv2D"
fused_act_arg
=
op_def
.
arg
.
add
()
fused_act_arg
=
op_def
.
arg
.
add
()
fused_act_arg
.
name
=
'activation'
fused_act_arg
.
name
=
'activation'
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录