Example #1
0
    def get_rescore_bboxes(self, guided_anchors, cls_scores, anchor_labels,
                           img_metas, cfg):

        det_bboxes = list()
        det_scores = list()
        det_labels = list()

        for i in range(len(img_metas)):
            bbox_pred = guided_anchors[i]
            scores = cls_scores[i]
            labels = anchor_labels[i]

            if scores.numel() == 0:

                det_bboxes.append(None)
                det_scores.append(None)
                det_labels.append(None)

                continue

            bbox_pred = bbox_pred.view(-1, 7)
            scores = torch.sigmoid(scores).view(-1)
            select = scores > cfg.score_thr

            bbox_pred = bbox_pred[select, :]
            scores = scores[select]
            labels = labels[select]

            if scores.numel() == 0:

                det_bboxes.append(None)
                det_scores.append(None)
                det_labels.append(None)

                continue

            boxes_for_nms = boxes3d_to_bev_torch(bbox_pred)
            keep = rotate_nms_torch(boxes_for_nms,
                                    scores,
                                    iou_threshold=cfg.nms.iou_thr)

            bbox_pred = bbox_pred[keep, :]
            scores = scores[keep]
            labels = labels[keep]

            det_bboxes.append(bbox_pred.detach().cpu().numpy())
            det_scores.append(scores.detach().cpu().numpy())
            det_labels.append(labels.detach().cpu().numpy())

        return det_bboxes, det_scores, det_labels
Example #2
0
    def get_det_bboxes(self, rois, cls_scores, bbox_preds, img_metas, cfg):

        det_bboxes = list()
        det_scores = list()

        for i in range(len(img_metas)):
            inds = torch.nonzero(rois[:, 0] == i).squeeze()
            roi = rois[inds, 1:]
            scores = cls_scores[inds, :]

            if bbox_preds is not None:
                bbox_pred = bbox_preds[inds, :]
            else:
                bbox_pred = roi

            scores = torch.sigmoid(scores).view(-1)

            select = scores > cfg.score_thr
            bbox_pred = bbox_pred[select, :]
            roi = roi[select, :]
            scores = scores[select]

            if scores.numel() == 0:
                det_bboxes.append(bbox_pred)
                det_scores.append(scores)
                continue

            if bbox_preds is not None:
                bbox_pred = delta2rbbox3d(roi, bbox_pred, self.target_means,
                                          self.target_stds)

            boxes_for_nms = boxes3d_to_bev_torch(bbox_pred)
            keep = rotate_nms_torch(boxes_for_nms,
                                    scores,
                                    iou_threshold=cfg.nms.iou_thr)

            bbox_pred = bbox_pred[keep, :]
            scores = scores[keep]

            det_bboxes.append(bbox_pred.detach().cpu().numpy())
            det_scores.append(scores.detach().cpu().numpy())

        return det_bboxes, det_scores
Example #3
0
    def _get_proposals_single(self, rpn_cls_score, rpn_bbox_pred, rpn_dir_pred,
                              anchors, anchor_mask, img_meta, cfg):

        if self.use_sigmoid_cls:
            rpn_cls_score = rpn_cls_score.permute(1, 2,
                                                  0).contiguous().view(-1)
            scores = rpn_cls_score.sigmoid()
        else:
            rpn_cls_score = rpn_cls_score.permute(1, 2,
                                                  0).contiguous().view(-1, 2)
            scores = F.softmax(rpn_cls_score, dim=1)[:, 1]

        rpn_bbox_pred = rpn_bbox_pred.permute(1, 2, 0).contiguous().view(-1, 7)

        rpn_dir_label = torch.max(rpn_dir_pred.view(-1, 2), dim=-1)[1]

        scores = scores[anchor_mask]
        rpn_bbox_pred = rpn_bbox_pred[anchor_mask]
        dir_label = rpn_dir_label[anchor_mask]
        anchors = anchors[anchor_mask]

        #####################################
        # borrow from bbox_head, for expriments

        # select = scores > .3
        #
        # bbox_pred = rpn_bbox_pred[select, :]
        # anchors = anchors[select, :]
        # scores = scores[select]
        #
        # if scores.numel() == 0:
        #     return bbox_pred, scores
        #
        # bboxes = delta2rbbox3d(anchors, bbox_pred, self.target_means,
        #                        self.target_stds)
        #
        # keep = nms_gpu(
        #     boxes3d_to_bev_torch(bboxes), scores, .1)

        # bboxes = bboxes.cpu().numpy()
        # scores = scores.cpu().numpy()
        # from mmdet.models.single_stage_heads.ssd_rotate_head import rotate_nms
        # keep = rotate_nms(bboxes[:, [0, 1, 3, 4, 6]], scores, iou_threshold=.01)

        # det_bboxes = bboxes[keep, :]
        # det_scores = scores[keep]
        #
        # return (det_bboxes, det_scores)

        #####################################

        _, order = scores.sort(0, descending=True)

        if cfg.nms_pre > 0:
            order = order[:cfg.nms_pre]
            rpn_bbox_pred = rpn_bbox_pred[order, :]
            anchors = anchors[order, :]
            scores = scores[order]
            dir_label = dir_label[order]

        proposals = delta2rbbox3d(anchors, rpn_bbox_pred, self.target_means,
                                  self.target_stds)

        keep = nms_gpu(boxes3d_to_bev_torch(proposals), scores, cfg.nms_thr)

        proposals = proposals[keep, :]
        scores = scores[keep]
        dir_label = dir_label[keep]

        proposals = proposals[:cfg.nms_post, :]
        scores = scores[:cfg.nms_post]
        dir_label = dir_label[:cfg.nms_post]

        opp_labels = (proposals[..., -1] > 0) ^ dir_label.byte()
        proposals[opp_labels, -1] += np.pi

        return proposals