当前位置: 首页>>代码示例>>Python>>正文


Python boxes.bbox_overlaps方法代码示例

本文整理汇总了Python中detectron.utils.boxes.bbox_overlaps方法的典型用法代码示例。如果您正苦于以下问题:Python boxes.bbox_overlaps方法的具体用法?Python boxes.bbox_overlaps怎么用?Python boxes.bbox_overlaps使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在detectron.utils.boxes的用法示例。


在下文中一共展示了boxes.bbox_overlaps方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_cython_bbox_iou_against_coco_api_bbox_iou

# 需要导入模块: from detectron.utils import boxes [as 别名]
# 或者: from detectron.utils.boxes import bbox_overlaps [as 别名]
def test_cython_bbox_iou_against_coco_api_bbox_iou(self):
        """Check that our cython implementation of bounding box IoU overlap
        matches the COCO API implementation.
        """
        def _do_test(b1, b2):
            # Compute IoU overlap with the cython implementation
            cython_iou = box_utils.bbox_overlaps(b1, b2)
            # Compute IoU overlap with the COCO API implementation
            # (requires converting boxes from xyxy to xywh format)
            xywh_b1 = box_utils.xyxy_to_xywh(b1)
            xywh_b2 = box_utils.xyxy_to_xywh(b2)
            not_crowd = [int(False)] * b2.shape[0]
            coco_ious = COCOmask.iou(xywh_b1, xywh_b2, not_crowd)
            # IoUs should be similar
            np.testing.assert_array_almost_equal(
                cython_iou, coco_ious, decimal=5
            )

        # Test small boxes
        b1 = random_boxes([10, 10, 20, 20], 5, 10)
        b2 = random_boxes([10, 10, 20, 20], 5, 10)
        _do_test(b1, b2)

        # Test bigger boxes
        b1 = random_boxes([10, 10, 110, 20], 20, 10)
        b2 = random_boxes([10, 10, 110, 20], 20, 10)
        _do_test(b1, b2) 
开发者ID:yihui-he,项目名称:KL-Loss,代码行数:29,代码来源:test_bbox_transform.py

示例2: compute_bbox_regression_targets

# 需要导入模块: from detectron.utils import boxes [as 别名]
# 或者: from detectron.utils.boxes import bbox_overlaps [as 别名]
def compute_bbox_regression_targets(entry):
    """Compute bounding-box regression targets for an image."""
    # Indices of ground-truth ROIs
    rois = entry['boxes']
    overlaps = entry['max_overlaps']
    labels = entry['max_classes']
    gt_inds = np.where((entry['gt_classes'] > 0) & (entry['is_crowd'] == 0))[0]
    # Targets has format (class, tx, ty, tw, th)
    targets = np.zeros((rois.shape[0], 5), dtype=np.float32)
    if len(gt_inds) == 0:
        # Bail if the image has no ground-truth ROIs
        return targets

    # Indices of examples for which we try to make predictions
    ex_inds = np.where(overlaps >= cfg.TRAIN.BBOX_THRESH)[0]

    # Get IoU overlap between each ex ROI and gt ROI
    ex_gt_overlaps = box_utils.bbox_overlaps(
        rois[ex_inds, :].astype(dtype=np.float32, copy=False),
        rois[gt_inds, :].astype(dtype=np.float32, copy=False))

    # Find which gt ROI each ex ROI has max overlap with:
    # this will be the ex ROI's gt target
    gt_assignment = ex_gt_overlaps.argmax(axis=1)
    gt_rois = rois[gt_inds[gt_assignment], :]
    ex_rois = rois[ex_inds, :]
    # Use class "1" for all boxes if using class_agnostic_bbox_reg
    targets[ex_inds, 0] = (
        1 if cfg.MODEL.CLS_AGNOSTIC_BBOX_REG else labels[ex_inds])
    targets[ex_inds, 1:] = box_utils.bbox_transform_inv(
        ex_rois, gt_rois, cfg.MODEL.BBOX_REG_WEIGHTS)
    return targets 
开发者ID:yihui-he,项目名称:KL-Loss,代码行数:34,代码来源:roidb.py

示例3: forward

# 需要导入模块: from detectron.utils import boxes [as 别名]
# 或者: from detectron.utils.boxes import bbox_overlaps [as 别名]
def forward(self, inputs, outputs):
        """See modeling.detector.AddBBoxAccuracy for inputs/outputs
        documentation.
        """

        # predicted bbox deltas
        bbox_deltas = inputs[0].data
        # proposals
        bbox_data = inputs[1].data
        assert bbox_data.shape[1] == 5
        bbox_prior = bbox_data[:, 1:]
        # labels
        labels = inputs[2].data
        # mapped gt boxes
        mapped_gt_boxes = inputs[3].data
        gt_boxes = mapped_gt_boxes[:, :4]
        max_overlap = mapped_gt_boxes[:, 4]

        # bbox iou only for fg and non-gt boxes
        keep_inds = np.where((labels > 0) & (max_overlap < 1.0))[0]
        num_boxes = keep_inds.size
        bbox_deltas = bbox_deltas[keep_inds, :]
        bbox_prior = bbox_prior[keep_inds, :]
        labels = labels[keep_inds]
        gt_boxes = gt_boxes[keep_inds, :]
        max_overlap = max_overlap[keep_inds]

        if cfg.MODEL.CLS_AGNOSTIC_BBOX_REG or num_boxes == 0:
            bbox_deltas = bbox_deltas[:, -4:]
        else:
            bbox_deltas = np.vstack(
                [
                    bbox_deltas[i, labels[i] * 4: labels[i] * 4 + 4]
                    for i in range(num_boxes)
                ]
            )
        pred_boxes = box_utils.bbox_transform(
            bbox_prior, bbox_deltas, self._bbox_reg_weights
        )

        avg_iou = 0.
        pre_avg_iou = sum(max_overlap)
        for i in range(num_boxes):
            gt_box = gt_boxes[i, :]
            pred_box = pred_boxes[i, :]
            tmp_iou = box_utils.bbox_overlaps(
                gt_box[np.newaxis, :].astype(dtype=np.float32, copy=False),
                pred_box[np.newaxis, :].astype(dtype=np.float32, copy=False),
            )
            avg_iou += tmp_iou[0]
        if num_boxes > 0:
            avg_iou /= num_boxes
            pre_avg_iou /= num_boxes
        outputs[0].reshape([1])
        outputs[0].data[...] = avg_iou
        outputs[1].reshape([1])
        outputs[1].data[...] = pre_avg_iou 
开发者ID:fyangneil,项目名称:Clustered-Object-Detection-in-Aerial-Image,代码行数:59,代码来源:bbox_accuracy.py


注:本文中的detectron.utils.boxes.bbox_overlaps方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。