Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
冰之2023
Mace
提交
e2f43f41
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,发现更多精彩内容 >>
提交
e2f43f41
编写于
9月 08, 2017
作者:
L
liuqi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix batch norm bugs and Add batch norm unit test and benchmark.
上级
8f246d81
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
160 addition
and
14 deletion
+160
-14
.gitignore
.gitignore
+1
-0
mace/kernels/benchmark/batch_norm_benchmark.cc
mace/kernels/benchmark/batch_norm_benchmark.cc
+76
-0
mace/kernels/test/batch_norm_neon_test.cc
mace/kernels/test/batch_norm_neon_test.cc
+73
-0
mace/ops/batch_norm.h
mace/ops/batch_norm.h
+6
-6
mace/ops/batch_norm_test.cc
mace/ops/batch_norm_test.cc
+4
-8
未找到文件。
.gitignore
浏览文件 @
e2f43f41
bazel-*
.idea/
cmake-build-debug/
*.sh
mace/kernels/benchmark/batch_norm_benchmark.cc
0 → 100644
浏览文件 @
e2f43f41
//
// Copyright (c) 2017 XiaoMi All rights reserved.
//
#include "mace/core/testing/test_benchmark.h"
#include "mace/kernels/batch_norm.h"
namespace
mace
{
template
<
DeviceType
D
,
typename
T
>
static
void
BatchNorm
(
int
iters
,
int
batch
,
int
channels
,
int
height
,
int
width
)
{
std
::
random_device
rd
;
std
::
mt19937
gen
(
rd
());
std
::
normal_distribution
<
float
>
nd
(
0
,
1
);
TIndex
input_size
=
batch
*
channels
*
height
*
width
;
std
::
vector
<
T
>
input
(
input_size
,
0.0
);
std
::
vector
<
T
>
scale
(
channels
,
0.0
);
std
::
vector
<
T
>
offset
(
channels
,
0.0
);
std
::
vector
<
T
>
mean
(
channels
,
0.0
);
std
::
vector
<
T
>
var
(
channels
,
0.0
);
for
(
int
i
=
0
;
i
<
input_size
;
++
i
)
{
input
[
i
]
=
nd
(
gen
);
}
for
(
int
i
=
0
;
i
<
channels
;
++
i
)
{
scale
[
i
]
=
nd
(
gen
);
offset
[
i
]
=
nd
(
gen
);
mean
[
i
]
=
nd
(
gen
);
var
[
i
]
=
std
::
abs
(
nd
(
gen
));
}
// declare output
std
::
unique_ptr
<
T
[]
>
output
(
new
T
[
input_size
]);
auto
functor
=
kernels
::
BatchNormFunctor
<
D
,
T
>
(
1e-5
);
while
(
iters
--
)
{
functor
(
input
.
data
(),
scale
.
data
(),
offset
.
data
(),
mean
.
data
(),
var
.
data
(),
batch
,
channels
,
height
*
width
,
output
.
get
());
}
}
#define BM_BATCH_NORM_MACRO(N, C, H, W, TYPE, DEVICE) \
static void BM_BATCH_NORM_##N##_##C##_##H##_##W##_##TYPE##_##DEVICE( \
int iters) { \
const int64 tot = static_cast<int64>(iters) * N * C * H * W; \
mace::testing::ItemsProcessed(tot); \
mace::testing::BytesProcessed(tot * (sizeof(TYPE)));\
BatchNorm<DEVICE, TYPE>(iters, N, C, H, W); \
} \
BENCHMARK(BM_BATCH_NORM_##N##_##C##_##H##_##W##_##TYPE##_##DEVICE)
#define BM_BATCH_NORM(N, C, H, W, TYPE) \
BM_BATCH_NORM_MACRO(N, C, H, W, TYPE, CPU); \
BM_BATCH_NORM_MACRO(N, C, H, W, TYPE, NEON);
BM_BATCH_NORM
(
1
,
1
,
128
,
128
,
float
);
BM_BATCH_NORM
(
1
,
1
,
512
,
512
,
float
);
BM_BATCH_NORM
(
1
,
1
,
1024
,
1024
,
float
);
BM_BATCH_NORM
(
16
,
1
,
256
,
256
,
float
);
BM_BATCH_NORM
(
32
,
1
,
256
,
256
,
float
);
BM_BATCH_NORM
(
64
,
1
,
256
,
256
,
float
);
BM_BATCH_NORM
(
1
,
3
,
128
,
128
,
float
);
BM_BATCH_NORM
(
1
,
3
,
512
,
512
,
float
);
BM_BATCH_NORM
(
1
,
3
,
1024
,
1024
,
float
);
BM_BATCH_NORM
(
16
,
3
,
256
,
256
,
float
);
BM_BATCH_NORM
(
32
,
3
,
256
,
256
,
float
);
BM_BATCH_NORM
(
64
,
3
,
256
,
256
,
float
);
}
// namespace mace
\ No newline at end of file
mace/kernels/test/batch_norm_neon_test.cc
0 → 100644
浏览文件 @
e2f43f41
//
// Copyright (c) 2017 XiaoMi All rights reserved.
//
#include <random>
#include "gtest/gtest.h"
#include "mace/kernels/batch_norm.h"
namespace
mace
{
TEST
(
BatchNormNeonTest
,
Simple
)
{
std
::
random_device
rd
;
std
::
mt19937
gen
(
rd
());
std
::
normal_distribution
<
float
>
nd
(
0
,
1
);
srand
(
time
(
NULL
));
// generate random input
TIndex
batch
=
1
+
rand
()
%
128
;
TIndex
channels
=
3
;
TIndex
height
=
2
+
rand
()
%
100
;
TIndex
width
=
2
+
rand
()
%
100
;
TIndex
input_size
=
batch
*
channels
*
height
*
width
;
std
::
vector
<
float
>
input
(
input_size
,
0.0
);
std
::
vector
<
float
>
scale
(
channels
,
0.0
);
std
::
vector
<
float
>
offset
(
channels
,
0.0
);
std
::
vector
<
float
>
mean
(
channels
,
0.0
);
std
::
vector
<
float
>
var
(
channels
,
0.0
);
for
(
int
i
=
0
;
i
<
input_size
;
++
i
)
{
input
[
i
]
=
nd
(
gen
);
}
for
(
int
i
=
0
;
i
<
channels
;
++
i
)
{
scale
[
i
]
=
nd
(
gen
);
offset
[
i
]
=
nd
(
gen
);
mean
[
i
]
=
nd
(
gen
);
var
[
i
]
=
std
::
abs
(
nd
(
gen
));
}
// declare output
std
::
unique_ptr
<
float
[]
>
output
(
new
float
[
input_size
]);
std
::
unique_ptr
<
float
[]
>
output_neon
(
new
float
[
input_size
]);
kernels
::
BatchNormFunctor
<
DeviceType
::
CPU
,
float
>
(
1e-5
)(
input
.
data
(),
scale
.
data
(),
offset
.
data
(),
mean
.
data
(),
var
.
data
(),
batch
,
channels
,
height
*
width
,
output
.
get
()
);
kernels
::
BatchNormFunctor
<
DeviceType
::
NEON
,
float
>
(
1e-5
)(
input
.
data
(),
scale
.
data
(),
offset
.
data
(),
mean
.
data
(),
var
.
data
(),
batch
,
channels
,
height
*
width
,
output_neon
.
get
()
);
for
(
TIndex
i
=
0
;
i
<
input_size
;
++
i
)
{
EXPECT_FLOAT_EQ
(
output
[
i
],
output_neon
[
i
]);
}
}
}
// namespace mace
\ No newline at end of file
mace/ops/batch_norm.h
浏览文件 @
e2f43f41
...
...
@@ -37,12 +37,12 @@ class BatchNormOp : public Operator<D, T> {
const
index_t
channel
=
input
->
dim
(
1
);
const
index_t
sample_size
=
input
->
dim
(
2
)
*
input
->
dim
(
3
);
const
float
*
input_ptr
=
input
->
data
<
float
>
();
const
float
*
scale_ptr
=
scale
->
data
<
float
>
();
const
float
*
offset_ptr
=
offset
->
data
<
float
>
();
const
float
*
mean_ptr
=
mean
->
data
<
float
>
();
const
float
*
var_ptr
=
var
->
data
<
float
>
();
float
*
output_ptr
=
output
->
mutable_data
<
float
>
();
const
T
*
input_ptr
=
input
->
data
<
T
>
();
const
T
*
scale_ptr
=
scale
->
data
<
T
>
();
const
T
*
offset_ptr
=
offset
->
data
<
T
>
();
const
T
*
mean_ptr
=
mean
->
data
<
T
>
();
const
T
*
var_ptr
=
var
->
data
<
T
>
();
T
*
output_ptr
=
output
->
mutable_data
<
T
>
();
functor_
(
input_ptr
,
scale_ptr
,
offset_ptr
,
mean_ptr
,
var_ptr
,
n
,
channel
,
sample_size
,
...
...
mace/ops/batch_norm_test.cc
浏览文件 @
e2f43f41
...
...
@@ -23,14 +23,10 @@ TEST_F(BatchNormOpTest, Simple) {
// Add input data
AddInputFromArray
<
float
>
(
"Input"
,
{
1
,
1
,
6
,
2
},
{
5
,
5
,
7
,
7
,
9
,
9
,
11
,
11
,
13
,
13
,
15
,
15
});
AddInputFromArray
<
float
>
(
"Scale"
,
{
2
},
{
4.0
f
,
4.0
f
});
AddInputFromArray
<
float
>
(
"Offset"
,
{
2
},
{
2.0
,
2.0
});
AddInputFromArray
<
float
>
(
"Mean"
,
{
2
},
{
10
,
10
});
AddInputFromArray
<
float
>
(
"Var"
,
{
2
},
{
11.67
f
,
11.67
f
});
AddInputFromArray
<
float
>
(
"Scale"
,
{
1
},
{
4.0
f
});
AddInputFromArray
<
float
>
(
"Offset"
,
{
1
},
{
2.0
});
AddInputFromArray
<
float
>
(
"Mean"
,
{
1
},
{
10
});
AddInputFromArray
<
float
>
(
"Var"
,
{
1
},
{
11.67
f
});
// Run
RunOp
();
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录