Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
慢慢CG
Mace
提交
dbb49292
Mace
项目概览
慢慢CG
/
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看板
提交
dbb49292
编写于
9月 12, 2017
作者:
L
Liangliang He
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'conv2d-neon' into 'master'
Change filter order to OIHW and Fix some warning. See merge request !30
上级
df37e07c
12c719a1
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
32 addition
and
47 deletion
+32
-47
mace/core/operator.h
mace/core/operator.h
+1
-1
mace/core/tensor.h
mace/core/tensor.h
+1
-2
mace/kernels/conv_2d.h
mace/kernels/conv_2d.h
+11
-15
mace/kernels/pooling.h
mace/kernels/pooling.h
+1
-3
mace/ops/conv_2d_test.cc
mace/ops/conv_2d_test.cc
+7
-12
mace/ops/conv_pool_2d_base.h
mace/ops/conv_pool_2d_base.h
+6
-6
mace/ops/pooling.cc
mace/ops/pooling.cc
+0
-2
mace/ops/pooling.h
mace/ops/pooling.h
+5
-5
mace/ops/pooling_test.cc
mace/ops/pooling_test.cc
+0
-1
未找到文件。
mace/core/operator.h
浏览文件 @
dbb49292
...
@@ -44,7 +44,7 @@ class OperatorBase {
...
@@ -44,7 +44,7 @@ class OperatorBase {
*
operator_def_
,
name
,
default_value
);
*
operator_def_
,
name
,
default_value
);
}
}
inline
const
Tensor
*
Input
(
index_
t
idx
)
{
inline
const
Tensor
*
Input
(
unsigned
in
t
idx
)
{
MACE_CHECK
(
idx
<
inputs_
.
size
());
MACE_CHECK
(
idx
<
inputs_
.
size
());
return
inputs_
[
idx
];
return
inputs_
[
idx
];
}
}
...
...
mace/core/tensor.h
浏览文件 @
dbb49292
...
@@ -68,9 +68,8 @@ class Tensor {
...
@@ -68,9 +68,8 @@ class Tensor {
inline
index_t
dim_size
()
const
{
return
shape_
.
size
();
}
inline
index_t
dim_size
()
const
{
return
shape_
.
size
();
}
inline
index_t
dim
(
index_
t
index
)
const
{
inline
index_t
dim
(
unsigned
in
t
index
)
const
{
MACE_CHECK
(
index
<
shape_
.
size
(),
"Exceeding ndim limit"
);
MACE_CHECK
(
index
<
shape_
.
size
(),
"Exceeding ndim limit"
);
MACE_CHECK
(
index
>=
0
,
"Cannot have negative dimension index"
);
return
shape_
[
index
];
return
shape_
[
index
];
}
}
...
...
mace/kernels/conv_2d.h
浏览文件 @
dbb49292
...
@@ -22,7 +22,7 @@ class Conv2dFunctor {
...
@@ -22,7 +22,7 @@ class Conv2dFunctor {
void
operator
()(
const
T
*
input
,
// NCHW
void
operator
()(
const
T
*
input
,
// NCHW
const
index_t
*
input_shape
,
const
index_t
*
input_shape
,
const
T
*
filter
,
//
kernel_h, kernel_w, c_in, c_out
const
T
*
filter
,
//
c_out, c_in, kernel_h, kernel_w
const
index_t
*
filter_shape
,
const
index_t
*
filter_shape
,
const
T
*
bias
,
// c_out
const
T
*
bias
,
// c_out
T
*
output
,
// NCHW
T
*
output
,
// NCHW
...
@@ -39,8 +39,8 @@ class Conv2dFunctor {
...
@@ -39,8 +39,8 @@ class Conv2dFunctor {
index_t
input_height
=
input_shape
[
2
];
index_t
input_height
=
input_shape
[
2
];
index_t
input_width
=
input_shape
[
3
];
index_t
input_width
=
input_shape
[
3
];
in
t
kernel_h
=
filter_shape
[
0
];
in
dex_t
kernel_h
=
filter_shape
[
2
];
in
t
kernel_w
=
filter_shape
[
1
];
in
dex_t
kernel_w
=
filter_shape
[
3
];
int
stride_h
=
strides_
[
0
];
int
stride_h
=
strides_
[
0
];
int
stride_w
=
strides_
[
1
];
int
stride_w
=
strides_
[
1
];
...
@@ -53,10 +53,12 @@ class Conv2dFunctor {
...
@@ -53,10 +53,12 @@ class Conv2dFunctor {
// The left-upper most offset of the padded input
// The left-upper most offset of the padded input
int
padded_h_start
=
0
-
paddings_
[
0
]
/
2
;
int
padded_h_start
=
0
-
paddings_
[
0
]
/
2
;
int
padded_w_start
=
0
-
paddings_
[
1
]
/
2
;
int
padded_w_start
=
0
-
paddings_
[
1
]
/
2
;
int
padded_h_stop
=
input_height
+
paddings_
[
0
]
-
paddings_
[
0
]
/
2
;
in
dex_
t
padded_h_stop
=
input_height
+
paddings_
[
0
]
-
paddings_
[
0
]
/
2
;
int
padded_w_stop
=
input_width
+
paddings_
[
1
]
-
paddings_
[
1
]
/
2
;
in
dex_
t
padded_w_stop
=
input_width
+
paddings_
[
1
]
-
paddings_
[
1
]
/
2
;
#pragma omp parallel for collpse(2)
index_t
kernel_size
=
input_channels
*
kernel_h
*
kernel_w
;
#pragma omp parallel for collapse(2)
for
(
int
n
=
0
;
n
<
batch
;
++
n
)
{
for
(
int
n
=
0
;
n
<
batch
;
++
n
)
{
for
(
int
c
=
0
;
c
<
channels
;
++
c
)
{
for
(
int
c
=
0
;
c
<
channels
;
++
c
)
{
for
(
int
h
=
0
;
h
<
height
;
++
h
)
{
for
(
int
h
=
0
;
h
<
height
;
++
h
)
{
...
@@ -65,17 +67,10 @@ class Conv2dFunctor {
...
@@ -65,17 +67,10 @@ class Conv2dFunctor {
c
*
height
*
width
+
c
*
height
*
width
+
h
*
width
+
w
;
h
*
width
+
w
;
T
sum
=
0
;
T
sum
=
0
;
const
T
*
filter_ptr
=
filter
+
c
*
kernel_size
;
for
(
int
inc
=
0
;
inc
<
input_channels
;
++
inc
)
{
for
(
int
inc
=
0
;
inc
<
input_channels
;
++
inc
)
{
for
(
int
kh
=
0
;
kh
<
kernel_h
;
++
kh
)
{
for
(
int
kh
=
0
;
kh
<
kernel_h
;
++
kh
)
{
for
(
int
kw
=
0
;
kw
<
kernel_w
;
++
kw
)
{
for
(
int
kw
=
0
;
kw
<
kernel_w
;
++
kw
)
{
/*
* TODO The tensorflow filter order is HWCiCo.
* We should consider other order for different
* implementaion to optimize memory access.
*/
int
filter_offset
=
kh
*
kernel_w
*
input_channels
*
channels
+
kw
*
input_channels
*
channels
+
inc
*
channels
+
c
;
int
inh
=
padded_h_start
+
h
*
stride_h
+
dilation_h
*
kh
;
int
inh
=
padded_h_start
+
h
*
stride_h
+
dilation_h
*
kh
;
int
inw
=
padded_w_start
+
w
*
stride_w
+
dilation_w
*
kw
;
int
inw
=
padded_w_start
+
w
*
stride_w
+
dilation_w
*
kw
;
...
@@ -94,8 +89,9 @@ class Conv2dFunctor {
...
@@ -94,8 +89,9 @@ class Conv2dFunctor {
n
*
input_channels
*
input_height
*
input_width
+
n
*
input_channels
*
input_height
*
input_width
+
inc
*
input_height
*
input_width
+
inc
*
input_height
*
input_width
+
inh
*
input_width
+
inw
;
inh
*
input_width
+
inw
;
sum
+=
input
[
input_offset
]
*
filter
[
filter_offset
]
;
sum
+=
input
[
input_offset
]
*
*
filter_ptr
;
}
}
++
filter_ptr
;
}
}
}
}
output
[
offset
]
=
sum
+
bias
[
c
];
output
[
offset
]
=
sum
+
bias
[
c
];
...
...
mace/kernels/pooling.h
浏览文件 @
dbb49292
...
@@ -56,10 +56,8 @@ public:
...
@@ -56,10 +56,8 @@ public:
// The left-upper most offset of the padded input
// The left-upper most offset of the padded input
int
padded_h_start
=
0
-
paddings_
[
0
]
/
2
;
int
padded_h_start
=
0
-
paddings_
[
0
]
/
2
;
int
padded_w_start
=
0
-
paddings_
[
1
]
/
2
;
int
padded_w_start
=
0
-
paddings_
[
1
]
/
2
;
int
padded_h_stop
=
input_height
+
paddings_
[
0
]
-
paddings_
[
0
]
/
2
;
int
padded_w_stop
=
input_width
+
paddings_
[
1
]
-
paddings_
[
0
]
/
2
;
#pragma omp parallel for collpse(2)
#pragma omp parallel for coll
a
pse(2)
for
(
int
n
=
0
;
n
<
batch
;
++
n
)
{
for
(
int
n
=
0
;
n
<
batch
;
++
n
)
{
for
(
int
c
=
0
;
c
<
channels
;
++
c
)
{
for
(
int
c
=
0
;
c
<
channels
;
++
c
)
{
index_t
out_offset
=
n
*
channels
*
height
*
width
+
index_t
out_offset
=
n
*
channels
*
height
*
width
+
...
...
mace/ops/conv_2d_test.cc
浏览文件 @
dbb49292
...
@@ -32,7 +32,7 @@ TEST_F(Conv2dOpTest, Simple_VALID) {
...
@@ -32,7 +32,7 @@ TEST_F(Conv2dOpTest, Simple_VALID) {
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
});
1
,
1
,
1
});
AddInputFromArray
<
float
>
(
"Filter"
,
{
3
,
3
,
2
,
1
},
AddInputFromArray
<
float
>
(
"Filter"
,
{
1
,
2
,
3
,
3
},
{
1.0
f
,
1.0
f
,
1.0
f
,
1.0
f
,
1.0
f
,
1.0
f
,
{
1.0
f
,
1.0
f
,
1.0
f
,
1.0
f
,
1.0
f
,
1.0
f
,
1.0
f
,
1.0
f
,
1.0
f
,
1.0
f
,
1.0
f
,
1.0
f
,
1.0
f
,
1.0
f
,
1.0
f
,
1.0
f
,
1.0
f
,
1.0
f
,
1.0
f
,
1.0
f
,
1.0
f
,
1.0
f
,
1.0
f
,
1.0
f
});
1.0
f
,
1.0
f
,
1.0
f
,
1.0
f
,
1.0
f
,
1.0
f
});
...
@@ -69,7 +69,7 @@ TEST_F(Conv2dOpTest, Simple_SAME) {
...
@@ -69,7 +69,7 @@ TEST_F(Conv2dOpTest, Simple_SAME) {
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
});
1
,
1
,
1
});
AddInputFromArray
<
float
>
(
"Filter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.5
f
,
0.5
f
,
0.5
f
,
0.5
f
,
0.5
f
});
1.0
f
,
0.5
f
,
1.0
f
,
0.5
f
,
1.0
f
,
0.5
f
,
1.0
f
,
0.5
f
,
1.0
f
,
0.5
f
,
1.0
f
,
0.5
f
,
1.0
f
,
0.5
f
,
1.0
f
,
0.5
f
,
1.0
f
,
0.5
f
,
1.0
f
,
0.5
f
});
AddInputFromArray
<
float
>
(
"Bias"
,
{
2
},
{
0.1
f
,
0.2
f
});
AddInputFromArray
<
float
>
(
"Bias"
,
{
2
},
{
0.1
f
,
0.2
f
});
// Run
// Run
...
...
mace/ops/conv_pool_2d_base.h
浏览文件 @
dbb49292
...
@@ -27,7 +27,7 @@ class ConvPool2dOpBase : public Operator<D, T> {
...
@@ -27,7 +27,7 @@ class ConvPool2dOpBase : public Operator<D, T> {
dilations_
(
OperatorBase
::
GetRepeatedArgument
<
int
>
(
"dilations"
))
{}
dilations_
(
OperatorBase
::
GetRepeatedArgument
<
int
>
(
"dilations"
))
{}
void
CalcPaddingAndOutputSize
(
const
index_t
*
input_shape
,
// NCHW
void
CalcPaddingAndOutputSize
(
const
index_t
*
input_shape
,
// NCHW
const
index_t
*
filter_shape
,
//
HWIO
const
index_t
*
filter_shape
,
//
OIHW
std
::
vector
<
index_t
>*
output_shape
,
std
::
vector
<
index_t
>*
output_shape
,
std
::
vector
<
int
>*
padding_size
)
{
std
::
vector
<
int
>*
padding_size
)
{
MACE_CHECK
(
dilations_
[
0
]
>
0
&&
dilations_
[
1
]
>
0
,
MACE_CHECK
(
dilations_
[
0
]
>
0
&&
dilations_
[
1
]
>
0
,
...
@@ -44,12 +44,12 @@ class ConvPool2dOpBase : public Operator<D, T> {
...
@@ -44,12 +44,12 @@ class ConvPool2dOpBase : public Operator<D, T> {
*
padding_size
=
{
0
,
0
};
*
padding_size
=
{
0
,
0
};
index_t
output_height
,
output_width
;
index_t
output_height
,
output_width
;
index_t
kernel_height
=
filter_shape
[
0
];
index_t
kernel_height
=
filter_shape
[
2
];
index_t
kernel_width
=
filter_shape
[
1
];
index_t
kernel_width
=
filter_shape
[
3
];
index_t
output_channels
=
filter_shape
[
3
];
index_t
output_channels
=
filter_shape
[
0
];
int
k_extent_height
=
(
kernel_height
-
1
)
*
dilations_
[
0
]
+
1
;
in
dex_
t
k_extent_height
=
(
kernel_height
-
1
)
*
dilations_
[
0
]
+
1
;
int
k_extent_width
=
(
kernel_width
-
1
)
*
dilations_
[
1
]
+
1
;
in
dex_
t
k_extent_width
=
(
kernel_width
-
1
)
*
dilations_
[
1
]
+
1
;
switch
(
padding_
)
{
switch
(
padding_
)
{
case
VALID
:
case
VALID
:
...
...
mace/ops/pooling.cc
浏览文件 @
dbb49292
...
@@ -4,8 +4,6 @@
...
@@ -4,8 +4,6 @@
#include "mace/ops/pooling.h"
#include "mace/ops/pooling.h"
#include "mace/proto/mace.pb.h"
#include "mace/kernels/pooling.h"
namespace
mace
{
namespace
mace
{
...
...
mace/ops/pooling.h
浏览文件 @
dbb49292
...
@@ -29,10 +29,10 @@ public:
...
@@ -29,10 +29,10 @@ public:
std
::
vector
<
index_t
>
output_shape
;
std
::
vector
<
index_t
>
output_shape
;
std
::
vector
<
int
>
paddings
;
std
::
vector
<
int
>
paddings
;
std
::
vector
<
index_t
>
filter_shape
=
std
::
vector
<
index_t
>
(
4
);
std
::
vector
<
index_t
>
filter_shape
=
std
::
vector
<
index_t
>
(
4
);
filter_shape
[
0
]
=
kernels_
[
0
];
filter_shape
[
0
]
=
in_shape
[
1
];
filter_shape
[
1
]
=
kernels_
[
1
];
filter_shape
[
1
]
=
in_shape
[
0
];
filter_shape
[
2
]
=
in_shape
[
0
];
filter_shape
[
2
]
=
kernels_
[
0
];
filter_shape
[
3
]
=
in_shape
[
1
];
filter_shape
[
3
]
=
kernels_
[
1
];
this
->
CalcPaddingAndOutputSize
(
in_shape
.
data
(),
filter_shape
.
data
(),
this
->
CalcPaddingAndOutputSize
(
in_shape
.
data
(),
filter_shape
.
data
(),
&
output_shape
,
&
paddings
);
&
output_shape
,
&
paddings
);
output
->
Resize
(
output_shape
);
output
->
Resize
(
output_shape
);
...
@@ -50,8 +50,8 @@ public:
...
@@ -50,8 +50,8 @@ public:
};
};
protected:
protected:
PoolingType
pooling_type_
;
std
::
vector
<
int
>
kernels_
;
std
::
vector
<
int
>
kernels_
;
PoolingType
pooling_type_
;
OP_INPUT_TAGS
(
INPUT
);
OP_INPUT_TAGS
(
INPUT
);
OP_OUTPUT_TAGS
(
OUTPUT
);
OP_OUTPUT_TAGS
(
OUTPUT
);
...
...
mace/ops/pooling_test.cc
浏览文件 @
dbb49292
...
@@ -5,7 +5,6 @@
...
@@ -5,7 +5,6 @@
#include "gtest/gtest.h"
#include "gtest/gtest.h"
#include "mace/core/operator.h"
#include "mace/core/operator.h"
#include "mace/core/net.h"
#include "mace/ops/ops_test_util.h"
#include "mace/ops/ops_test_util.h"
#include "mace/ops/conv_pool_2d_base.h"
#include "mace/ops/conv_pool_2d_base.h"
#include "mace/kernels/pooling.h"
#include "mace/kernels/pooling.h"
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录