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


Python boxes.bbox_transform方法代码示例

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


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

示例1: test_bbox_transform_and_inverse

# 需要导入模块: from detectron.utils import boxes [as 别名]
# 或者: from detectron.utils.boxes import bbox_transform [as 别名]
def test_bbox_transform_and_inverse(self):
        weights = (5, 5, 10, 10)
        src_boxes = random_boxes([10, 10, 20, 20], 1, 10)
        dst_boxes = random_boxes([10, 10, 20, 20], 1, 10)
        deltas = box_utils.bbox_transform_inv(
            src_boxes, dst_boxes, weights=weights
        )
        dst_boxes_reconstructed = box_utils.bbox_transform(
            src_boxes, deltas, weights=weights
        )
        np.testing.assert_array_almost_equal(
            dst_boxes, dst_boxes_reconstructed, decimal=5
        ) 
开发者ID:yihui-he,项目名称:KL-Loss,代码行数:15,代码来源:test_bbox_transform.py

示例2: test_bbox_dataset_to_prediction_roundtrip

# 需要导入模块: from detectron.utils import boxes [as 别名]
# 或者: from detectron.utils.boxes import bbox_transform [as 别名]
def test_bbox_dataset_to_prediction_roundtrip(self):
        """Simulate the process of reading a ground-truth box from a dataset,
        make predictions from proposals, convert the predictions back to the
        dataset format, and then use the COCO API to compute IoU overlap between
        the gt box and the predictions. These should have IoU of 1.
        """
        weights = (5, 5, 10, 10)
        # 1/ "read" a box from a dataset in the default (x1, y1, w, h) format
        gt_xywh_box = [10, 20, 100, 150]
        # 2/ convert it to our internal (x1, y1, x2, y2) format
        gt_xyxy_box = box_utils.xywh_to_xyxy(gt_xywh_box)
        # 3/ consider nearby proposal boxes
        prop_xyxy_boxes = random_boxes(gt_xyxy_box, 10, 10)
        # 4/ compute proposal-to-gt transformation deltas
        deltas = box_utils.bbox_transform_inv(
            prop_xyxy_boxes, np.array([gt_xyxy_box]), weights=weights
        )
        # 5/ use deltas to transform proposals to xyxy predicted box
        pred_xyxy_boxes = box_utils.bbox_transform(
            prop_xyxy_boxes, deltas, weights=weights
        )
        # 6/ convert xyxy predicted box to xywh predicted box
        pred_xywh_boxes = box_utils.xyxy_to_xywh(pred_xyxy_boxes)
        # 7/ use COCO API to compute IoU
        not_crowd = [int(False)] * pred_xywh_boxes.shape[0]
        ious = COCOmask.iou(pred_xywh_boxes, np.array([gt_xywh_box]), not_crowd)
        np.testing.assert_array_almost_equal(ious, np.ones(ious.shape)) 
开发者ID:yihui-he,项目名称:KL-Loss,代码行数:29,代码来源:test_bbox_transform.py

示例3: forward

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

        bbox_deltas = inputs[0].data
        assert cfg.MODEL.CLS_AGNOSTIC_BBOX_REG
        assert bbox_deltas.shape[1] == 8
        bbox_deltas = bbox_deltas[:, -4:]
        bbox_data = inputs[1].data
        assert bbox_data.shape[1] == 5
        batch_inds = bbox_data[:, :1]
        bbox_prior = bbox_data[:, 1:]

        # Transform bbox priors into proposals via bbox transformations
        bbox_decode = box_utils.bbox_transform(
            bbox_prior, bbox_deltas, self._bbox_reg_weights
        )

        # remove mal-boxes with non-positive width or height and ground
        # truth boxes during training
        if len(inputs) > 2:
            mapped_gt_boxes = inputs[2].data
            max_overlap = mapped_gt_boxes[:, 4]
            keep = _filter_boxes(bbox_decode, max_overlap)
            bbox_decode = bbox_decode[keep, :]
            batch_inds = batch_inds[keep, :]

        bbox_decode = np.hstack((batch_inds, bbox_decode))
        outputs[0].reshape(bbox_decode.shape)
        outputs[0].data[...] = bbox_decode 
开发者ID:fyangneil,项目名称:Clustered-Object-Detection-in-Aerial-Image,代码行数:33,代码来源:decode_bboxes.py

示例4: forward

# 需要导入模块: from detectron.utils import boxes [as 别名]
# 或者: from detectron.utils.boxes import bbox_transform [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_transform方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。