"...git@developer.sourcefind.cn:renzhc/diffusers_dcu.git" did not exist on "56f740051dae2d410677292a5c9e5b66e60f87dc"
Unverified Commit f6a7d78c authored by Wenwei Zhang's avatar Wenwei Zhang Committed by GitHub
Browse files

Fix (torch.nonzero): Fix warning of torch.nonzero and bug of nms_iou (#70)

parent 3ba50ca5
...@@ -55,7 +55,7 @@ class IoUNegPiecewiseSampler(RandomSampler): ...@@ -55,7 +55,7 @@ class IoUNegPiecewiseSampler(RandomSampler):
def _sample_neg(self, assign_result, num_expected, **kwargs): def _sample_neg(self, assign_result, num_expected, **kwargs):
"""Randomly sample some negative samples.""" """Randomly sample some negative samples."""
neg_inds = torch.nonzero(assign_result.gt_inds == 0) neg_inds = torch.nonzero(assign_result.gt_inds == 0, as_tuple=False)
if neg_inds.numel() != 0: if neg_inds.numel() != 0:
neg_inds = neg_inds.squeeze(1) neg_inds = neg_inds.squeeze(1)
if len(neg_inds) <= num_expected: if len(neg_inds) <= num_expected:
...@@ -80,7 +80,8 @@ class IoUNegPiecewiseSampler(RandomSampler): ...@@ -80,7 +80,8 @@ class IoUNegPiecewiseSampler(RandomSampler):
max_iou_thr = self.neg_iou_thr[piece_inds] max_iou_thr = self.neg_iou_thr[piece_inds]
piece_neg_inds = torch.nonzero( piece_neg_inds = torch.nonzero(
(max_overlaps >= min_iou_thr) (max_overlaps >= min_iou_thr)
& (max_overlaps < max_iou_thr)).view(-1) & (max_overlaps < max_iou_thr),
as_tuple=False).view(-1)
if len(piece_neg_inds) < piece_expected_num: if len(piece_neg_inds) < piece_expected_num:
neg_inds_choice = torch.cat( neg_inds_choice = torch.cat(
......
...@@ -129,7 +129,8 @@ def aligned_3d_nms(boxes, scores, classes, thresh): ...@@ -129,7 +129,8 @@ def aligned_3d_nms(boxes, scores, classes, thresh):
inter = inter_l * inter_w * inter_h inter = inter_l * inter_w * inter_h
iou = inter / (area[i] + area[score_sorted[:last - 1]] - inter) iou = inter / (area[i] + area[score_sorted[:last - 1]] - inter)
iou = iou * (classes1 == classes2).float() iou = iou * (classes1 == classes2).float()
score_sorted = score_sorted[torch.nonzero(iou <= thresh).flatten()] score_sorted = score_sorted[torch.nonzero(
iou <= thresh, as_tuple=False).flatten()]
indices = boxes.new_tensor(pick, dtype=torch.long) indices = boxes.new_tensor(pick, dtype=torch.long)
return indices return indices
...@@ -140,7 +140,7 @@ class FreeAnchor3DHead(Anchor3DHead): ...@@ -140,7 +140,7 @@ class FreeAnchor3DHead(Anchor3DHead):
box_cls_prob = torch.sparse.sum( box_cls_prob = torch.sparse.sum(
object_cls_box_prob, dim=0).to_dense() object_cls_box_prob, dim=0).to_dense()
indices = torch.nonzero(box_cls_prob).t_() indices = torch.nonzero(box_cls_prob, as_tuple=False).t_()
if indices.numel() == 0: if indices.numel() == 0:
image_box_prob = torch.zeros( image_box_prob = torch.zeros(
anchors_.size(0), anchors_.size(0),
......
...@@ -409,7 +409,8 @@ class VoteHead(nn.Module): ...@@ -409,7 +409,8 @@ class VoteHead(nn.Module):
box_indices_all = gt_bboxes_3d.points_in_boxes(points) box_indices_all = gt_bboxes_3d.points_in_boxes(points)
for i in range(gt_labels_3d.shape[0]): for i in range(gt_labels_3d.shape[0]):
box_indices = box_indices_all[:, i] box_indices = box_indices_all[:, i]
indices = torch.nonzero(box_indices).squeeze(-1) indices = torch.nonzero(
box_indices, as_tuple=False).squeeze(-1)
selected_points = points[indices] selected_points = points[indices]
vote_target_masks[indices] = 1 vote_target_masks[indices] = 1
vote_targets_tmp = vote_targets[indices] vote_targets_tmp = vote_targets[indices]
...@@ -418,7 +419,8 @@ class VoteHead(nn.Module): ...@@ -418,7 +419,8 @@ class VoteHead(nn.Module):
for j in range(self.gt_per_seed): for j in range(self.gt_per_seed):
column_indices = torch.nonzero( column_indices = torch.nonzero(
vote_target_idx[indices] == j).squeeze(-1) vote_target_idx[indices] == j,
as_tuple=False).squeeze(-1)
vote_targets_tmp[column_indices, vote_targets_tmp[column_indices,
int(j * 3):int(j * 3 + int(j * 3):int(j * 3 +
3)] = votes[column_indices] 3)] = votes[column_indices]
...@@ -435,7 +437,8 @@ class VoteHead(nn.Module): ...@@ -435,7 +437,8 @@ class VoteHead(nn.Module):
dtype=torch.long) dtype=torch.long)
for i in torch.unique(pts_instance_mask): for i in torch.unique(pts_instance_mask):
indices = torch.nonzero(pts_instance_mask == i).squeeze(-1) indices = torch.nonzero(
pts_instance_mask == i, as_tuple=False).squeeze(-1)
if pts_semantic_mask[indices[0]] < self.num_classes: if pts_semantic_mask[indices[0]] < self.num_classes:
selected_points = points[indices, :3] selected_points = points[indices, :3]
center = 0.5 * ( center = 0.5 * (
...@@ -558,7 +561,8 @@ class VoteHead(nn.Module): ...@@ -558,7 +561,8 @@ class VoteHead(nn.Module):
# filter empty boxes and boxes with low score # filter empty boxes and boxes with low score
scores_mask = (obj_scores > self.test_cfg.score_thr) 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( nonempty_mask = torch.zeros_like(bbox_classes).scatter(
0, nonempty_box_inds[nms_selected], 1) 0, nonempty_box_inds[nms_selected], 1)
selected = (nonempty_mask.bool() & scores_mask.bool()) selected = (nonempty_mask.bool() & scores_mask.bool())
......
...@@ -37,7 +37,7 @@ def nms_gpu(boxes, scores, thresh): ...@@ -37,7 +37,7 @@ def nms_gpu(boxes, scores, thresh):
boxes = boxes[order].contiguous() boxes = boxes[order].contiguous()
keep = boxes.new_zeros(boxes.size(0)) keep = torch.zeros(boxes.size(0), dtype=torch.long)
num_out = iou3d_cuda.nms_gpu(boxes, keep, thresh, boxes.device.index) num_out = iou3d_cuda.nms_gpu(boxes, keep, thresh, boxes.device.index)
return order[keep[:num_out].cuda(boxes.device)].contiguous() return order[keep[:num_out].cuda(boxes.device)].contiguous()
...@@ -57,7 +57,7 @@ def nms_normal_gpu(boxes, scores, thresh): ...@@ -57,7 +57,7 @@ def nms_normal_gpu(boxes, scores, thresh):
boxes = boxes[order].contiguous() boxes = boxes[order].contiguous()
keep = boxes.new_zeros(boxes.size(0)) keep = torch.zeros(boxes.size(0), dtype=torch.long)
num_out = iou3d_cuda.nms_normal_gpu(boxes, keep, thresh, num_out = iou3d_cuda.nms_normal_gpu(boxes, keep, thresh,
boxes.device.index) boxes.device.index)
return order[keep[:num_out].cuda(boxes.device)].contiguous() return order[keep[:num_out].cuda(boxes.device)].contiguous()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment