Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
TonyTonyFun
Paddle
提交
1c558ad3
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,发现更多精彩内容 >>
提交
1c558ad3
编写于
1月 22, 2019
作者:
J
jerrywgz
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add gpu kernel for box clip, test=develop
上级
5246285e
变更
5
显示空白变更内容
内联
并排
Showing
5 changed file
with
63 addition
and
34 deletion
+63
-34
paddle/fluid/operators/detection/CMakeLists.txt
paddle/fluid/operators/detection/CMakeLists.txt
+1
-1
paddle/fluid/operators/detection/box_clip_op.cc
paddle/fluid/operators/detection/box_clip_op.cc
+26
-19
paddle/fluid/operators/detection/box_clip_op.h
paddle/fluid/operators/detection/box_clip_op.h
+2
-2
python/paddle/fluid/layers/detection.py
python/paddle/fluid/layers/detection.py
+32
-10
python/paddle/fluid/tests/unittests/test_box_clip_op.py
python/paddle/fluid/tests/unittests/test_box_clip_op.py
+2
-2
未找到文件。
paddle/fluid/operators/detection/CMakeLists.txt
浏览文件 @
1c558ad3
...
...
@@ -31,7 +31,7 @@ detection_library(polygon_box_transform_op SRCS polygon_box_transform_op.cc
polygon_box_transform_op.cu
)
detection_library
(
rpn_target_assign_op SRCS rpn_target_assign_op.cc
)
detection_library
(
generate_proposal_labels_op SRCS generate_proposal_labels_op.cc
)
detection_library
(
box_clip_op SRCS box_clip_op.cc
)
detection_library
(
box_clip_op SRCS box_clip_op.cc
box_clip_op.cu
)
if
(
WITH_GPU
)
detection_library
(
generate_proposals_op SRCS generate_proposals_op.cc generate_proposals_op.cu DEPS memory cub
)
...
...
paddle/fluid/operators/detection/box_clip_op.cc
浏览文件 @
1c558ad3
...
...
@@ -21,51 +21,58 @@ class BoxClipOp : public framework::OperatorWithKernel {
protected:
void
InferShape
(
framework
::
InferShapeContext
*
ctx
)
const
override
{
PADDLE_ENFORCE
(
ctx
->
HasInput
(
"Input
Box
"
),
"Input(Input
Box
) of BoxClipOp should not be null."
);
PADDLE_ENFORCE
(
ctx
->
HasInput
(
"Input"
),
"Input(Input) of BoxClipOp should not be null."
);
PADDLE_ENFORCE
(
ctx
->
HasInput
(
"ImInfo"
),
"Input(ImInfo) of BoxClipOp should not be null."
);
auto
input_box_dims
=
ctx
->
GetInputDim
(
"Input
Box
"
);
auto
input_box_dims
=
ctx
->
GetInputDim
(
"Input"
);
auto
im_info_dims
=
ctx
->
GetInputDim
(
"ImInfo"
);
if
(
ctx
->
IsRuntime
())
{
auto
input_box_size
=
input_box_dims
.
size
();
PADDLE_ENFORCE_EQ
(
input_box_dims
[
input_box_size
-
1
],
4
,
"The last dimension of Input
Box
must be 4"
);
"The last dimension of Input must be 4"
);
PADDLE_ENFORCE_EQ
(
im_info_dims
.
size
(),
2
,
"The rank of Input(Input
Box
) in BoxClipOp must be 2"
);
"The rank of Input(Input) in BoxClipOp must be 2"
);
PADDLE_ENFORCE_EQ
(
im_info_dims
[
1
],
3
,
"The last dimension of ImInfo must be 3"
);
}
ctx
->
ShareDim
(
"Input
Box"
,
/*->*/
"OutputBox
"
);
ctx
->
ShareLoD
(
"Input
Box"
,
/*->*/
"OutputBox
"
);
ctx
->
ShareDim
(
"Input
"
,
/*->*/
"Output
"
);
ctx
->
ShareLoD
(
"Input
"
,
/*->*/
"Output
"
);
}
/*
protected:
framework::OpKernelType GetExpectedKernelType(
const framework::ExecutionContext& ctx) const override {
auto
data_type
=
framework
::
GetDataTypeOfVar
(
ctx
.
InputVar
(
"InputBox
"
));
auto data_type = framework::GetDataTypeOfVar(ctx.InputVar("Input
"));
return framework::OpKernelType(data_type, platform::CPUPlace());
}
*/
};
class
BoxClipOpMaker
:
public
framework
::
OpProtoAndCheckerMaker
{
public:
void
Make
()
override
{
AddInput
(
"Input
Box
"
,
AddInput
(
"Input"
,
"(LoDTensor) "
"Input
Box
is a LoDTensor with shape [..., 4] holds 4 points"
"Input is a LoDTensor with shape [..., 4] holds 4 points"
"in last dimension in format [xmin, ymin, xmax, ymax]"
);
AddInput
(
"ImInfo"
,
"(Tensor) Information for image reshape is in shape (N, 3), "
"in format (height, width, im_scale)"
);
AddOutput
(
"Output
Box
"
,
AddOutput
(
"Output"
,
"(LoDTensor) "
"Output
Box is a LoDTensor with the same shape as InputBox
"
"Output
is a LoDTensor with the same shape as Input
"
"and it is the result after clip"
);
AddComment
(
R"DOC(
This operator clips input boxes to original input images.
This operator clips input boxes to original input images.
The formula is given as follows:
$$height_out = \max(\min(height_loc, im_h), 0)$$
$$width_out = \max(\min(width_loc, im_w), 0)$$
)DOC"
);
}
};
...
...
paddle/fluid/operators/detection/box_clip_op.h
浏览文件 @
1c558ad3
...
...
@@ -25,9 +25,9 @@ template <typename DeviceContext, typename T>
class
BoxClipKernel
:
public
framework
::
OpKernel
<
T
>
{
public:
void
Compute
(
const
framework
::
ExecutionContext
&
context
)
const
override
{
auto
*
input_box
=
context
.
Input
<
LoDTensor
>
(
"Input
Box
"
);
auto
*
input_box
=
context
.
Input
<
LoDTensor
>
(
"Input"
);
auto
*
im_info
=
context
.
Input
<
LoDTensor
>
(
"ImInfo"
);
auto
*
output_box
=
context
.
Output
<
LoDTensor
>
(
"Output
Box
"
);
auto
*
output_box
=
context
.
Output
<
LoDTensor
>
(
"Output"
);
auto
&
dev_ctx
=
context
.
template
device_context
<
platform
::
CPUDeviceContext
>();
output_box
->
mutable_data
<
T
>
(
context
.
GetPlace
());
...
...
python/paddle/fluid/layers/detection.py
浏览文件 @
1c558ad3
...
...
@@ -31,11 +31,24 @@ import numpy
from
functools
import
reduce
__all__
=
[
'prior_box'
,
'density_prior_box'
,
'multi_box_head'
,
'bipartite_match'
,
'target_assign'
,
'detection_output'
,
'ssd_loss'
,
'detection_map'
,
'rpn_target_assign'
,
'anchor_generator'
,
'roi_perspective_transform'
,
'generate_proposal_labels'
,
'generate_proposals'
,
'iou_similarity'
,
'box_coder'
,
'polygon_box_transform'
,
'yolov3_loss'
,
'box_clip'
'prior_box'
,
'density_prior_box'
,
'multi_box_head'
,
'bipartite_match'
,
'target_assign'
,
'detection_output'
,
'ssd_loss'
,
'detection_map'
,
'rpn_target_assign'
,
'anchor_generator'
,
'roi_perspective_transform'
,
'generate_proposal_labels'
,
'generate_proposals'
,
'iou_similarity'
,
'box_coder'
,
'polygon_box_transform'
,
'yolov3_loss'
,
'box_clip'
,
]
...
...
@@ -1800,13 +1813,22 @@ def generate_proposals(scores,
return
rpn_rois
,
rpn_roi_probs
def
box_clip
(
input
_box
,
im_info
,
inplace
=
False
,
name
=
None
):
def
box_clip
(
input
,
im_info
,
inplace
=
False
,
name
=
None
):
"""
Clip the box into the size given by im_info
The formula is given as follows:
.. code-block:: text
height_out = max(min(height_loc, im_h), 0)
width_out = max(min(width_loc, im_w), 0)
Args:
input_box(variable): The input box, the last dimension is 4.
im_info(variable): The information of image with shape [N, 3].
im_info(variable): The information of image with shape [N, 3] with
layout (height, width, scale). height and width
is the input size and scale is the ratio of input
size and original size.
inplace(bool): Must use :attr:`False` if :attr:`input_box` is used in
multiple operators. If this flag is set :attr:`True`,
reuse input :attr:`input_box` to clip, which will
...
...
@@ -1832,12 +1854,12 @@ def box_clip(input_box, im_info, inplace=False, name=None):
"""
helper
=
LayerHelper
(
"box_clip"
,
**
locals
())
output
=
helper
.
create_variable_for_type_inference
(
dtype
=
input
_box
.
dtype
)
inputs
=
{
"Input
Box"
:
input_box
,
"ImInfo"
:
im_info
}
output
=
helper
.
create_variable_for_type_inference
(
dtype
=
input
.
dtype
)
inputs
=
{
"Input
"
:
input
,
"ImInfo"
:
im_info
}
helper
.
append_op
(
type
=
"box_clip"
,
inputs
=
inputs
,
attrs
=
{
"inplace:"
:
inplace
},
outputs
=
{
"Output
Box
"
:
output
})
outputs
=
{
"Output"
:
output
})
return
output
python/paddle/fluid/tests/unittests/test_box_clip_op.py
浏览文件 @
1c558ad3
...
...
@@ -60,10 +60,10 @@ class TestBoxClipOp(OpTest):
output_boxes
=
batch_box_clip
(
input_boxes
,
im_info
,
lod
[
0
])
self
.
inputs
=
{
'Input
Box
'
:
(
input_boxes
.
astype
(
'float32'
),
lod
),
'Input'
:
(
input_boxes
.
astype
(
'float32'
),
lod
),
'ImInfo'
:
im_info
.
astype
(
'float32'
),
}
self
.
outputs
=
{
'Output
Box
'
:
output_boxes
}
self
.
outputs
=
{
'Output'
:
output_boxes
}
if
__name__
==
'__main__'
:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录