Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
6f8f468f
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2298
Star
20931
Fork
5422
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1423
列表
看板
标记
里程碑
合并请求
543
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1,423
Issue
1,423
列表
看板
标记
里程碑
合并请求
543
合并请求
543
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
6f8f468f
编写于
12月 20, 2016
作者:
G
gaoyuan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add priorbox layer gpu unit test.
上级
7dfe3bdf
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
92 addition
and
35 deletion
+92
-35
paddle/gserver/tests/test_PriorBox.cpp
paddle/gserver/tests/test_PriorBox.cpp
+92
-35
未找到文件。
paddle/gserver/tests/test_PriorBox.cpp
浏览文件 @
6f8f468f
...
...
@@ -24,14 +24,15 @@ using namespace std; // NOLINT
// Do one forward pass of priorBox layer and check to see if its output
// matches the given result
void
doOnePriorBoxTest
(
size_t
feature
MapW
idth
,
size_t
feature
MapH
eight
,
size_t
image
W
idth
,
size_t
image
H
eight
,
vector
<
int
>
min
S
ize
,
vector
<
int
>
max
S
ize
,
vector
<
float
>
aspect
R
atio
,
void
doOnePriorBoxTest
(
size_t
feature
_map_w
idth
,
size_t
feature
_map_h
eight
,
size_t
image
_w
idth
,
size_t
image
_h
eight
,
vector
<
int
>
min
_s
ize
,
vector
<
int
>
max
_s
ize
,
vector
<
float
>
aspect
_r
atio
,
vector
<
float
>
variance
,
bool
use_gpu
,
MatrixPtr
&
result
)
{
// Setting up the priorbox layer
TestConfig
configt
;
...
...
@@ -42,28 +43,27 @@ void doOnePriorBoxTest(size_t featureMapWidth,
configt
.
inputDefs
.
push_back
({
INPUT_DATA
,
"image"
,
1
,
0
});
configt
.
layerConfig
.
add_inputs
();
PriorBoxConfig
*
pb
=
input
->
mutable_priorbox_conf
();
for
(
size_t
i
=
0
;
i
<
minSize
.
size
();
i
++
)
pb
->
add_min_size
(
minSize
[
i
]);
for
(
size_t
i
=
0
;
i
<
maxSize
.
size
();
i
++
)
pb
->
add_max_size
(
maxSize
[
i
]);
for
(
size_t
i
=
0
;
i
<
aspectRatio
.
size
();
i
++
)
pb
->
add_aspect_ratio
(
aspectRatio
[
i
]);
for
(
size_t
i
=
0
;
i
<
min_size
.
size
();
i
++
)
pb
->
add_min_size
(
min_size
[
i
]);
for
(
size_t
i
=
0
;
i
<
max_size
.
size
();
i
++
)
pb
->
add_max_size
(
max_size
[
i
]);
for
(
size_t
i
=
0
;
i
<
variance
.
size
();
i
++
)
pb
->
add_variance
(
variance
[
i
]);
for
(
size_t
i
=
0
;
i
<
aspect_ratio
.
size
();
i
++
)
pb
->
add_aspect_ratio
(
aspect_ratio
[
i
]);
// data layer initialize
std
::
vector
<
DataLayerPtr
>
dataLayers
;
LayerMap
layerMap
;
vector
<
Argument
>
datas
;
initDataLayer
(
configt
,
&
dataLayers
,
&
datas
,
&
layerMap
,
"priorbox"
,
1
,
false
,
false
);
dataLayers
[
0
]
->
getOutput
().
setFrameHeight
(
feature
MapH
eight
);
dataLayers
[
0
]
->
getOutput
().
setFrameWidth
(
feature
MapW
idth
);
dataLayers
[
1
]
->
getOutput
().
setFrameHeight
(
image
H
eight
);
dataLayers
[
1
]
->
getOutput
().
setFrameWidth
(
image
W
idth
);
configt
,
&
dataLayers
,
&
datas
,
&
layerMap
,
"priorbox"
,
1
,
false
,
use_gpu
);
dataLayers
[
0
]
->
getOutput
().
setFrameHeight
(
feature
_map_h
eight
);
dataLayers
[
0
]
->
getOutput
().
setFrameWidth
(
feature
_map_w
idth
);
dataLayers
[
1
]
->
getOutput
().
setFrameHeight
(
image
_h
eight
);
dataLayers
[
1
]
->
getOutput
().
setFrameWidth
(
image
_w
idth
);
// test layer initialize
std
::
vector
<
ParameterPtr
>
parameters
;
LayerPtr
priorboxLayer
;
initTestLayer
(
configt
,
&
layerMap
,
&
parameters
,
&
priorboxLayer
);
priorboxLayer
->
forward
(
PASS_GC
);
checkMatrixEqual
(
priorboxLayer
->
getOutputValue
(),
result
);
}
...
...
@@ -73,6 +73,7 @@ TEST(Layer, priorBoxLayerFwd) {
vector
<
int
>
maxSize
;
vector
<
float
>
aspectRatio
;
vector
<
float
>
variance
;
bool
useGpu
=
false
;
minSize
.
push_back
(
276
);
maxSize
.
push_back
(
330
);
...
...
@@ -81,9 +82,8 @@ TEST(Layer, priorBoxLayerFwd) {
variance
.
push_back
(
0.2
);
variance
.
push_back
(
0.2
);
// CPU case 1.
MatrixPtr
result
;
result
=
Matrix
::
create
(
1
,
2
*
8
,
false
,
false
);
float
resultData
[]
=
{
0.04
,
0.04
,
0.96
,
...
...
@@ -100,52 +100,109 @@ TEST(Layer, priorBoxLayerFwd) {
0.1
,
0.2
,
0.2
};
result
=
Matrix
::
create
(
1
,
2
*
8
,
false
,
useGpu
);
result
->
setData
(
resultData
);
doOnePriorBoxTest
(
/* feature
MapW
idth */
1
,
/* feature
MapH
eight */
1
,
/* image
W
idth */
300
,
/* image
H
eight */
300
,
doOnePriorBoxTest
(
/* feature
_map_w
idth */
1
,
/* feature
_map_h
eight */
1
,
/* image
_w
idth */
300
,
/* image
_h
eight */
300
,
minSize
,
maxSize
,
aspectRatio
,
variance
,
useGpu
,
result
);
// CPU case 2.
variance
[
1
]
=
0.2
;
variance
[
3
]
=
0.1
;
maxSize
.
pop_back
();
Matrix
::
resizeOrCreate
(
result
,
1
,
4
*
8
,
false
,
false
);
float
resultData2
[]
=
{
0
,
0
,
0.595
,
0.595
,
0.1
,
0.2
,
0.2
,
0.1
,
0.405
,
0
,
1
,
0.595
,
0.1
,
0.2
,
0.2
,
0.1
,
0
,
0.405
,
0.595
,
1
,
0.1
,
0.2
,
0.2
,
0.1
,
0.405
,
0.405
,
1
,
1
,
0.1
,
0.2
,
0.2
,
0.1
};
Matrix
::
resizeOrCreate
(
result
,
1
,
4
*
8
,
false
,
useGpu
);
result
->
setData
(
resultData2
);
doOnePriorBoxTest
(
/* feature
MapW
idth */
2
,
/* feature
MapH
eight */
2
,
/* image
W
idth */
400
,
/* image
H
eight */
400
,
doOnePriorBoxTest
(
/* feature
_map_w
idth */
2
,
/* feature
_map_h
eight */
2
,
/* image
_w
idth */
400
,
/* image
_h
eight */
400
,
minSize
,
maxSize
,
aspectRatio
,
variance
,
useGpu
,
result
);
// CPU case 3.
aspectRatio
.
push_back
(
2
);
Matrix
::
resizeOrCreate
(
result
,
1
,
3
*
8
,
false
,
false
);
float
resultData3
[]
=
{
0.04
,
0.04
,
0.96
,
0.96
,
0.1
,
0.2
,
0.2
,
0.1
,
0
,
0.17473088
,
1
,
0.825269
,
0.1
,
0.2
,
0.2
,
0.1
,
0.17473088
,
0
,
0.825269
,
1
,
0.1
,
0.2
,
0.2
,
0.1
};
Matrix
::
resizeOrCreate
(
result
,
1
,
3
*
8
,
false
,
useGpu
);
result
->
setData
(
resultData3
);
doOnePriorBoxTest
(
/* feature
MapW
idth */
1
,
/* feature
MapH
eight */
1
,
/* image
W
idth */
300
,
/* image
H
eight */
300
,
doOnePriorBoxTest
(
/* feature
_map_w
idth */
1
,
/* feature
_map_h
eight */
1
,
/* image
_w
idth */
300
,
/* image
_h
eight */
300
,
minSize
,
maxSize
,
aspectRatio
,
variance
,
useGpu
,
result
);
#ifndef PADDLE_ONLY_CPU
// reset the input parameters
variance
[
1
]
=
0.1
;
variance
[
3
]
=
0.2
;
maxSize
.
push_back
(
330
);
aspectRatio
.
pop_back
();
MatrixPtr
resultGpu
;
useGpu
=
true
;
// GPU case 1.
resultGpu
=
Matrix
::
create
(
1
,
2
*
8
,
false
,
useGpu
);
resultGpu
->
copyFrom
(
resultData
,
2
*
8
);
doOnePriorBoxTest
(
/* feature_map_width */
1
,
/* feature_map_height */
1
,
/* image_width */
300
,
/* image_height */
300
,
minSize
,
maxSize
,
aspectRatio
,
variance
,
useGpu
,
resultGpu
);
// GPU case 2.
variance
[
1
]
=
0.2
;
variance
[
3
]
=
0.1
;
maxSize
.
pop_back
();
Matrix
::
resizeOrCreate
(
resultGpu
,
1
,
4
*
8
,
false
,
useGpu
);
resultGpu
->
copyFrom
(
resultData2
,
4
*
8
);
doOnePriorBoxTest
(
/* feature_map_width */
2
,
/* feature_map_height */
2
,
/* image_width */
400
,
/* image_height */
400
,
minSize
,
maxSize
,
aspectRatio
,
variance
,
useGpu
,
resultGpu
);
// GPU case 3.
aspectRatio
.
push_back
(
2
);
Matrix
::
resizeOrCreate
(
resultGpu
,
1
,
3
*
8
,
false
,
useGpu
);
resultGpu
->
copyFrom
(
resultData3
,
3
*
8
);
doOnePriorBoxTest
(
/* feature_map_width */
1
,
/* feature_map_height */
1
,
/* image_width */
300
,
/* image_height */
300
,
minSize
,
maxSize
,
aspectRatio
,
variance
,
useGpu
,
resultGpu
);
#endif
}
int
main
(
int
argc
,
char
**
argv
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录