Skip to content

Commit f493268

Browse files
authored
fix generate_proposals (#23797) (#24225)
* test=develop fix generate_proposals
1 parent 28fa467 commit f493268

File tree

3 files changed

+41
-6
lines changed

3 files changed

+41
-6
lines changed

python/paddle/fluid/layers/detection.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2742,7 +2742,8 @@ def generate_proposals(scores,
27422742
nms_thresh=0.5,
27432743
min_size=0.1,
27442744
eta=1.0,
2745-
name=None):
2745+
name=None,
2746+
return_rois_num=False):
27462747
"""
27472748
**Generate proposal Faster-RCNN**
27482749
@@ -2789,7 +2790,10 @@ def generate_proposals(scores,
27892790
width < min_size. The data type must be float32. `0.1` by default.
27902791
eta(float): Apply in adaptive NMS, if adaptive `threshold > 0.5`,
27912792
`adaptive_threshold = adaptive_threshold * eta` in each iteration.
2792-
2793+
return_rois_num(bool): When setting True, it will return a 1D Tensor with shape [N, ] that includes Rois's
2794+
num of each image in one batch. The N is the image's num. For example, the tensor has values [4,5] that represents
2795+
the first image has 4 Rois, the second image has 5 Rois. It only used in rcnn model.
2796+
'False' by default.
27932797
Returns:
27942798
tuple:
27952799
A tuple with format ``(rpn_rois, rpn_roi_probs)``.
@@ -2843,7 +2847,10 @@ def generate_proposals(scores,
28432847
rpn_roi_probs.stop_gradient = True
28442848
rpn_rois_lod.stop_gradient = True
28452849

2846-
return rpn_rois, rpn_roi_probs, rpn_rois_lod
2850+
if return_rois_num:
2851+
return rpn_rois, rpn_roi_probs, rpn_rois_lod
2852+
else:
2853+
return rpn_rois, rpn_roi_probs
28472854

28482855

28492856
def box_clip(input, im_info, name=None):

python/paddle/fluid/tests/test_detection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ def test_generate_proposals(self):
480480
name='bbox_deltas',
481481
shape=[num_anchors * 4, 8, 8],
482482
dtype='float32')
483-
rpn_rois, rpn_roi_probs, _ = fluid.layers.generate_proposals(
483+
rpn_rois, rpn_roi_probs = fluid.layers.generate_proposals(
484484
name='generate_proposals',
485485
scores=scores,
486486
bbox_deltas=bbox_deltas,

python/paddle/fluid/tests/unittests/test_generate_proposals_op.py

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,8 +282,6 @@ def set_data(self):
282282
self.outputs = {
283283
'RpnRois': (self.rpn_rois[0], [self.lod]),
284284
'RpnRoiProbs': (self.rpn_roi_probs[0], [self.lod]),
285-
'RpnRoisLod': (np.asarray(
286-
self.lod, dtype=np.int32))
287285
}
288286

289287
def test_check_output(self):
@@ -328,5 +326,35 @@ def init_test_output(self):
328326
self.nms_thresh, self.min_size, self.eta)
329327

330328

329+
class TestGenerateProposalsOutLodOp(TestGenerateProposalsOp):
330+
def set_data(self):
331+
self.init_test_params()
332+
self.init_test_input()
333+
self.init_test_output()
334+
self.inputs = {
335+
'Scores': self.scores,
336+
'BboxDeltas': self.bbox_deltas,
337+
'ImInfo': self.im_info.astype(np.float32),
338+
'Anchors': self.anchors,
339+
'Variances': self.variances
340+
}
341+
342+
self.attrs = {
343+
'pre_nms_topN': self.pre_nms_topN,
344+
'post_nms_topN': self.post_nms_topN,
345+
'nms_thresh': self.nms_thresh,
346+
'min_size': self.min_size,
347+
'eta': self.eta,
348+
'return_rois_num': True
349+
}
350+
351+
self.outputs = {
352+
'RpnRois': (self.rpn_rois[0], [self.lod]),
353+
'RpnRoiProbs': (self.rpn_roi_probs[0], [self.lod]),
354+
'RpnRoisLod': (np.asarray(
355+
self.lod, dtype=np.int32))
356+
}
357+
358+
331359
if __name__ == '__main__':
332360
unittest.main()

0 commit comments

Comments
 (0)