Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleDetection
提交
9f990d90
P
PaddleDetection
项目概览
PaddlePaddle
/
PaddleDetection
大约 1 年 前同步成功
通知
695
Star
11112
Fork
2696
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
184
列表
看板
标记
里程碑
合并请求
40
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleDetection
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
184
Issue
184
列表
看板
标记
里程碑
合并请求
40
合并请求
40
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
9f990d90
编写于
12月 16, 2016
作者:
G
gaoyuan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add unittest of the priorbox layer
上级
1048aee0
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
171 addition
and
1 deletion
+171
-1
paddle/gserver/layers/PriorBox.cpp
paddle/gserver/layers/PriorBox.cpp
+1
-0
paddle/gserver/tests/CMakeLists.txt
paddle/gserver/tests/CMakeLists.txt
+8
-0
paddle/gserver/tests/test_PriorBox.cpp
paddle/gserver/tests/test_PriorBox.cpp
+160
-0
python/paddle/trainer/config_parser.py
python/paddle/trainer/config_parser.py
+2
-1
未找到文件。
paddle/gserver/layers/PriorBox.cpp
浏览文件 @
9f990d90
...
...
@@ -76,6 +76,7 @@ void PriorBoxLayer::forward(PassType passType) {
auto
image
=
getInput
(
1
);
int
imageWidth
=
image
.
getFrameWidth
();
int
imageHeight
=
image
.
getFrameHeight
();
float
stepW
=
static_cast
<
float
>
(
imageWidth
)
/
layerWidth
;
float
stepH
=
static_cast
<
float
>
(
imageHeight
)
/
layerHeight
;
int
dim
=
layerHeight
*
layerWidth
*
numPriors_
*
4
;
...
...
paddle/gserver/tests/CMakeLists.txt
浏览文件 @
9f990d90
...
...
@@ -34,6 +34,14 @@ add_unittest_without_exec(test_ConvTrans
add_test
(
NAME test_ConvTrans
COMMAND test_ConvTrans
)
################# test_PriorBox #######################
add_unittest_without_exec
(
test_PriorBox
test_PriorBox.cpp
LayerGradUtil.cpp
TestUtil.cpp
)
add_test
(
NAME test_PriorBox
COMMAND test_PriorBox
)
################# test_ConvUnify #######################
add_unittest_without_exec
(
test_ConvUnify
test_ConvUnify.cpp
...
...
paddle/gserver/tests/test_PriorBox.cpp
0 → 100644
浏览文件 @
9f990d90
/* 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 <string>
#include <vector>
#include "LayerGradUtil.h"
#include "TestUtil.h"
using
namespace
paddle
;
// NOLINT
using
namespace
std
;
// NOLINT
P_DECLARE_bool
(
use_gpu
);
P_DECLARE_int32
(
gpu_id
);
P_DECLARE_bool
(
thread_local_rand_use_global_seed
);
// Do one forward pass of priorBox layer and check to see if its output
// matches the given result
void
doOnePriorBoxTest
(
size_t
featureMapWidth
,
size_t
featureMapHeight
,
size_t
imageWidth
,
size_t
imageHeight
,
vector
<
int
>
minSize
,
vector
<
int
>
maxSize
,
vector
<
float
>
aspectRatio
,
vector
<
float
>
variance
,
MatrixPtr
&
result
)
{
// Setting up the priorbox layer
TestConfig
configt
;
configt
.
layerConfig
.
set_type
(
"priorbox"
);
configt
.
inputDefs
.
push_back
({
INPUT_DATA
,
"featureMap"
,
1
,
0
});
LayerInputConfig
*
input
=
configt
.
layerConfig
.
add_inputs
();
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
<
variance
.
size
();
i
++
)
pb
->
add_variance
(
variance
[
i
]);
// data layer initialize
std
::
vector
<
DataLayerPtr
>
dataLayers
;
LayerMap
layerMap
;
vector
<
Argument
>
datas
;
initDataLayer
(
configt
,
&
dataLayers
,
&
datas
,
&
layerMap
,
"priorbox"
,
1
,
false
,
true
);
dataLayers
[
0
]
->
getOutput
().
setFrameHeight
(
featureMapHeight
);
dataLayers
[
0
]
->
getOutput
().
setFrameWidth
(
featureMapWidth
);
dataLayers
[
1
]
->
getOutput
().
setFrameHeight
(
imageHeight
);
dataLayers
[
1
]
->
getOutput
().
setFrameWidth
(
imageWidth
);
// test layer initialize
std
::
vector
<
ParameterPtr
>
parameters
;
LayerPtr
priorboxLayer
;
initTestLayer
(
configt
,
&
layerMap
,
&
parameters
,
&
priorboxLayer
);
priorboxLayer
->
forward
(
PASS_GC
);
checkMatrixEqual
(
priorboxLayer
->
getOutputValue
(),
result
);
}
TEST
(
Layer
,
priorBoxLayerFwd
)
{
vector
<
int
>
minSize
;
vector
<
int
>
maxSize
;
vector
<
float
>
aspectRatio
;
vector
<
float
>
variance
;
minSize
.
push_back
(
276
);
maxSize
.
push_back
(
330
);
variance
.
push_back
(
0.1
);
variance
.
push_back
(
0.1
);
variance
.
push_back
(
0.2
);
variance
.
push_back
(
0.2
);
MatrixPtr
result
;
result
=
Matrix
::
create
(
1
,
2
*
8
,
false
,
false
);
float
resultData
[]
=
{
0.04
,
0.04
,
0.96
,
0.96
,
0.1
,
0.1
,
0.2
,
0.2
,
0
,
0
,
1
,
1
,
0.1
,
0.1
,
0.2
,
0.2
};
result
->
setData
(
resultData
);
doOnePriorBoxTest
(
/* featureMapWidth */
1
,
/* featureMapHeight */
1
,
/* imageWidth */
300
,
/* imageHeight */
300
,
minSize
,
maxSize
,
aspectRatio
,
variance
,
result
);
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
};
result
->
setData
(
resultData2
);
doOnePriorBoxTest
(
/* featureMapWidth */
2
,
/* featureMapHeight */
2
,
/* imageWidth */
400
,
/* imageHeight */
400
,
minSize
,
maxSize
,
aspectRatio
,
variance
,
result
);
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
};
result
->
setData
(
resultData3
);
doOnePriorBoxTest
(
/* featureMapWidth */
1
,
/* featureMapHeight */
1
,
/* imageWidth */
300
,
/* imageHeight */
300
,
minSize
,
maxSize
,
aspectRatio
,
variance
,
result
);
}
int
main
(
int
argc
,
char
**
argv
)
{
testing
::
InitGoogleTest
(
&
argc
,
argv
);
initMain
(
argc
,
argv
);
FLAGS_thread_local_rand_use_global_seed
=
true
;
srand
(
1
);
return
RUN_ALL_TESTS
();
}
python/paddle/trainer/config_parser.py
浏览文件 @
9f990d90
...
...
@@ -1583,7 +1583,7 @@ class PriorBoxLayer(LayerBase):
def
__init__
(
self
,
name
,
inputs
,
size
,
min_size
,
max_size
,
aspect_ratio
,
variance
):
super
(
PriorBoxLayer
,
self
).
__init__
(
name
,
'priorbox'
,
0
,
inputs
)
config_assert
(
len
(
inputs
)
==
2
,
'PriorBoxLayer must have 2 input'
)
config_assert
(
len
(
inputs
)
==
2
,
'PriorBoxLayer must have 2 input
s
'
)
input_layer
=
self
.
get_input_layer
(
1
)
config_assert
(
input_layer
.
type
==
'data'
,
...
...
@@ -1591,6 +1591,7 @@ class PriorBoxLayer(LayerBase):
'a data layer'
)
config_assert
(
input_layer
.
width
>
0
,
'The data layer must set width'
)
config_assert
(
input_layer
.
height
>
0
,
'The data layer must set height'
)
config_assert
(
len
(
variance
)
==
4
,
'The variance must have 4 inputs'
)
self
.
config
.
inputs
[
0
].
priorbox_conf
.
min_size
.
extend
(
min_size
)
self
.
config
.
inputs
[
0
].
priorbox_conf
.
max_size
.
extend
(
max_size
)
self
.
config
.
inputs
[
0
].
priorbox_conf
.
aspect_ratio
.
extend
(
aspect_ratio
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录