Skip to content

Commit

Permalink
Fix nonzero warning (#330)
Browse files Browse the repository at this point in the history
* fix nonzero warning with as_tuple

* fix nonzero warning with as_tuple #320
  • Loading branch information
wHao-Wu authored Mar 2, 2021
1 parent ccd3047 commit df505fe
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 9 deletions.
2 changes: 1 addition & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Welcome to MMDetection3D's documentation!
getting_started.md
model_zoo.md
data_preparation.md

.. toctree::
:maxdepth: 2
:caption: Quick Run
Expand Down
3 changes: 2 additions & 1 deletion mmdet3d/models/dense_heads/anchor3d_head.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,8 @@ def loss_single(self, cls_score, bbox_pred, dir_cls_preds, labels,

bg_class_ind = self.num_classes
pos_inds = ((labels >= 0)
& (labels < bg_class_ind)).nonzero().reshape(-1)
& (labels < bg_class_ind)).nonzero(
as_tuple=False).reshape(-1)
num_pos = len(pos_inds)

pos_bbox_pred = bbox_pred[pos_inds]
Expand Down
3 changes: 2 additions & 1 deletion mmdet3d/models/dense_heads/ssd_3d_head.py
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,8 @@ def multiclass_nms_single(self, obj_scores, sem_scores, bbox, points,

# filter empty boxes and boxes with low score
scores_mask = (obj_scores >= self.test_cfg.score_thr)
nonempty_box_inds = torch.nonzero(nonempty_box_mask).flatten()
nonempty_box_inds = torch.nonzero(
nonempty_box_mask, as_tuple=False).flatten()
nonempty_mask = torch.zeros_like(bbox_classes).scatter(
0, nonempty_box_inds[nms_selected], 1)
selected = (nonempty_mask.bool() & scores_mask.bool())
Expand Down
8 changes: 4 additions & 4 deletions mmdet3d/models/dense_heads/train_mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,11 +277,11 @@ def anchor_target_single_assigner(self,
neg_inds = sampling_result.neg_inds
else:
pos_inds = torch.nonzero(
anchors.new_zeros((anchors.shape[0], ), dtype=torch.bool) > 0
).squeeze(-1).unique()
anchors.new_zeros((anchors.shape[0], ), dtype=torch.bool) > 0,
as_tuple=False).squeeze(-1).unique()
neg_inds = torch.nonzero(
anchors.new_zeros((anchors.shape[0], ), dtype=torch.bool) ==
0).squeeze(-1).unique()
anchors.new_zeros((anchors.shape[0], ), dtype=torch.bool) == 0,
as_tuple=False).squeeze(-1).unique()

if gt_labels is not None:
labels += num_classes
Expand Down
3 changes: 2 additions & 1 deletion mmdet3d/models/roi_heads/bbox_heads/h3d_bbox_head.py
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,8 @@ def multiclass_nms_single(self, obj_scores, sem_scores, bbox, points,

# filter empty boxes and boxes with low score
scores_mask = (obj_scores > self.test_cfg.score_thr)
nonempty_box_inds = torch.nonzero(nonempty_box_mask).flatten()
nonempty_box_inds = torch.nonzero(
nonempty_box_mask, as_tuple=False).flatten()
nonempty_mask = torch.zeros_like(bbox_classes).scatter(
0, nonempty_box_inds[nms_selected], 1)
selected = (nonempty_mask.bool() & scores_mask.bool())
Expand Down
2 changes: 1 addition & 1 deletion mmdet3d/models/roi_heads/mask_heads/primitive_head.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ def get_targets_single(self,
pts_instance_mask[background_mask] = gt_labels_3d.shape[0]

instance_flag = torch.nonzero(
pts_semantic_mask != self.num_classes).squeeze(1)
pts_semantic_mask != self.num_classes, as_tuple=False).squeeze(1)
instance_labels = pts_instance_mask[instance_flag].unique()

with_yaw = gt_bboxes_3d.with_yaw
Expand Down

0 comments on commit df505fe

Please sign in to comment.