Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
as350144
Mace
提交
2cb646dc
Mace
项目概览
as350144
/
Mace
与 Fork 源项目一致
Fork自
Xiaomi / Mace
通知
2
Star
1
Fork
1
代码
文件
提交
分支
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,发现更多精彩内容 >>
提交
2cb646dc
编写于
9月 19, 2017
作者:
L
liuqi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Update the padding calculation logic of depthwise conv2d.
上级
de985851
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
36 addition
and
33 deletion
+36
-33
mace/kernels/depthwise_conv2d.h
mace/kernels/depthwise_conv2d.h
+18
-10
mace/kernels/neon/depthwise_conv_neon.cc
mace/kernels/neon/depthwise_conv_neon.cc
+3
-5
mace/ops/conv_pool_2d_base.h
mace/ops/conv_pool_2d_base.h
+11
-14
mace/ops/depthwise_conv2d.h
mace/ops/depthwise_conv2d.h
+4
-4
未找到文件。
mace/kernels/depthwise_conv2d.h
浏览文件 @
2cb646dc
...
...
@@ -15,11 +15,21 @@ namespace kernels {
template
<
DeviceType
D
,
typename
T
>
class
DepthwiseConv2dFunctor
{
public:
DepthwiseConv2dFunctor
(
const
index_t
*
input_shape
,
const
index_t
*
filter_shape
,
const
int
*
strides
,
const
Padding
padding
,
const
int
*
dilations
)
:
strides_
(
strides
),
paddings_
(
2
,
0
),
dilations_
(
dilations
)
{
CalPaddingSize
(
input_shape
,
filter_shape
,
dilations_
,
strides_
,
padding
,
paddings_
.
data
());
}
DepthwiseConv2dFunctor
(
const
int
*
strides
,
Padding
paddings
,
const
int
*
dilations
)
:
const
std
::
vector
<
int
>&
paddings
,
const
int
*
dilations
)
:
strides_
(
strides
),
padding_
(
paddings
),
padding
s
_
(
paddings
),
dilations_
(
dilations
)
{}
void
operator
()(
const
T
*
input
,
// NCHW
...
...
@@ -53,13 +63,11 @@ class DepthwiseConv2dFunctor {
MACE_CHECK
(
batch
==
input_batch
,
"Input/Output batch size mismatch"
);
vector
<
int
>
paddings_size
(
2
,
0
);
CalPaddingSize
(
input_shape
,
filter_shape
,
dilations_
,
strides_
,
padding_
,
paddings_size
.
data
());
// The left-upper most offset of the padded input
int
padded_h_start
=
0
-
paddings_
size
[
0
]
/
2
;
int
padded_w_start
=
0
-
paddings_
size
[
1
]
/
2
;
index_t
padded_h_stop
=
input_height
+
paddings_
size
[
0
]
-
paddings_size
[
0
]
/
2
;
index_t
padded_w_stop
=
input_width
+
paddings_
size
[
1
]
-
paddings_size
[
1
]
/
2
;
int
padded_h_start
=
0
-
paddings_
[
0
]
/
2
;
int
padded_w_start
=
0
-
paddings_
[
1
]
/
2
;
index_t
padded_h_stop
=
input_height
+
paddings_
[
0
]
-
paddings_
[
0
]
/
2
;
index_t
padded_w_stop
=
input_width
+
paddings_
[
1
]
-
paddings_
[
1
]
/
2
;
index_t
kernel_size
=
filter_shape
[
1
]
*
kernel_h
*
kernel_w
;
index_t
multiplier
=
channels
/
input_channels
;
...
...
@@ -103,7 +111,7 @@ class DepthwiseConv2dFunctor {
}
private:
const
int
*
strides_
;
// [stride_h, stride_w]
Padding
padding_
;
std
::
vector
<
int
>
paddings_
;
// [padding_h, padding_w]
const
int
*
dilations_
;
// [dilation_h, dilation_w]
};
...
...
mace/kernels/neon/depthwise_conv_neon.cc
浏览文件 @
2cb646dc
...
...
@@ -57,17 +57,15 @@ void DepthwiseConv2dFunctor<DeviceType::NEON, float>::operator()(const float* in
<<
"filter"
<<
kernel_h
<<
"x"
<<
kernel_w
<<
","
<<
" stride "
<<
strides_
[
0
]
<<
"x"
<<
strides_
[
1
]
<<
" is not implemented yet, using slow version"
;
DepthwiseConv2dFunctor
<
DeviceType
::
CPU
,
float
>
(
strides_
,
padding_
,
dilations_
)(
DepthwiseConv2dFunctor
<
DeviceType
::
CPU
,
float
>
(
strides_
,
padding
s
_
,
dilations_
)(
input
,
input_shape
,
filter
,
filter_shape
,
bias
,
output
,
output_shape
);
return
;
}
// Keep this alive during kernel execution
vector
<
int
>
paddings_size
(
2
,
0
);
CalPaddingSize
(
input_shape
,
filter_shape
,
dilations_
,
strides_
,
padding_
,
paddings_size
.
data
());
Tensor
padded_input
;
if
(
paddings_
size
[
0
]
>
0
||
paddings_size
[
1
]
>
0
)
{
ConstructInputWithPadding
(
input
,
input_shape
,
paddings_
size
.
data
(),
&
padded_input
);
if
(
paddings_
[
0
]
>
0
||
paddings_
[
1
]
>
0
)
{
ConstructInputWithPadding
(
input
,
input_shape
,
paddings_
.
data
(),
&
padded_input
);
input
=
padded_input
.
data
<
float
>
();
input_shape
=
padded_input
.
shape
().
data
();
}
...
...
mace/ops/conv_pool_2d_base.h
浏览文件 @
2cb646dc
...
...
@@ -22,15 +22,12 @@ class ConvPool2dOpBase : public Operator<D, T> {
void
CalOutputSize
(
const
index_t
*
input_shape
,
// NCHW
const
index_t
*
filter_shape
,
// OIHW
const
int
*
dilations
,
const
int
*
strides
,
Padding
padding
,
index_t
*
output_shape
)
{
MACE_CHECK
(
dilations
[
0
]
>
0
&&
dilations
[
1
]
>
0
,
MACE_CHECK
(
dilations
_
[
0
]
>
0
&&
dilations_
[
1
]
>
0
,
"Invalid dilations, must >= 1"
);
MACE_CHECK
((
dilations
[
0
]
==
1
||
strides
[
0
]
==
1
)
&&
(
dilations
[
1
]
==
1
||
strides
[
1
]
==
1
),
MACE_CHECK
((
dilations
_
[
0
]
==
1
||
strides_
[
0
]
==
1
)
&&
(
dilations
_
[
1
]
==
1
||
strides_
[
1
]
==
1
),
"If dilations > 1, strides should be 1"
);
MACE_CHECK_NOTNULL
(
output_shape
);
/*
...
...
@@ -42,21 +39,21 @@ class ConvPool2dOpBase : public Operator<D, T> {
index_t
output_height
,
output_width
;
switch
(
padding
)
{
switch
(
padding
_
)
{
case
VALID
:
output_height
=
(
input_shape
[
2
]
-
(
filter_shape
[
2
]
-
1
)
*
dilations
[
0
]
-
1
)
/
strides
[
0
]
+
1
;
output_width
=
(
input_shape
[
3
]
-
(
filter_shape
[
3
]
-
1
)
*
dilations
[
1
]
-
1
)
/
strides
[
1
]
+
1
;
output_height
=
(
input_shape
[
2
]
-
(
filter_shape
[
2
]
-
1
)
*
dilations
_
[
0
]
-
1
)
/
strides_
[
0
]
+
1
;
output_width
=
(
input_shape
[
3
]
-
(
filter_shape
[
3
]
-
1
)
*
dilations
_
[
1
]
-
1
)
/
strides_
[
1
]
+
1
;
break
;
case
SAME
:
output_height
=
(
input_shape
[
2
]
-
1
)
/
strides
[
0
]
+
1
;
output_width
=
(
input_shape
[
3
]
-
1
)
/
strides
[
1
]
+
1
;
output_height
=
(
input_shape
[
2
]
-
1
)
/
strides
_
[
0
]
+
1
;
output_width
=
(
input_shape
[
3
]
-
1
)
/
strides
_
[
1
]
+
1
;
break
;
case
FULL
:
output_height
=
(
input_shape
[
2
]
+
(
filter_shape
[
2
]
-
1
)
*
dilations
[
0
]
-
1
)
/
strides
[
0
]
+
1
;
output_width
=
(
input_shape
[
3
]
+
(
filter_shape
[
3
]
-
1
)
*
dilations
[
1
]
-
1
)
/
strides
[
1
]
+
1
;
output_height
=
(
input_shape
[
2
]
+
(
filter_shape
[
2
]
-
1
)
*
dilations
_
[
0
]
-
1
)
/
strides_
[
0
]
+
1
;
output_width
=
(
input_shape
[
3
]
+
(
filter_shape
[
3
]
-
1
)
*
dilations
_
[
1
]
-
1
)
/
strides_
[
1
]
+
1
;
break
;
default:
MACE_CHECK
(
false
,
"Unsupported padding type: "
,
padding
);
MACE_CHECK
(
false
,
"Unsupported padding type: "
,
padding
_
);
}
output_shape
[
0
]
=
input_shape
[
0
];
...
...
mace/ops/depthwise_conv2d.h
浏览文件 @
2cb646dc
...
...
@@ -19,7 +19,9 @@ class DepthwiseConv2dOp : public ConvPool2dOpBase<D, T> {
public:
DepthwiseConv2dOp
(
const
OperatorDef
&
op_def
,
Workspace
*
ws
)
:
ConvPool2dOpBase
<
D
,
T
>
(
op_def
,
ws
),
functor_
(
this
->
strides_
.
data
(),
this
->
padding_
,
this
->
dilations_
.
data
()){};
functor_
(
this
->
Input
(
INPUT
)
->
shape
().
data
(),
this
->
Input
(
FILTER
)
->
shape
().
data
(),
this
->
strides_
.
data
(),
this
->
padding_
,
this
->
dilations_
.
data
()){};
bool
Run
()
override
{
const
Tensor
*
input
=
this
->
Input
(
INPUT
);
...
...
@@ -32,9 +34,7 @@ class DepthwiseConv2dOp : public ConvPool2dOpBase<D, T> {
filter_shape
[
0
]
*=
filter_shape
[
1
];
filter_shape
[
1
]
=
1
;
std
::
vector
<
index_t
>
output_shape
(
4
);
this
->
CalOutputSize
(
input
->
shape
().
data
(),
filter_shape
.
data
(),
this
->
dilations_
.
data
(),
this
->
strides_
.
data
(),
this
->
padding_
,
output_shape
.
data
());
this
->
CalOutputSize
(
input
->
shape
().
data
(),
filter_shape
.
data
(),
output_shape
.
data
());
output
->
Resize
(
output_shape
);
functor_
(
input
->
data
<
T
>
(),
input
->
shape
().
data
(),
filter
->
data
<
T
>
(),
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录