Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
机器未来
Paddle
提交
873ee9ab
P
Paddle
项目概览
机器未来
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
873ee9ab
编写于
10月 25, 2017
作者:
L
Luo Tao
提交者:
zchen0211
10月 31, 2017
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add test_Expand and simply the gserver/tests/CMakeLists
上级
8013328e
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
174 addition
and
116 deletion
+174
-116
paddle/gserver/tests/CMakeLists.txt
paddle/gserver/tests/CMakeLists.txt
+49
-116
paddle/gserver/tests/test_Expand.cpp
paddle/gserver/tests/test_Expand.cpp
+125
-0
未找到文件。
paddle/gserver/tests/CMakeLists.txt
浏览文件 @
873ee9ab
# gserver pacakge unittests
if
(
NOT MOBILE_INFERENCE
)
################### test_ProtoDataProvider ############
add_unittest_without_exec
(
test_ProtoDataProvider
test_ProtoDataProvider.cpp
)
# test_ProtoDataProvider will mkdir as same name,
# so if WORKING_DIRECTORY is default directory, then
# mkdir will get error.
add_test
(
NAME test_ProtoDataProvider
COMMAND
${
CMAKE_CURRENT_BINARY_DIR
}
/test_ProtoDataProvider
WORKING_DIRECTORY
${
PADDLE_SOURCE_DIR
}
/paddle
)
endif
()
add_simple_unittest
(
test_LinearChainCRF
)
add_simple_unittest
(
test_MultinomialSampler
)
add_simple_unittest
(
test_RecurrentLayer
)
################# test_LayerGrad #######################
add_unittest_without_exec
(
test_LayerGrad
test_LayerGrad.cpp
LayerGradUtil.cpp
)
add_test
(
NAME test_LayerGrad
COMMAND test_LayerGrad
)
function
(
gserver_test TARGET
)
add_unittest_without_exec
(
${
TARGET
}
${
TARGET
}
.cpp
LayerGradUtil.cpp
)
add_test
(
NAME
${
TARGET
}
COMMAND
${
TARGET
}
)
endfunction
()
gserver_test
(
test_LayerGrad
)
gserver_test
(
test_CRFLayerGrad
)
gserver_test
(
test_CrossEntropyOverBeamGrad
)
gserver_test
(
test_SeqSliceLayerGrad
)
gserver_test
(
test_ActivationGrad
)
gserver_test
(
test_ConvTrans
)
gserver_test
(
test_PriorBox
)
gserver_test
(
test_DetectionOutput
)
gserver_test
(
test_ConvUnify
)
gserver_test
(
test_BatchNorm
)
gserver_test
(
test_KmaxSeqScore
)
gserver_test
(
test_Expand
)
########## test_Mkldnn layers and activations ##########
if
(
WITH_MKLDNN
)
...
...
@@ -32,89 +37,6 @@ if(WITH_MKLDNN)
WORKING_DIRECTORY
${
PADDLE_SOURCE_DIR
}
/paddle
)
endif
()
################ test_CRFLayerGrad ####################
add_unittest_without_exec
(
test_CRFLayerGrad
test_CRFLayerGrad.cpp
LayerGradUtil.cpp
)
add_test
(
NAME test_CRFLayerGrad
COMMAND test_CRFLayerGrad
)
################ test_CrossEntropyOverBeam ####################
add_unittest_without_exec
(
test_CrossEntropyOverBeam
test_CrossEntropyOverBeamGrad.cpp
LayerGradUtil.cpp
)
add_test
(
NAME test_CrossEntropyOverBeam
COMMAND test_CrossEntropyOverBeam
)
################ test_SeqSliceLayerGrad ####################
add_unittest_without_exec
(
test_SeqSliceLayerGrad
test_SeqSliceLayerGrad.cpp
LayerGradUtil.cpp
)
add_test
(
NAME test_SeqSliceLayerGrad
COMMAND test_SeqSliceLayerGrad
)
add_unittest_without_exec
(
test_ActivationGrad
test_ActivationGrad.cpp
LayerGradUtil.cpp
)
add_test
(
NAME test_ActivationGrad
COMMAND test_ActivationGrad
)
################# test_ConvTrans #######################
add_unittest_without_exec
(
test_ConvTrans
test_ConvTrans.cpp
LayerGradUtil.cpp
)
add_test
(
NAME test_ConvTrans
COMMAND test_ConvTrans
)
################# test_PriorBox #######################
add_unittest_without_exec
(
test_PriorBox
test_PriorBox.cpp
LayerGradUtil.cpp
)
add_test
(
NAME test_PriorBox
COMMAND test_PriorBox
)
################# test_DetectionOutput #######################
add_unittest_without_exec
(
test_DetectionOutput
test_DetectionOutput.cpp
LayerGradUtil.cpp
)
add_test
(
NAME test_DetectionOutput
COMMAND test_DetectionOutput
)
################# test_ConvUnify #######################
add_unittest_without_exec
(
test_ConvUnify
test_ConvUnify.cpp
LayerGradUtil.cpp
)
add_test
(
NAME test_ConvUnify
COMMAND test_ConvUnify
)
################# test_BatchNorm #######################
add_unittest_without_exec
(
test_BatchNorm
test_BatchNorm.cpp
LayerGradUtil.cpp
)
add_test
(
NAME test_BatchNorm
COMMAND test_BatchNorm
)
################# test_KmaxSeqScore #######################
add_unittest_without_exec
(
test_KmaxSeqScore
test_KmaxSeqScore.cpp
LayerGradUtil.cpp
)
add_test
(
NAME test_KmaxSeqScore
COMMAND test_KmaxSeqScore
)
if
(
NOT MOBILE_INFERENCE
)
################## test_Evaluator #######################
add_unittest
(
test_Evaluator
test_Evaluator.cpp
)
endif
()
################ test_LinearChainCRF ####################
add_simple_unittest
(
test_LinearChainCRF
)
############## test_MultinomialSampler ###################
add_simple_unittest
(
test_MultinomialSampler
)
############## test_PyDataProvider ########################
if
(
WITH_PYTHON
)
add_unittest_without_exec
(
test_PyDataProvider
...
...
@@ -125,9 +47,6 @@ if(WITH_PYTHON)
WORKING_DIRECTORY
${
PADDLE_SOURCE_DIR
}
/paddle
)
endif
()
############### test_RecurrentLayer #######################
add_simple_unittest
(
test_RecurrentLayer
)
############### test_WarpCTCLayer #######################
if
(
NOT WITH_DOUBLE
)
add_unittest_without_exec
(
test_WarpCTCLayer
...
...
@@ -139,19 +58,33 @@ if(NOT WITH_DOUBLE)
endif
()
if
(
NOT MOBILE_INFERENCE
)
############### test_RecurrentGradientMachine ###############
# TODO(yuyang18): There is some bug in test_RecurrentGradientMachine
# I will fix it.
add_unittest_without_exec
(
test_RecurrentGradientMachine
test_RecurrentGradientMachine.cpp
)
add_test
(
NAME test_RecurrentGradientMachine
COMMAND .set_python_path.sh -d
${
PADDLE_SOURCE_DIR
}
/python:
${
PADDLE_SOURCE_DIR
}
/paddle/gserver/tests
${
CMAKE_CURRENT_BINARY_DIR
}
/test_RecurrentGradientMachine
WORKING_DIRECTORY
${
PADDLE_SOURCE_DIR
}
/paddle
)
endif
()
################### test_ProtoDataProvider ############
add_unittest_without_exec
(
test_ProtoDataProvider
test_ProtoDataProvider.cpp
)
if
(
NOT MOBILE_INFERENCE
)
# test_ProtoDataProvider will mkdir as same name,
# so if WORKING_DIRECTORY is default directory, then
# mkdir will get error.
add_test
(
NAME test_ProtoDataProvider
COMMAND
${
CMAKE_CURRENT_BINARY_DIR
}
/test_ProtoDataProvider
WORKING_DIRECTORY
${
PADDLE_SOURCE_DIR
}
/paddle
)
################## test_Evaluator #######################
add_unittest
(
test_Evaluator
test_Evaluator.cpp
)
############### test_RecurrentGradientMachine ###############
# TODO(yuyang18): There is some bug in test_RecurrentGradientMachine
# I will fix it.
add_unittest_without_exec
(
test_RecurrentGradientMachine
test_RecurrentGradientMachine.cpp
)
add_test
(
NAME test_RecurrentGradientMachine
COMMAND .set_python_path.sh -d
${
PADDLE_SOURCE_DIR
}
/python:
${
PADDLE_SOURCE_DIR
}
/paddle/gserver/tests
${
CMAKE_CURRENT_BINARY_DIR
}
/test_RecurrentGradientMachine
WORKING_DIRECTORY
${
PADDLE_SOURCE_DIR
}
/paddle
)
############### test_NetworkCompare ###############
add_unittest_without_exec
(
test_NetworkCompare
test_NetworkCompare.cpp
)
if
(
WITH_GPU
)
...
...
paddle/gserver/tests/test_Expand.cpp
0 → 100644
浏览文件 @
873ee9ab
/* Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserve.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. */
#include <gtest/gtest.h>
#include <string>
#include <vector>
#include "LayerGradUtil.h"
#include "paddle/testing/TestUtil.h"
using
namespace
paddle
;
// NOLINT
using
namespace
std
;
// NOLINT
// Do one forward pass of expand layer and check to see if its output
// matches the given result.(Test onlyCPU currently.)
void
doOneExpandTest
(
string
trans_type
,
bool
hasSubseq
,
bool
useGpu
,
Argument
&
input1
,
Argument
&
input2
,
Argument
&
result
)
{
FLAGS_use_gpu
=
false
;
// Setting up the expand layer
TestConfig
config
;
config
.
layerConfig
.
set_type
(
"expand"
);
auto
inputType1
=
trans_type
==
"non-seq"
?
INPUT_DENSE_DIM_DATA
:
INPUT_SEQUENCE_DATA
;
config
.
inputDefs
.
push_back
({
inputType1
,
"layer0"
,
1
,
0
});
auto
inputType2
=
hasSubseq
?
INPUT_HASSUB_SEQUENCE_DATA
:
INPUT_SEQUENCE_DATA
;
config
.
inputDefs
.
push_back
({
inputType2
,
"layer1"
,
1
,
0
});
config
.
layerConfig
.
add_inputs
();
config
.
layerConfig
.
add_inputs
();
config
.
layerConfig
.
set_trans_type
(
trans_type
);
// data layer initialize
std
::
vector
<
DataLayerPtr
>
dataLayers
;
LayerMap
layerMap
;
vector
<
Argument
>
datas
;
initDataLayer
(
config
,
&
dataLayers
,
&
datas
,
&
layerMap
,
"expand"
,
1
,
false
,
useGpu
);
dataLayers
[
0
]
->
getOutput
()
=
input1
;
dataLayers
[
1
]
->
getOutput
()
=
input2
;
// test layer initialize
std
::
vector
<
ParameterPtr
>
parameters
;
LayerPtr
expandLayer
;
initTestLayer
(
config
,
&
layerMap
,
&
parameters
,
&
expandLayer
);
expandLayer
->
forward
(
PASS_GC
);
checkMatrixEqual
(
expandLayer
->
getOutputValue
(),
result
.
value
);
}
TEST
(
Layer
,
ExpandLayerFwd
)
{
bool
useGpu
=
false
;
// Assume batch_size =3 in all cases.
// CPU case 1. non-seq expand to seq
// input1 = 1,2,3
// input2 = [4,5],[6],[7,8,9]
// result = [1,1],[2],[3,3,3]
Argument
input1
,
input2
,
result
;
input1
.
value
=
Matrix
::
create
(
3
,
1
,
false
,
useGpu
);
real
input1Data
[]
=
{
1
,
2
,
3
};
input1
.
value
->
setData
(
input1Data
);
input2
.
value
=
Matrix
::
create
(
6
,
1
,
false
,
useGpu
);
real
input2Data
[]
=
{
4
,
5
,
6
,
7
,
8
,
9
};
input2
.
value
->
setData
(
input2Data
);
input2
.
sequenceStartPositions
=
ICpuGpuVector
::
create
(
4
,
useGpu
);
int
input2Seq
[]
=
{
0
,
2
,
3
,
6
};
input2
.
sequenceStartPositions
->
copyFrom
(
input2Seq
,
4
,
useGpu
);
result
.
value
=
Matrix
::
create
(
6
,
1
,
false
,
useGpu
);
real
resultData
[]
=
{
1
,
1
,
2
,
3
,
3
,
3
};
result
.
value
->
setData
(
resultData
);
doOneExpandTest
(
"non-seq"
,
false
,
useGpu
,
input1
,
input2
,
result
);
// CPU case 2. non-seq expand to sub-seq
// input1 = 1,2,3
// input2 = [[4,5]],[[6]],[[7],[8,9]]
// result = [[1,1]],[[2]],[[3],[3,3]]
input2
.
subSequenceStartPositions
=
ICpuGpuVector
::
create
(
5
,
useGpu
);
int
input2SubSeq
[]
=
{
0
,
2
,
3
,
4
,
6
};
input2
.
subSequenceStartPositions
->
copyFrom
(
input2SubSeq
,
5
,
useGpu
);
doOneExpandTest
(
"non-seq"
,
true
,
useGpu
,
input1
,
input2
,
result
);
// CPU case 3. seq expand to sub-seq
// input1 = [1,2],[3],[4]
// input2 = [[4,5]],[[6]],[[7],[8,9]]
// result = [[1,1]],[[2]],[[3],[4,4]]
Matrix
::
resizeOrCreate
(
input1
.
value
,
4
,
1
,
false
,
useGpu
);
real
input1Data_case3
[]
=
{
1
,
2
,
3
,
4
};
input1
.
value
->
setData
(
input1Data_case3
);
input1
.
sequenceStartPositions
=
ICpuGpuVector
::
create
(
4
,
useGpu
);
int
input1Seq
[]
=
{
0
,
2
,
3
,
4
};
input1
.
sequenceStartPositions
->
copyFrom
(
input1Seq
,
4
,
useGpu
);
real
resultData_case3
[]
=
{
1
,
1
,
2
,
3
,
4
,
4
};
result
.
value
->
setData
(
resultData_case3
);
doOneExpandTest
(
"seq"
,
true
,
useGpu
,
input1
,
input2
,
result
);
}
int
main
(
int
argc
,
char
**
argv
)
{
testing
::
InitGoogleTest
(
&
argc
,
argv
);
initMain
(
argc
,
argv
);
return
RUN_ALL_TESTS
();
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录