Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
TonyTonyFun
Paddle
提交
142f6328
P
Paddle
项目概览
TonyTonyFun
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
142f6328
编写于
1月 22, 2018
作者:
W
wanghaox
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update code
上级
f020f4b5
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
57 addition
and
74 deletion
+57
-74
paddle/operators/prior_box_op.cc
paddle/operators/prior_box_op.cc
+16
-21
paddle/operators/prior_box_op.h
paddle/operators/prior_box_op.h
+9
-9
python/paddle/v2/fluid/tests/test_prior_box_op.py
python/paddle/v2/fluid/tests/test_prior_box_op.py
+32
-44
未找到文件。
paddle/operators/prior_box_op.cc
浏览文件 @
142f6328
...
...
@@ -23,14 +23,14 @@ class PriorBoxOp : public framework::OperatorWithKernel {
void
InferShape
(
framework
::
InferShapeContext
*
ctx
)
const
override
{
PADDLE_ENFORCE
(
ctx
->
HasInput
(
"Input"
),
"Input(
X
) of PriorBoxOp should not be null."
);
"Input(
Input
) of PriorBoxOp should not be null."
);
PADDLE_ENFORCE
(
ctx
->
HasInput
(
"Image"
),
"Input(
Offset
) of PriorBoxOp should not be null."
);
"Input(
Image
) of PriorBoxOp should not be null."
);
auto
image_dims
=
ctx
->
GetInputDim
(
"Image"
);
auto
input_dims
=
ctx
->
GetInputDim
(
"Input"
);
PADDLE_ENFORCE
(
image_dims
.
size
()
==
4
,
"The
forma
t of image is NCHW."
);
PADDLE_ENFORCE
(
input_dims
.
size
()
==
4
,
"The
forma
t of input is NCHW."
);
PADDLE_ENFORCE
(
image_dims
.
size
()
==
4
,
"The
layou
t of image is NCHW."
);
PADDLE_ENFORCE
(
input_dims
.
size
()
==
4
,
"The
layou
t of input is NCHW."
);
PADDLE_ENFORCE_LT
(
input_dims
[
2
],
image_dims
[
2
],
"The height of input must smaller than image."
);
...
...
@@ -45,7 +45,7 @@ class PriorBoxOp : public framework::OperatorWithKernel {
bool
flip
=
ctx
->
Attrs
().
Get
<
bool
>
(
"flip"
);
PADDLE_ENFORCE_GT
(
min_sizes
.
size
(),
0
,
"Size of min_size must be at least 1."
);
"Size of min_size
s
must be at least 1."
);
for
(
size_t
i
=
0
;
i
<
min_sizes
.
size
();
++
i
)
{
PADDLE_ENFORCE_GT
(
min_sizes
[
i
],
0
,
"min_sizes[%d] must be positive."
,
i
);
}
...
...
@@ -56,7 +56,7 @@ class PriorBoxOp : public framework::OperatorWithKernel {
int
num_priors
=
aspect_ratios_vec
.
size
()
*
min_sizes
.
size
();
if
(
max_sizes
.
size
()
>
0
)
{
PADDLE_ENFORCE_EQ
(
max_sizes
.
size
(),
min_sizes
.
size
(),
"The
length
of min_size and max_size must be equal."
);
"The
number
of min_size and max_size must be equal."
);
for
(
size_t
i
=
0
;
i
<
min_sizes
.
size
();
++
i
)
{
PADDLE_ENFORCE_GT
(
max_sizes
[
i
],
min_sizes
[
i
],
"max_size[%d] must be greater than min_size[%d]."
,
i
,
...
...
@@ -65,13 +65,10 @@ class PriorBoxOp : public framework::OperatorWithKernel {
}
}
if
(
variances
.
size
()
>
1
)
{
PADDLE_ENFORCE_EQ
(
variances
.
size
(),
4
,
"Must and only provide 4 variance."
);
for
(
size_t
i
=
0
;
i
<
variances
.
size
();
++
i
)
{
PADDLE_ENFORCE_GT
(
variances
[
i
],
0.0
,
"variance[%d] must be greater than 0."
,
i
);
}
PADDLE_ENFORCE_EQ
(
variances
.
size
(),
4
,
"Must and only provide 4 variance."
);
for
(
size_t
i
=
0
;
i
<
variances
.
size
();
++
i
)
{
PADDLE_ENFORCE_GT
(
variances
[
i
],
0.0
,
"variance[%d] must be greater than 0."
,
i
);
}
const
float
step_h
=
ctx
->
Attrs
().
Get
<
float
>
(
"step_h"
);
...
...
@@ -95,19 +92,19 @@ class PriorBoxOpMaker : public framework::OpProtoAndCheckerMaker {
:
OpProtoAndCheckerMaker
(
proto
,
op_checker
)
{
AddInput
(
"Input"
,
"(Tensor, default Tensor<float>), "
"the input feature data of PriorBoxOp, The
forma
t is NCHW."
);
"the input feature data of PriorBoxOp, The
layou
t is NCHW."
);
AddInput
(
"Image"
,
"(Tensor, default Tensor<float>), "
"the input image data of PriorBoxOp, The
forma
t is NCHW."
);
"the input image data of PriorBoxOp, The
layou
t is NCHW."
);
AddOutput
(
"Boxes"
,
"(Tensor, default Tensor<float>), the output prior boxes of "
"PriorBoxOp. The
forma
t is [layer_height, layer_width, "
"PriorBoxOp. The
layou
t is [layer_height, layer_width, "
"num_priors, 4]. layer_height is the height of input, "
"layer_width is the width of input, num_priors is the box "
"count of each position."
);
AddOutput
(
"Variances"
,
"(Tensor, default Tensor<float>), the expanded variances of "
"PriorBoxOp. The
forma
t is [layer_height, layer_width, "
"PriorBoxOp. The
layou
t is [layer_height, layer_width, "
"num_priors, 4]. layer_height is the height of input, "
"layer_width is the width of input, num_priors is the box "
"count of each position."
);
...
...
@@ -117,12 +114,10 @@ class PriorBoxOpMaker : public framework::OpProtoAndCheckerMaker {
"List of max sizes of generated prior boxes."
);
AddAttr
<
std
::
vector
<
float
>>
(
"aspect_ratios"
,
"(vector<float>) "
,
"List of aspect ratios of generated prior boxes."
)
.
SetDefault
({});
"List of aspect ratios of generated prior boxes."
);
AddAttr
<
std
::
vector
<
float
>>
(
"variances"
,
"(vector<float>) "
,
"List of variances to be encoded in prior boxes."
)
.
SetDefault
({
0.1
});
"List of variances to be encoded in prior boxes."
);
AddAttr
<
bool
>
(
"flip"
,
"(bool) "
,
"Whether to flip aspect ratios."
)
.
SetDefault
(
true
);
AddAttr
<
bool
>
(
"clip"
,
"(bool) "
,
"Whether to clip out-of-boundary boxes."
)
...
...
paddle/operators/prior_box_op.h
浏览文件 @
142f6328
...
...
@@ -70,9 +70,9 @@ class PriorBoxOpKernel : public framework::OpKernel<T> {
std
::
vector
<
float
>
aspect_ratios
;
ExpandAspectRatios
(
input_aspect_ratio
,
flip
,
aspect_ratios
);
auto
step_w
=
ctx
.
Attr
<
float
>
(
"step_w"
);
auto
step_h
=
ctx
.
Attr
<
float
>
(
"step_h"
);
auto
offset
=
ctx
.
Attr
<
float
>
(
"offset"
);
T
step_w
=
static_cast
<
T
>
(
ctx
.
Attr
<
float
>
(
"step_w"
)
);
T
step_h
=
static_cast
<
T
>
(
ctx
.
Attr
<
float
>
(
"step_h"
)
);
T
offset
=
static_cast
<
T
>
(
ctx
.
Attr
<
float
>
(
"offset"
)
);
auto
img_width
=
image
->
dims
()[
3
];
auto
img_height
=
image
->
dims
()[
2
];
...
...
@@ -80,10 +80,10 @@ class PriorBoxOpKernel : public framework::OpKernel<T> {
auto
layer_width
=
input
->
dims
()[
3
];
auto
layer_height
=
input
->
dims
()[
2
];
float
step_width
,
step_height
;
T
step_width
,
step_height
;
if
(
step_w
==
0
||
step_h
==
0
)
{
step_width
=
static_cast
<
float
>
(
img_width
)
/
layer_width
;
step_height
=
static_cast
<
float
>
(
img_height
)
/
layer_height
;
step_width
=
static_cast
<
T
>
(
img_width
)
/
layer_width
;
step_height
=
static_cast
<
T
>
(
img_height
)
/
layer_height
;
}
else
{
step_width
=
step_w
;
step_height
=
step_h
;
...
...
@@ -100,9 +100,9 @@ class PriorBoxOpKernel : public framework::OpKernel<T> {
auto
e_boxes
=
framework
::
EigenTensor
<
T
,
4
>::
From
(
*
boxes
);
for
(
int
h
=
0
;
h
<
layer_height
;
++
h
)
{
for
(
int
w
=
0
;
w
<
layer_width
;
++
w
)
{
float
center_x
=
(
w
+
offset
)
*
step_width
;
float
center_y
=
(
h
+
offset
)
*
step_height
;
float
box_width
,
box_height
;
T
center_x
=
(
w
+
offset
)
*
step_width
;
T
center_y
=
(
h
+
offset
)
*
step_height
;
T
box_width
,
box_height
;
int
idx
=
0
;
for
(
size_t
s
=
0
;
s
<
min_sizes
.
size
();
++
s
)
{
int
min_size
=
min_sizes
[
s
];
...
...
python/paddle/v2/fluid/tests/test_prior_box_op.py
浏览文件 @
142f6328
# Copyright (c) 2018 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.
import
unittest
import
numpy
as
np
import
sys
...
...
@@ -86,44 +100,26 @@ class TestPriorBoxOp(OpTest):
idx
=
0
for
h
in
range
(
self
.
layer_h
):
for
w
in
range
(
self
.
layer_w
):
c
enter
_x
=
(
w
+
self
.
offset
)
*
self
.
step_w
c
enter
_y
=
(
h
+
self
.
offset
)
*
self
.
step_h
c_x
=
(
w
+
self
.
offset
)
*
self
.
step_w
c_y
=
(
h
+
self
.
offset
)
*
self
.
step_h
idx
=
0
for
s
in
range
(
len
(
self
.
min_sizes
)):
min_size
=
self
.
min_sizes
[
s
]
# first prior: aspect_ratio = 1, size = min_size
box_width
=
box_height
=
min_size
# xmin
out_boxes
[
h
,
w
,
idx
,
0
]
=
(
center_x
-
box_width
/
2.
)
/
self
.
image_w
# ymin
out_boxes
[
h
,
w
,
idx
,
1
]
=
(
center_y
-
box_height
/
2.
)
/
self
.
image_h
# xmax
out_boxes
[
h
,
w
,
idx
,
2
]
=
(
center_x
+
box_width
/
2.
)
/
self
.
image_w
# ymax
out_boxes
[
h
,
w
,
idx
,
3
]
=
(
center_y
+
box_height
/
2.
)
/
self
.
image_h
c_w
=
c_h
=
min_size
/
2.
out_boxes
[
h
,
w
,
idx
,
:]
=
[
(
c_x
-
c_w
)
/
self
.
image_w
,
(
c_y
-
c_h
)
/
self
.
image_h
,
(
c_x
+
c_w
)
/
self
.
image_w
,
(
c_y
+
c_h
)
/
self
.
image_h
]
idx
+=
1
if
len
(
self
.
max_sizes
)
>
0
:
max_size
=
self
.
max_sizes
[
s
]
# second prior: aspect_ratio = 1,
# size = sqrt(min_size * max_size)
box_width
=
box_height
=
math
.
sqrt
(
min_size
*
max_size
)
# xmin
out_boxes
[
h
,
w
,
idx
,
0
]
=
(
center_x
-
box_width
/
2.
)
/
self
.
image_w
# ymin
out_boxes
[
h
,
w
,
idx
,
1
]
=
(
center_y
-
box_height
/
2.
)
/
self
.
image_h
# xmax
out_boxes
[
h
,
w
,
idx
,
2
]
=
(
center_x
+
box_width
/
2.
)
/
self
.
image_w
# ymax
out_boxes
[
h
,
w
,
idx
,
3
]
=
(
center_y
+
box_height
/
2.
)
/
self
.
image_h
c_w
=
c_h
=
math
.
sqrt
(
min_size
*
max_size
)
/
2
out_boxes
[
h
,
w
,
idx
,
:]
=
[(
c_x
-
c_w
)
/
self
.
image_w
,
(
c_y
-
c_h
)
/
self
.
image_h
,
(
c_x
+
c_w
)
/
self
.
image_w
,
(
c_y
+
c_h
)
/
self
.
image_h
]
idx
+=
1
# rest of priors
...
...
@@ -131,20 +127,12 @@ class TestPriorBoxOp(OpTest):
ar
=
self
.
real_aspect_ratios
[
r
]
if
math
.
fabs
(
ar
-
1.
)
<
1e-6
:
continue
box_width
=
min_size
*
math
.
sqrt
(
ar
)
box_height
=
min_size
/
math
.
sqrt
(
ar
)
# xmin
out_boxes
[
h
,
w
,
idx
,
0
]
=
(
center_x
-
box_width
/
2.
)
/
self
.
image_w
# ymin
out_boxes
[
h
,
w
,
idx
,
1
]
=
(
center_y
-
box_height
/
2.
)
/
self
.
image_h
# xmax
out_boxes
[
h
,
w
,
idx
,
2
]
=
(
center_x
+
box_width
/
2.
)
/
self
.
image_w
# ymax
out_boxes
[
h
,
w
,
idx
,
3
]
=
(
center_y
+
box_height
/
2.
)
/
self
.
image_h
c_w
=
min_size
*
math
.
sqrt
(
ar
)
/
2
c_h
=
(
min_size
/
math
.
sqrt
(
ar
))
/
2
out_boxes
[
h
,
w
,
idx
,
:]
=
[(
c_x
-
c_w
)
/
self
.
image_w
,
(
c_y
-
c_h
)
/
self
.
image_h
,
(
c_x
+
c_w
)
/
self
.
image_w
,
(
c_y
+
c_h
)
/
self
.
image_h
]
idx
+=
1
# clip the prior's coordidate such that it is within[0, 1]
if
self
.
clip
:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录