Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
1a88baae
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2299
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看板
提交
1a88baae
编写于
8月 30, 2018
作者:
J
jerrywgz
提交者:
qingqing01
8月 30, 2018
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add rpn_target_assign api test (#13013)
* Add unit test for rpn_target_assign API.
上级
03b1e4be
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
62 addition
and
7 deletion
+62
-7
paddle/fluid/API.spec
paddle/fluid/API.spec
+1
-1
python/paddle/fluid/layers/detection.py
python/paddle/fluid/layers/detection.py
+8
-6
python/paddle/fluid/tests/test_detection.py
python/paddle/fluid/tests/test_detection.py
+53
-0
未找到文件。
paddle/fluid/API.spec
浏览文件 @
1a88baae
...
@@ -301,7 +301,7 @@ paddle.fluid.layers.target_assign ArgSpec(args=['input', 'matched_indices', 'neg
...
@@ -301,7 +301,7 @@ paddle.fluid.layers.target_assign ArgSpec(args=['input', 'matched_indices', 'neg
paddle.fluid.layers.detection_output ArgSpec(args=['loc', 'scores', 'prior_box', 'prior_box_var', 'background_label', 'nms_threshold', 'nms_top_k', 'keep_top_k', 'score_threshold', 'nms_eta'], varargs=None, keywords=None, defaults=(0, 0.3, 400, 200, 0.01, 1.0))
paddle.fluid.layers.detection_output ArgSpec(args=['loc', 'scores', 'prior_box', 'prior_box_var', 'background_label', 'nms_threshold', 'nms_top_k', 'keep_top_k', 'score_threshold', 'nms_eta'], varargs=None, keywords=None, defaults=(0, 0.3, 400, 200, 0.01, 1.0))
paddle.fluid.layers.ssd_loss ArgSpec(args=['location', 'confidence', 'gt_box', 'gt_label', 'prior_box', 'prior_box_var', 'background_label', 'overlap_threshold', 'neg_pos_ratio', 'neg_overlap', 'loc_loss_weight', 'conf_loss_weight', 'match_type', 'mining_type', 'normalize', 'sample_size'], varargs=None, keywords=None, defaults=(None, 0, 0.5, 3.0, 0.5, 1.0, 1.0, 'per_prediction', 'max_negative', True, None))
paddle.fluid.layers.ssd_loss ArgSpec(args=['location', 'confidence', 'gt_box', 'gt_label', 'prior_box', 'prior_box_var', 'background_label', 'overlap_threshold', 'neg_pos_ratio', 'neg_overlap', 'loc_loss_weight', 'conf_loss_weight', 'match_type', 'mining_type', 'normalize', 'sample_size'], varargs=None, keywords=None, defaults=(None, 0, 0.5, 3.0, 0.5, 1.0, 1.0, 'per_prediction', 'max_negative', True, None))
paddle.fluid.layers.detection_map ArgSpec(args=['detect_res', 'label', 'class_num', 'background_label', 'overlap_threshold', 'evaluate_difficult', 'has_state', 'input_states', 'out_states', 'ap_version'], varargs=None, keywords=None, defaults=(0, 0.3, True, None, None, None, 'integral'))
paddle.fluid.layers.detection_map ArgSpec(args=['detect_res', 'label', 'class_num', 'background_label', 'overlap_threshold', 'evaluate_difficult', 'has_state', 'input_states', 'out_states', 'ap_version'], varargs=None, keywords=None, defaults=(0, 0.3, True, None, None, None, 'integral'))
paddle.fluid.layers.rpn_target_assign ArgSpec(args=['loc', 'scores', 'anchor_box', 'gt_box', 'rpn_batch_size_per_im', 'fg_fraction', 'rpn_positive_overlap', 'rpn_negative_overlap'], varargs=None, keywords=None, defaults=(256, 0.25, 0.7, 0.3))
paddle.fluid.layers.rpn_target_assign ArgSpec(args=['loc', 'scores', 'anchor_box', '
anchor_var', '
gt_box', 'rpn_batch_size_per_im', 'fg_fraction', 'rpn_positive_overlap', 'rpn_negative_overlap'], varargs=None, keywords=None, defaults=(256, 0.25, 0.7, 0.3))
paddle.fluid.layers.anchor_generator ArgSpec(args=['input', 'anchor_sizes', 'aspect_ratios', 'variance', 'stride', 'offset', 'name'], varargs=None, keywords=None, defaults=(None, None, [0.1, 0.1, 0.2, 0.2], None, 0.5, None))
paddle.fluid.layers.anchor_generator ArgSpec(args=['input', 'anchor_sizes', 'aspect_ratios', 'variance', 'stride', 'offset', 'name'], varargs=None, keywords=None, defaults=(None, None, [0.1, 0.1, 0.2, 0.2], None, 0.5, None))
paddle.fluid.layers.generate_proposal_labels ArgSpec(args=['rpn_rois', 'gt_classes', 'gt_boxes', 'im_scales', 'batch_size_per_im', 'fg_fraction', 'fg_thresh', 'bg_thresh_hi', 'bg_thresh_lo', 'bbox_reg_weights', 'class_nums'], varargs=None, keywords=None, defaults=(256, 0.25, 0.25, 0.5, 0.0, [0.1, 0.1, 0.2, 0.2], None))
paddle.fluid.layers.generate_proposal_labels ArgSpec(args=['rpn_rois', 'gt_classes', 'gt_boxes', 'im_scales', 'batch_size_per_im', 'fg_fraction', 'fg_thresh', 'bg_thresh_hi', 'bg_thresh_lo', 'bbox_reg_weights', 'class_nums'], varargs=None, keywords=None, defaults=(256, 0.25, 0.25, 0.5, 0.0, [0.1, 0.1, 0.2, 0.2], None))
paddle.fluid.layers.generate_proposals ArgSpec(args=['scores', 'bbox_deltas', 'im_info', 'anchors', 'variances', 'pre_nms_top_n', 'post_nms_top_n', 'nms_thresh', 'min_size', 'eta', 'name'], varargs=None, keywords=None, defaults=(6000, 1000, 0.5, 0.1, 1.0, None))
paddle.fluid.layers.generate_proposals ArgSpec(args=['scores', 'bbox_deltas', 'im_info', 'anchors', 'variances', 'pre_nms_top_n', 'post_nms_top_n', 'nms_thresh', 'min_size', 'eta', 'name'], varargs=None, keywords=None, defaults=(6000, 1000, 0.5, 0.1, 1.0, None))
...
...
python/paddle/fluid/layers/detection.py
浏览文件 @
1a88baae
...
@@ -58,6 +58,7 @@ for _OP in set(__auto__):
...
@@ -58,6 +58,7 @@ for _OP in set(__auto__):
def
rpn_target_assign
(
loc
,
def
rpn_target_assign
(
loc
,
scores
,
scores
,
anchor_box
,
anchor_box
,
anchor_var
,
gt_box
,
gt_box
,
rpn_batch_size_per_im
=
256
,
rpn_batch_size_per_im
=
256
,
fg_fraction
=
0.25
,
fg_fraction
=
0.25
,
...
@@ -96,6 +97,8 @@ def rpn_target_assign(loc,
...
@@ -96,6 +97,8 @@ def rpn_target_assign(loc,
if the input is image feature map, they are close to the origin
if the input is image feature map, they are close to the origin
of the coordinate system. [xmax, ymax] is the right bottom
of the coordinate system. [xmax, ymax] is the right bottom
coordinate of the anchor box.
coordinate of the anchor box.
anchor_var(Variable): A 2-D Tensor with shape [M,4] holds expanded
variances of anchors.
gt_box (Variable): The ground-truth boudding boxes (bboxes) are a 2D
gt_box (Variable): The ground-truth boudding boxes (bboxes) are a 2D
LoDTensor with shape [Ng, 4], Ng is the total number of ground-truth
LoDTensor with shape [Ng, 4], Ng is the total number of ground-truth
bboxes of mini-batch input.
bboxes of mini-batch input.
...
@@ -145,30 +148,29 @@ def rpn_target_assign(loc,
...
@@ -145,30 +148,29 @@ def rpn_target_assign(loc,
# 1. Compute the regression target bboxes
# 1. Compute the regression target bboxes
target_bbox
=
box_coder
(
target_bbox
=
box_coder
(
prior_box
=
anchor_box
,
prior_box
=
anchor_box
,
prior_box_var
=
anchor_var
,
target_box
=
gt_box
,
target_box
=
gt_box
,
code_type
=
'encode_center_size'
,
code_type
=
'encode_center_size'
,
box_normalized
=
False
)
box_normalized
=
False
)
# 2. Compute overlaps between the prior boxes and the gt boxes overlaps
# 2. Compute overlaps between the prior boxes and the gt boxes overlaps
iou
=
iou_similarity
(
x
=
gt_box
,
y
=
anchor_box
)
iou
=
iou_similarity
(
x
=
gt_box
,
y
=
anchor_box
)
# 3. Assign target label to anchors
# 3. Assign target label to anchors
loc_index
=
helper
.
create_tmp_variable
(
dtype
=
anchor_box
.
dtype
)
loc_index
=
helper
.
create_tmp_variable
(
dtype
=
anchor_box
.
dtype
)
score_index
=
helper
.
create_tmp_variable
(
dtype
=
anchor_box
.
dtype
)
score_index
=
helper
.
create_tmp_variable
(
dtype
=
anchor_box
.
dtype
)
target_label
=
helper
.
create_tmp_variable
(
dtype
=
anchor_box
.
dtype
)
target_label
=
helper
.
create_tmp_variable
(
dtype
=
anchor_box
.
dtype
)
helper
.
append_op
(
helper
.
append_op
(
type
=
"rpn_target_assign"
,
type
=
"rpn_target_assign"
,
inputs
=
{
'
Overlap'
:
iou
,
},
inputs
=
{
'
DistMat'
:
iou
},
outputs
=
{
outputs
=
{
'LocationIndex'
:
loc_index
,
'LocationIndex'
:
loc_index
,
'ScoreIndex'
:
score_index
,
'ScoreIndex'
:
score_index
,
'TargetLabel'
:
target_label
,
'TargetLabel'
:
target_label
},
},
attrs
=
{
attrs
=
{
'rpn_batch_size_per_im'
:
rpn_batch_size_per_im
,
'rpn_batch_size_per_im'
:
rpn_batch_size_per_im
,
'rpn_positive_overlap'
:
rpn_positive_overlap
,
'rpn_positive_overlap'
:
rpn_positive_overlap
,
'rpn_negative_overlap'
:
rpn_negative_overlap
,
'rpn_negative_overlap'
:
rpn_negative_overlap
,
'fg_fraction'
:
fg_fraction
,
'fg_fraction'
:
fg_fraction
})
})
# 4. Reshape and gather the target entry
# 4. Reshape and gather the target entry
...
@@ -181,7 +183,7 @@ def rpn_target_assign(loc,
...
@@ -181,7 +183,7 @@ def rpn_target_assign(loc,
predicted_location
=
nn
.
gather
(
loc
,
loc_index
)
predicted_location
=
nn
.
gather
(
loc
,
loc_index
)
target_label
=
nn
.
gather
(
target_label
,
score_index
)
target_label
=
nn
.
gather
(
target_label
,
score_index
)
target_bbox
=
nn
.
gather
(
target_bbox
,
loc_index
)
target_bbox
=
nn
.
gather
(
target_bbox
,
loc_index
)
return
predicted_scores
,
predicted_loc
,
target_label
,
target_bbox
return
predicted_scores
,
predicted_loc
ation
,
target_label
,
target_bbox
def
detection_output
(
loc
,
def
detection_output
(
loc
,
...
...
python/paddle/fluid/tests/test_detection.py
浏览文件 @
1a88baae
...
@@ -250,6 +250,59 @@ class TestDetectionMAP(unittest.TestCase):
...
@@ -250,6 +250,59 @@ class TestDetectionMAP(unittest.TestCase):
print
(
str
(
program
))
print
(
str
(
program
))
class
TestRpnTargetAssign
(
unittest
.
TestCase
):
def
test_rpn_target_assign
(
self
):
program
=
Program
()
with
program_guard
(
program
):
loc_shape
=
[
10
,
50
,
4
]
score_shape
=
[
10
,
50
,
2
]
anchor_shape
=
[
50
,
4
]
loc
=
layers
.
data
(
name
=
'loc'
,
shape
=
loc_shape
,
append_batch_size
=
False
,
dtype
=
'float32'
)
scores
=
layers
.
data
(
name
=
'scores'
,
shape
=
score_shape
,
append_batch_size
=
False
,
dtype
=
'float32'
)
anchor_box
=
layers
.
data
(
name
=
'anchor_box'
,
shape
=
anchor_shape
,
append_batch_size
=
False
,
dtype
=
'float32'
)
anchor_var
=
layers
.
data
(
name
=
'anchor_var'
,
shape
=
anchor_shape
,
append_batch_size
=
False
,
dtype
=
'float32'
)
gt_box
=
layers
.
data
(
name
=
'gt_box'
,
shape
=
[
4
],
lod_level
=
1
,
dtype
=
'float32'
)
predicted_scores
,
predicted_location
,
target_label
,
target_bbox
=
layers
.
rpn_target_assign
(
loc
=
loc
,
scores
=
scores
,
anchor_box
=
anchor_box
,
anchor_var
=
anchor_var
,
gt_box
=
gt_box
,
rpn_batch_size_per_im
=
256
,
fg_fraction
=
0.25
,
rpn_positive_overlap
=
0.7
,
rpn_negative_overlap
=
0.3
)
self
.
assertIsNotNone
(
predicted_scores
)
self
.
assertIsNotNone
(
predicted_location
)
self
.
assertIsNotNone
(
target_label
)
self
.
assertIsNotNone
(
target_bbox
)
assert
predicted_scores
.
shape
[
1
]
==
2
assert
predicted_location
.
shape
[
1
]
==
4
assert
predicted_location
.
shape
[
1
]
==
target_bbox
.
shape
[
1
]
print
(
str
(
program
))
class
TestGenerateProposals
(
unittest
.
TestCase
):
class
TestGenerateProposals
(
unittest
.
TestCase
):
def
test_generate_proposals
(
self
):
def
test_generate_proposals
(
self
):
data_shape
=
[
20
,
64
,
64
]
data_shape
=
[
20
,
64
,
64
]
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录