Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle-Lite
提交
95372548
P
Paddle-Lite
项目概览
PaddlePaddle
/
Paddle-Lite
通知
331
Star
4
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
271
列表
看板
标记
里程碑
合并请求
78
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle-Lite
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
271
Issue
271
列表
看板
标记
里程碑
合并请求
78
合并请求
78
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
95372548
编写于
10月 17, 2019
作者:
L
liu zhengxi
提交者:
GitHub
10月 17, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
enable batch_norm op and add its unit tests, test=develop (#2201)
上级
ad541652
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
18 addition
and
9 deletion
+18
-9
lite/kernels/x86/CMakeLists.txt
lite/kernels/x86/CMakeLists.txt
+2
-0
lite/kernels/x86/batch_norm_compute.h
lite/kernels/x86/batch_norm_compute.h
+11
-9
lite/kernels/x86/batch_norm_compute_test.cc
lite/kernels/x86/batch_norm_compute_test.cc
+5
-0
未找到文件。
lite/kernels/x86/CMakeLists.txt
浏览文件 @
95372548
...
...
@@ -34,6 +34,7 @@ add_kernel(shape_compute_x86 X86 basic SRCS shape_compute.cc DEPS ${lite_kernel_
add_kernel
(
sequence_pool_compute_x86 X86 basic SRCS sequence_pool_compute.cc DEPS
${
lite_kernel_deps
}
sequence_pooling
)
add_kernel
(
softmax_compute_x86 X86 basic SRCS softmax_compute.cc DEPS
${
lite_kernel_deps
}
softmax
)
add_kernel
(
elementwise_compute_x86 X86 basic SRCS elementwise_compute.cc DEPS
${
lite_kernel_deps
}
)
add_kernel
(
batch_norm_compute_x86 X86 basic SRCS batch_norm_compute.cc DEPS
${
lite_kernel_deps
}
)
if
(
NOT LITE_WITH_X86
)
return
()
...
...
@@ -49,6 +50,7 @@ lite_cc_test(test_reshape_compute_x86 SRCS reshape_compute_test.cc DEPS reshape_
lite_cc_test
(
test_concat_compute_x86 SRCS concat_compute_test.cc DEPS concat_compute_x86
)
lite_cc_test
(
test_sequence_pool_compute_x86 SRCS sequence_pool_compute_test.cc DEPS sequence_pool_compute_x86
)
lite_cc_test
(
test_shape_compute_x86 SRCS shape_compute_test.cc DEPS shape_compute_x86
)
lite_cc_test
(
test_batch_norm_compute_x86 SRCS batch_norm_compute_test.cc DEPS batch_norm_compute_x86
)
lite_cc_test
(
test_softmax_compute_x86 SRCS softmax_compute_test.cc DEPS softmax_compute_x86
)
lite_cc_test
(
test_elementwise_compute_x86 SRCS elementwise_compute_test.cc DEPS elementwise_compute_x86
)
lite_cc_test
(
test_relu_compute_x86 SRCS relu_compute_test.cc DEPS activation_compute_x86
)
...
...
lite/kernels/x86/batch_norm_compute.h
浏览文件 @
95372548
...
...
@@ -13,12 +13,14 @@
// limitations under the License.
#pragma once
#include <Eigen/Core>
#include <random>
#include <string>
#include "lite/core/kernel.h"
#include "lite/core/op_registry.h"
#include "paddle/fluid/framework/eigen.h"
#include "paddle/fluid/framework/operator.h"
#include "lite/core/types.h"
#include "lite/fluid/eigen.h"
#include "lite/operators/batch_norm_op.h"
namespace
paddle
{
namespace
lite
{
...
...
@@ -42,6 +44,7 @@ class BatchNormCompute : public KernelLite<TARGET(kX86), PRECISION(kFloat)> {
public:
using
param_t
=
operators
::
BatchNormParam
;
void
Run
()
override
{
// auto &context = ctx_->As<X86Context>();
auto
&
param
=
*
param_
.
get_mutable
<
operators
::
BatchNormParam
>
();
bool
global_stats
=
param
.
is_test
||
param
.
use_global_stats
;
...
...
@@ -55,12 +58,12 @@ class BatchNormCompute : public KernelLite<TARGET(kX86), PRECISION(kFloat)> {
const
int
sample_size
=
x
->
dims
().
production
()
/
N
/
C
;
// alloc memory
param
.
y
->
template
mutable_data
<
T
>();
param
.
y
->
mutable_data
<
T
>
();
if
(
!
param
.
is_test
)
{
param
.
mean_out
->
template
mutable_data
<
T
>();
param
.
variance_out
->
template
mutable_data
<
T
>();
param
.
saved_mean
->
template
mutable_data
<
T
>();
param
.
saved_variance
->
template
mutable_data
<
T
>();
param
.
mean_out
->
mutable_data
<
T
>
();
param
.
variance_out
->
mutable_data
<
T
>
();
param
.
saved_mean
->
mutable_data
<
T
>
();
param
.
saved_variance
->
mutable_data
<
T
>
();
}
if
(
!
global_stats
)
{
// saved_xx is use just in this batch of data
...
...
@@ -79,8 +82,7 @@ class BatchNormCompute : public KernelLite<TARGET(kX86), PRECISION(kFloat)> {
if
((
N
*
sample_size
)
==
1
)
{
LOG
(
WARNING
)
<<
"Only 1 element in normalization dimension, "
<<
"we skip the batch norm calculation, let y = x."
;
framework
::
TensorCopy
(
x
->
raw_tensor
(),
platform
::
CPUPlace
(),
&
param
.
y
->
raw_tensor
());
param
.
y
->
CopyDataFrom
(
*
x
);
return
;
}
...
...
lite/kernels/x86/batch_norm_compute_test.cc
浏览文件 @
95372548
...
...
@@ -15,6 +15,8 @@
#include "lite/kernels/x86/batch_norm_compute.h"
#include <gtest/gtest.h>
#include <iostream>
#include <memory>
#include <utility>
#include <vector>
#include "lite/core/op_registry.h"
...
...
@@ -116,6 +118,9 @@ TEST(batch_norm_x86, run_test) {
param
.
saved_mean
=
&
saved_mean
;
param
.
saved_variance
=
&
saved_variance
;
std
::
unique_ptr
<
KernelContext
>
ctx
(
new
KernelContext
);
ctx
->
As
<
X86Context
>
();
batch_norm
.
SetContext
(
std
::
move
(
ctx
));
batch_norm
.
SetParam
(
param
);
batch_norm
.
Run
();
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录