Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix] Fix potential gradient divergence of corner_loss in PointRCNN #1224

Merged
merged 1 commit into from
Feb 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions configs/_base_/models/point_rcnn.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,23 +91,26 @@
pos_iou_thr=0.55,
neg_iou_thr=0.55,
min_pos_iou=0.55,
ignore_iof_thr=-1),
ignore_iof_thr=-1,
match_low_quality=False),
dict( # for Pedestrian
type='MaxIoUAssigner',
iou_calculator=dict(
type='BboxOverlaps3D', coordinate='lidar'),
pos_iou_thr=0.55,
neg_iou_thr=0.55,
min_pos_iou=0.55,
ignore_iof_thr=-1),
ignore_iof_thr=-1,
match_low_quality=False),
dict( # for Cyclist
type='MaxIoUAssigner',
iou_calculator=dict(
type='BboxOverlaps3D', coordinate='lidar'),
pos_iou_thr=0.55,
neg_iou_thr=0.55,
min_pos_iou=0.55,
ignore_iof_thr=-1)
ignore_iof_thr=-1,
match_low_quality=False)
],
sampler=dict(
type='IoUNegPiecewiseSampler',
Expand Down
4 changes: 1 addition & 3 deletions mmdet3d/core/bbox/samplers/iou_neg_piecewise_sampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,7 @@ def _sample_neg(self, assign_result, num_expected, **kwargs):
if neg_inds.numel() != 0:
neg_inds = neg_inds.squeeze(1)
if len(neg_inds) <= 0:
raise NotImplementedError(
'Not support sampling the negative samples when the length '
'of negative samples is 0')
return neg_inds.squeeze(1)
else:
neg_inds_choice = neg_inds.new_zeros([0])
extend_num = 0
Expand Down
29 changes: 27 additions & 2 deletions mmdet3d/models/dense_heads/point_rpn_head.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,15 +272,17 @@ def get_bboxes(self,
bbox3d = self.bbox_coder.decode(bbox_preds[b], points[b, ..., :3],
object_class[b])
bbox_selected, score_selected, labels, cls_preds_selected = \
self.class_agnostic_nms(obj_scores[b], sem_scores[b], bbox3d)
self.class_agnostic_nms(obj_scores[b], sem_scores[b], bbox3d,
points[b, ..., :3], input_metas[b])
bbox = input_metas[b]['box_type_3d'](
bbox_selected.clone(),
box_dim=bbox_selected.shape[-1],
with_yaw=True)
results.append((bbox, score_selected, labels, cls_preds_selected))
return results

def class_agnostic_nms(self, obj_scores, sem_scores, bbox):
def class_agnostic_nms(self, obj_scores, sem_scores, bbox, points,
input_meta):
"""Class agnostic nms.

Args:
Expand All @@ -298,6 +300,29 @@ def class_agnostic_nms(self, obj_scores, sem_scores, bbox):
else:
nms_func = nms_normal_gpu

num_bbox = bbox.shape[0]
bbox = input_meta['box_type_3d'](
bbox.clone(),
box_dim=bbox.shape[-1],
with_yaw=True,
origin=(0.5, 0.5, 0.5))

if isinstance(bbox, LiDARInstance3DBoxes):
box_idx = bbox.points_in_boxes(points)
box_indices = box_idx.new_zeros([num_bbox + 1])
box_idx[box_idx == -1] = num_bbox
box_indices.scatter_add_(0, box_idx.long(),
box_idx.new_ones(box_idx.shape))
box_indices = box_indices[:-1]
nonempty_box_mask = box_indices >= 0
elif isinstance(bbox, DepthInstance3DBoxes):
box_indices = bbox.points_in_boxes(points)
nonempty_box_mask = box_indices.T.sum(1) >= 0
else:
raise NotImplementedError('Unsupported bbox type!')

bbox = bbox.tensor[nonempty_box_mask]

if self.test_cfg.score_thr is not None:
score_thr = self.test_cfg.score_thr
keep = (obj_scores >= score_thr)
Expand Down