Example #1
0
    def get_det_bboxes(self,
                       rois,
                       cls_score,
                       bbox_pred,
                       img_shape,
                       scale_factor,
                       rescale=False,
                       cfg=None):
        if isinstance(cls_score, list):
            cls_score = sum(cls_score) / float(len(cls_score))
        scores = F.softmax(cls_score, dim=1) if cls_score is not None else None

        # TODO: check and simplify it
        if rois.size(1) == 5:
            obbs = hbb2obb_v2(rois[:, 1:])
        elif rois.size(1) == 6:
            obbs = rois[:, 1:]
        else:
            print('strange size')
            import pdb
            pdb.set_trace()
        if bbox_pred is not None:
            # bboxes = delta2dbbox(rois[:, 1:], bbox_pred, self.target_means,
            #                     self.target_stds, img_shape)
            if self.with_module:
                dbboxes = delta2dbbox(obbs, bbox_pred, self.target_means,
                                      self.target_stds, img_shape)
            else:
                dbboxes = delta2dbbox_v3(obbs, bbox_pred, self.target_means,
                                         self.target_stds, img_shape)
        else:
            # bboxes = rois[:, 1:]
            dbboxes = obbs
            # TODO: add clip here

        if rescale:
            # bboxes /= scale_factor
            # dbboxes[:, :4] /= scale_factor
            dbboxes[:, 0::5] /= scale_factor
            dbboxes[:, 1::5] /= scale_factor
            dbboxes[:, 2::5] /= scale_factor
            dbboxes[:, 3::5] /= scale_factor
        # if cfg is None:
        #     c_device = dbboxes.device
        #
        #     det_bboxes, det_labels = Pesudomulticlass_nms_rbbox(dbboxes, scores,
        #                                             0.05,
        #                                             1000)
        #
        #     return det_bboxes, det_labels
        # else:
        c_device = dbboxes.device

        det_bboxes, det_labels = multiclass_nms_rbbox(dbboxes, scores,
                                                      cfg.score_thr, cfg.nms,
                                                      cfg.max_per_img)
        # det_bboxes = torch.from_numpy(det_bboxes).to(c_device)
        # det_labels = torch.from_numpy(det_labels).to(c_device)
        return det_bboxes, det_labels
Example #2
0
    def get_det_bboxes(self,
                       rois,
                       cls_score,
                       bbox_pred,
                       img_shape,
                       scale_factor,
                       rescale=False,
                       cfg=None):
        if isinstance(cls_score, list):
            cls_score = sum(cls_score) / float(len(cls_score))
        scores = F.softmax(cls_score, dim=1) if cls_score is not None else None

        # TODO: check and simplify it
        if rois.size(1) == 5:
            obbs = hbb2obb_v2(rois[:, 1:])
        elif rois.size(1) == 6:
            obbs = rois[:, 1:]
        else:
            print('strange size')
            import pdb
            pdb.set_trace()
        if bbox_pred is not None:
            # bboxes = delta2dbbox(rois[:, 1:], bbox_pred, self.target_means,
            #                     self.target_stds, img_shape)
            if self.with_module:
                dbboxes = delta2dbbox(obbs, bbox_pred, self.target_means,
                                      self.target_stds, img_shape)
            else:
                dbboxes = delta2dbbox_v3(obbs, bbox_pred, self.target_means,
                                         self.target_stds, img_shape)
        else:
            # bboxes = rois[:, 1:]
            dbboxes = obbs
            # TODO: add clip here

        if rescale:
            # bboxes /= scale_factor
            # dbboxes[:, :4] /= scale_factor
            dbboxes[:, 0::5] /= scale_factor
            dbboxes[:, 1::5] /= scale_factor
            dbboxes[:, 2::5] /= scale_factor
            dbboxes[:, 3::5] /= scale_factor
        # if cfg is None:
        #     c_device = dbboxes.device
        #
        #     det_bboxes, det_labels = Pesudomulticlass_nms_rbbox(dbboxes, scores,
        #                                             0.05,
        #                                             1000)
        #
        #     return det_bboxes, det_labels
        # else:
        c_device = dbboxes.device

        det_bboxes, det_labels = multiclass_nms_rbbox(dbboxes, scores,
                                                cfg.score_thr, cfg.nms,
                                                cfg.max_per_img)
        # det_bboxes = torch.from_numpy(det_bboxes).to(c_device)
        # det_labels = torch.from_numpy(det_labels).to(c_device)

        # ###########################################################
        from mmdet.MARK import PRINT_RBBOX_HEAD_RS_LOSS
        if PRINT_RBBOX_HEAD_RS_LOSS:
            # pos_inds = pos_inds[0:min(len(pos_inds), 10)]
            pred_score = scores
            pred_score, pred_label = torch.max(pred_score, dim=1)

            # 前景标签
            pred_f_indices = pred_label != 0

            if torch.sum(pred_f_indices) > 0:
                print('#' * 80)
                print('for pred score: ', pred_score[pred_f_indices])
                print('#' * 80)
        # ###########################################################

        return det_bboxes, det_labels