Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
野马c
Mace
提交
297f5771
Mace
项目概览
野马c
/
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,发现更多精彩内容 >>
提交
297f5771
编写于
9月 19, 2017
作者:
L
liuqi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Change the type of batch_norm's attribute epsilon to tensor.
上级
5b21653b
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
19 addition
and
12 deletion
+19
-12
mace/kernels/batch_norm.h
mace/kernels/batch_norm.h
+3
-5
mace/kernels/neon/batch_norm_neon.cc
mace/kernels/neon/batch_norm_neon.cc
+2
-1
mace/kernels/neon/max_pooling_neon_3x3.cc
mace/kernels/neon/max_pooling_neon_3x3.cc
+0
-1
mace/ops/batch_norm.h
mace/ops/batch_norm.h
+6
-3
mace/ops/batch_norm_benchmark.cc
mace/ops/batch_norm_benchmark.cc
+2
-0
mace/ops/batch_norm_test.cc
mace/ops/batch_norm_test.cc
+6
-2
未找到文件。
mace/kernels/batch_norm.h
浏览文件 @
297f5771
...
...
@@ -13,16 +13,13 @@ namespace kernels {
template
<
DeviceType
D
,
typename
T
>
struct
BatchNormFunctor
{
float
variance_epsilon_
;
BatchNormFunctor
(
const
float
variance_epsilon
)
:
variance_epsilon_
(
variance_epsilon
)
{}
void
operator
()(
const
T
*
input
,
const
T
*
scale
,
const
T
*
offset
,
const
T
*
mean
,
const
T
*
var
,
const
float
variance_epsilon
,
const
index_t
n
,
const
index_t
channel
,
const
index_t
sample_size
,
...
...
@@ -37,7 +34,7 @@ struct BatchNormFunctor {
// Y = new_scale * X + new_offset;
T
new_scale
,
new_offset
;
for
(
index_t
c
=
0
;
c
<
channel
;
++
c
)
{
new_scale
=
scale
[
c
]
/
std
::
sqrt
(
var
[
c
]
+
this
->
variance_epsilon_
);
new_scale
=
scale
[
c
]
/
std
::
sqrt
(
var
[
c
]
+
variance_epsilon
);
new_offset
=
offset
[
c
]
-
mean
[
c
]
*
new_scale
;
index_t
pos
=
c
*
sample_size
;
...
...
@@ -60,6 +57,7 @@ void BatchNormFunctor<DeviceType::NEON, float>::operator()(
const
float
*
offset
,
const
float
*
mean
,
const
float
*
var
,
const
float
variance_epsilon
,
const
index_t
n
,
const
index_t
channel
,
const
index_t
sample_size
,
...
...
mace/kernels/neon/batch_norm_neon.cc
浏览文件 @
297f5771
...
...
@@ -15,6 +15,7 @@ void BatchNormFunctor<DeviceType::NEON, float>::operator()(
const
float
*
offset
,
const
float
*
mean
,
const
float
*
var
,
const
float
variance_epsilon
,
const
index_t
n
,
const
index_t
channel
,
const
index_t
sample_size
,
...
...
@@ -31,7 +32,7 @@ void BatchNormFunctor<DeviceType::NEON, float>::operator()(
index_t
count
=
sample_size
>>
2
;
index_t
remain_count
=
sample_size
-
(
count
<<
2
);
for
(
index_t
c
=
0
;
c
<
channel
;
++
c
)
{
new_scale
=
scale
[
c
]
/
std
::
sqrt
(
var
[
c
]
+
this
->
variance_epsilon_
);
new_scale
=
scale
[
c
]
/
std
::
sqrt
(
var
[
c
]
+
variance_epsilon
);
new_offset
=
offset
[
c
]
-
mean
[
c
]
*
new_scale
;
index_t
pos
=
c
*
sample_size
;
...
...
mace/kernels/neon/max_pooling_neon_3x3.cc
浏览文件 @
297f5771
...
...
@@ -3,7 +3,6 @@
//
#include <arm_neon.h>
#include <float.h>
#include <limits>
#include "mace/core/common.h"
...
...
mace/ops/batch_norm.h
浏览文件 @
297f5771
...
...
@@ -15,8 +15,7 @@ class BatchNormOp : public Operator<D, T> {
public:
BatchNormOp
(
const
OperatorDef
&
operator_def
,
Workspace
*
ws
)
:
Operator
<
D
,
T
>
(
operator_def
,
ws
),
functor_
(
OperatorBase
::
GetSingleArgument
<
float
>
(
"variance_epsilon"
,
1e-4
))
{}
functor_
()
{}
bool
Run
()
override
{
const
Tensor
*
input
=
this
->
Input
(
0
);
...
...
@@ -24,6 +23,7 @@ class BatchNormOp : public Operator<D, T> {
const
Tensor
*
offset
=
this
->
Input
(
2
);
const
Tensor
*
mean
=
this
->
Input
(
3
);
const
Tensor
*
var
=
this
->
Input
(
4
);
const
Tensor
*
epsilon
=
this
->
Input
(
5
);
MACE_CHECK
(
input
->
dim_size
()
==
4
,
"input must be 4-dimensional. "
,
input
->
dim_size
());
...
...
@@ -35,6 +35,8 @@ class BatchNormOp : public Operator<D, T> {
mean
->
dim_size
());
MACE_CHECK
(
var
->
dim_size
()
==
1
,
"var must be 1-dimensional. "
,
var
->
dim_size
());
MACE_CHECK
(
epsilon
->
dim_size
()
==
0
,
"epsilon must be 0-dimensional. "
,
epsilon
->
dim_size
());
Tensor
*
output
=
this
->
Output
(
0
);
output
->
ResizeLike
(
input
);
...
...
@@ -48,9 +50,10 @@ class BatchNormOp : public Operator<D, T> {
const
T
*
offset_ptr
=
offset
->
data
<
T
>
();
const
T
*
mean_ptr
=
mean
->
data
<
T
>
();
const
T
*
var_ptr
=
var
->
data
<
T
>
();
const
T
*
epsilon_ptr
=
epsilon
->
data
<
T
>
();
T
*
output_ptr
=
output
->
mutable_data
<
T
>
();
functor_
(
input_ptr
,
scale_ptr
,
offset_ptr
,
mean_ptr
,
var_ptr
,
n
,
channel
,
functor_
(
input_ptr
,
scale_ptr
,
offset_ptr
,
mean_ptr
,
var_ptr
,
*
epsilon_ptr
,
n
,
channel
,
sample_size
,
output_ptr
);
return
true
;
}
...
...
mace/ops/batch_norm_benchmark.cc
浏览文件 @
297f5771
...
...
@@ -19,6 +19,7 @@ static void BatchNorm(
.
Input
(
"Offset"
)
.
Input
(
"Mean"
)
.
Input
(
"Var"
)
.
Input
(
"Epsilon"
)
.
Output
(
"Output"
)
.
Finalize
(
net
.
operator_def
());
...
...
@@ -28,6 +29,7 @@ static void BatchNorm(
net
.
AddRandomInput
<
T
>
(
"Offset"
,
{
channels
});
net
.
AddRandomInput
<
T
>
(
"Mean"
,
{
channels
});
net
.
AddRandomInput
<
T
>
(
"Var"
,
{
channels
},
true
);
net
.
AddInputFromArray
<
float
>
(
"Epsilon"
,
{},
{
1e-3
});
// Warm-up
for
(
int
i
=
0
;
i
<
5
;
++
i
)
{
...
...
mace/ops/batch_norm_test.cc
浏览文件 @
297f5771
...
...
@@ -18,6 +18,7 @@ TEST_F(BatchNormOpTest, SimpleCPU) {
.
Input
(
"Offset"
)
.
Input
(
"Mean"
)
.
Input
(
"Var"
)
.
Input
(
"Epsilon"
)
.
Output
(
"Output"
)
.
Finalize
(
net
.
operator_def
());
...
...
@@ -28,6 +29,7 @@ TEST_F(BatchNormOpTest, SimpleCPU) {
net
.
AddInputFromArray
<
float
>
(
"Offset"
,
{
1
},
{
2.0
});
net
.
AddInputFromArray
<
float
>
(
"Mean"
,
{
1
},
{
10
});
net
.
AddInputFromArray
<
float
>
(
"Var"
,
{
1
},
{
11.67
f
});
net
.
AddInputFromArray
<
float
>
(
"Epsilon"
,
{},
{
1e-3
});
// Run
net
.
RunOp
();
...
...
@@ -46,8 +48,8 @@ TEST_F(BatchNormOpTest, SimpleNeon) {
// generate random input
index_t
batch
=
1
+
rand
()
%
10
;
index_t
channels
=
3
+
rand
()
%
50
;
index_t
height
=
10
+
rand
()
%
50
;
index_t
width
=
1
0
+
rand
()
%
50
;
index_t
height
=
10
3
;
index_t
width
=
1
13
;
// Construct graph
auto
&
net
=
test_net
();
OpDefBuilder
(
"BatchNorm"
,
"BatchNormTest"
)
...
...
@@ -56,6 +58,7 @@ TEST_F(BatchNormOpTest, SimpleNeon) {
.
Input
(
"Offset"
)
.
Input
(
"Mean"
)
.
Input
(
"Var"
)
.
Input
(
"Epsilon"
)
.
Output
(
"Output"
)
.
Finalize
(
net
.
operator_def
());
...
...
@@ -65,6 +68,7 @@ TEST_F(BatchNormOpTest, SimpleNeon) {
net
.
AddRandomInput
<
float
>
(
"Offset"
,
{
channels
});
net
.
AddRandomInput
<
float
>
(
"Mean"
,
{
channels
});
net
.
AddRandomInput
<
float
>
(
"Var"
,
{
channels
},
true
);
net
.
AddInputFromArray
<
float
>
(
"Epsilon"
,
{},
{
1e-3
});
// run cpu
net
.
RunOp
();
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录