Skip to content

Commit dc2f428

Browse files
committed
update code from review comments, test=develop
1 parent 234f8af commit dc2f428

File tree

4 files changed

+18
-15
lines changed

4 files changed

+18
-15
lines changed

paddle/fluid/operators/detection/bbox_util.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -149,17 +149,18 @@ void ClipTiledBoxes(const platform::DeviceContext& ctx,
149149
}
150150
}
151151

152+
// Calculate max IoU between each box and ground-truth and
153+
// each row represents one box
152154
template <typename T>
153-
void MaxOverlaps(const framework::Tensor& iou,
154-
framework::Tensor* max_overlaps) {
155-
const T* proposal_to_gt_overlaps = iou.data<T>();
155+
void MaxIoU(const framework::Tensor& iou, framework::Tensor* max_iou) {
156+
const T* iou_data = iou.data<T>();
156157
int row = iou.dims()[0];
157158
int col = iou.dims()[1];
158-
T* max_overlaps_dt = max_overlaps->data<T>();
159+
T* max_iou_data = max_iou->data<T>();
159160
for (int i = 0; i < row; ++i) {
160-
const T* v = proposal_to_gt_overlaps + i * col;
161+
const T* v = iou_data + i * col;
161162
T max_v = *std::max_element(v, v + col);
162-
max_overlaps_dt[i] = max_v;
163+
max_iou_data[i] = max_v;
163164
}
164165
}
165166

paddle/fluid/operators/detection/generate_proposal_labels_op.cc

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ void AppendRois(LoDTensor* out, int64_t offset, Tensor* to_add) {
3333
memcpy(out_data + offset, to_add_data, to_add->numel() * sizeof(T));
3434
}
3535

36+
// Filter the ground-truth in RoIs and the RoIs with non-positive area.
37+
// The ground-truth has max overlap with itself so the max_overlap is 1
38+
// and the corresponding RoI will be removed.
3639
template <typename T>
3740
void FilterRoIs(const platform::DeviceContext& ctx, const Tensor& rpn_rois,
3841
const Tensor& max_overlap, Tensor* keep) {
@@ -354,7 +357,7 @@ std::vector<Tensor> SampleRoisForOneImage(
354357
proposal_with_max_overlap.mutable_data<T>({proposals_num},
355358
context.GetPlace());
356359

357-
MaxOverlaps<T>(proposal_to_gt_overlaps, &proposal_with_max_overlap);
360+
MaxIoU<T>(proposal_to_gt_overlaps, &proposal_with_max_overlap);
358361

359362
// Generate proposal index
360363
std::vector<std::vector<int>> fg_bg_gt =
@@ -546,7 +549,7 @@ class GenerateProposalLabelsKernel : public framework::OpKernel<T> {
546549
max_overlap_slice =
547550
max_overlap->Slice(rpn_rois_lod[i], rpn_rois_lod[i + 1]);
548551
} else {
549-
max_overlap_slice.mutable_data<T>(im_info_slice.dims(),
552+
max_overlap_slice.mutable_data<T>({rpn_rois_slice.dims()[0]},
550553
context.GetPlace());
551554
}
552555
std::vector<Tensor> tensor_output = SampleRoisForOneImage<T>(
@@ -620,8 +623,8 @@ class GenerateProposalLabelsOpMaker : public framework::OpProtoAndCheckerMaker {
620623
AddInput("MaxOverlap",
621624
"(LoDTensor), This input is a 1D LoDTensor with shape [N]."
622625
"N is the number of Input(RpnRois), "
623-
"each element is the maxoverlap between "
624-
"the input RoIs and ground-truth.")
626+
"each element is the maximum overlap between "
627+
"the proposal RoI and ground-truth.")
625628
.AsDispensable();
626629

627630
AddOutput(

python/paddle/fluid/layers/detection.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2640,8 +2640,8 @@ def generate_proposal_labels(rpn_rois,
26402640
use_random(bool): Use random sampling to choose foreground and background boxes.
26412641
is_cls_agnostic(bool): bbox regression use class agnostic simply which only represent fg and bg boxes.
26422642
is_cascade_rcnn(bool): it will filter some bbox crossing the image's boundary when setting True.
2643-
max_overlap(Variable): Maximum overlap between each Input box and ground-truth.
2644-
return_max_overlap(bool): Whether return the maximum overlap between each Output box and ground-truth.
2643+
max_overlap(Variable): Maximum overlap between each proposal box and ground-truth.
2644+
return_max_overlap(bool): Whether return the maximum overlap between each sampled RoI and ground-truth.
26452645
26462646
Returns:
26472647
tuple:
@@ -2652,7 +2652,7 @@ def generate_proposal_labels(rpn_rois,
26522652
- **bbox_targets**: 2-D LoDTensor with shape ``[batch_size_per_im * batch_size, 4 * class_num]``. The regression targets of all RoIs. The data type is the same as ``rpn_rois``.
26532653
- **bbox_inside_weights**: 2-D LoDTensor with shape ``[batch_size_per_im * batch_size, 4 * class_num]``. The weights of foreground boxes' regression loss. The data type is the same as ``rpn_rois``.
26542654
- **bbox_outside_weights**: 2-D LoDTensor with shape ``[batch_size_per_im * batch_size, 4 * class_num]``. The weights of regression loss. The data type is the same as ``rpn_rois``.
2655-
- **max_overlap**: 1-D LoDTensor with shape ``[P]``. P is the number of output ``rois``. The maximum overlap between each output box and ground-truth.
2655+
- **max_overlap**: 1-D LoDTensor with shape ``[P]``. P is the number of output ``rois``. The maximum overlap between each sampled RoI and ground-truth.
26562656
26572657
Examples:
26582658
.. code-block:: python

python/paddle/fluid/tests/test_detection.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,8 +318,7 @@ def test_generate_proposal_labels(self):
318318
name='is_crowd', shape=[6], dtype='int32', lod_level=1)
319319
gt_boxes = fluid.data(
320320
name='gt_boxes', shape=[6, 4], dtype='float32', lod_level=1)
321-
im_info = fluid.data(
322-
name='im_info', shape=[1, 3], dtype='float32', lod_level=1)
321+
im_info = fluid.data(name='im_info', shape=[1, 3], dtype='float32')
323322
max_overlap = fluid.data(
324323
name='max_overlap', shape=[4], dtype='float32', lod_level=1)
325324
self.class_nums = 5

0 commit comments

Comments
 (0)