當前位置: 首頁>>代碼示例>>Python>>正文


Python boxes.xyxy_to_xywh方法代碼示例

本文整理匯總了Python中utils.boxes.xyxy_to_xywh方法的典型用法代碼示例。如果您正苦於以下問題:Python boxes.xyxy_to_xywh方法的具體用法?Python boxes.xyxy_to_xywh怎麽用?Python boxes.xyxy_to_xywh使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在utils.boxes的用法示例。


在下文中一共展示了boxes.xyxy_to_xywh方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _coco_bbox_results_one_category

# 需要導入模塊: from utils import boxes [as 別名]
# 或者: from utils.boxes import xyxy_to_xywh [as 別名]
def _coco_bbox_results_one_category(json_dataset, boxes, cat_id):
    results = []
    image_ids = json_dataset.COCO.getImgIds()
    image_ids.sort()
    assert len(boxes) == len(image_ids)
    for i, image_id in enumerate(image_ids):
        dets = boxes[i]
        if isinstance(dets, list) and len(dets) == 0:
            continue
        dets = dets.astype(np.float)
        scores = dets[:, -1]
        xywh_dets = box_utils.xyxy_to_xywh(dets[:, 0:4])
        xs = xywh_dets[:, 0]
        ys = xywh_dets[:, 1]
        ws = xywh_dets[:, 2]
        hs = xywh_dets[:, 3]
        results.extend(
            [{'image_id': image_id,
              'category_id': cat_id,
              'bbox': [xs[k], ys[k], ws[k], hs[k]],
              'score': scores[k]} for k in range(dets.shape[0])])
    return results 
開發者ID:roytseng-tw,項目名稱:Detectron.pytorch,代碼行數:24,代碼來源:json_dataset_evaluator.py

示例2: _filter_crowd_proposals

# 需要導入模塊: from utils import boxes [as 別名]
# 或者: from utils.boxes import xyxy_to_xywh [as 別名]
def _filter_crowd_proposals(roidb, crowd_thresh):
    """Finds proposals that are inside crowd regions and marks them as
    overlap = -1 with each ground-truth rois, which means they will be excluded
    from training.
    """
    for entry in roidb:
        gt_overlaps = entry['gt_overlaps'].toarray()
        crowd_inds = np.where(entry['is_crowd'] == 1)[0]
        non_gt_inds = np.where(entry['gt_classes'] == 0)[0]
        if len(crowd_inds) == 0 or len(non_gt_inds) == 0:
            continue
        crowd_boxes = box_utils.xyxy_to_xywh(entry['boxes'][crowd_inds, :])
        non_gt_boxes = box_utils.xyxy_to_xywh(entry['boxes'][non_gt_inds, :])
        iscrowd_flags = [int(True)] * len(crowd_inds)
        ious = COCOmask.iou(non_gt_boxes, crowd_boxes, iscrowd_flags)
        bad_inds = np.where(ious.max(axis=1) > crowd_thresh)[0]
        gt_overlaps[non_gt_inds[bad_inds], :] = -1
        entry['gt_overlaps'] = scipy.sparse.csr_matrix(gt_overlaps) 
開發者ID:roytseng-tw,項目名稱:Detectron.pytorch,代碼行數:20,代碼來源:json_dataset.py

示例3: _coco_bbox_results_one_category

# 需要導入模塊: from utils import boxes [as 別名]
# 或者: from utils.boxes import xyxy_to_xywh [as 別名]
def _coco_bbox_results_one_category(json_dataset, boxes, cat_id):
    results = []
    # image_ids = json_dataset.COCO.getImgIds()
    # image_ids.sort()
    image_ids = json_dataset.test_img_ids
    assert len(boxes) == len(image_ids)
    for i, image_id in enumerate(image_ids):
        dets = boxes[i]
        if (isinstance(dets, list) and len(dets) == 0) or dets is None:
            continue
        dets = dets.astype(np.float)
        scores = dets[:, -1]
        xywh_dets = box_utils.xyxy_to_xywh(dets[:, 0:4])
        xs = xywh_dets[:, 0]
        ys = xywh_dets[:, 1]
        ws = xywh_dets[:, 2]
        hs = xywh_dets[:, 3]
        results.extend(
            [{'image_id': image_id,
              'category_id': cat_id,
              'bbox': [xs[k], ys[k], ws[k], hs[k]],
              'score': scores[k]} for k in range(dets.shape[0])])
    return results 
開發者ID:ruotianluo,項目名稱:Context-aware-ZSR,代碼行數:25,代碼來源:json_dataset_evaluator.py

示例4: convert_raw_predictions_to_objs

# 需要導入模塊: from utils import boxes [as 別名]
# 或者: from utils.boxes import xyxy_to_xywh [as 別名]
def convert_raw_predictions_to_objs(self, annots, image_id):
        if len(annots['boxes']) == 0:
            return []
        objs = []
        N = annots['boxes'].shape[0]
        for i in range(N):
            obj = {}
            # COCO labels are in xywh format, but I make predictions in xyxy
            # Remove the score from box before converting
            obj['bbox'] = box_utils.xyxy_to_xywh(annots['boxes'][i][
                np.newaxis, :4]).reshape((-1,)).tolist()
            obj['num_keypoints'] = annots['poses'][i].shape[-1]
            assert(obj['num_keypoints'] == cfg.KRCNN.NUM_KEYPOINTS)
            obj['segmentation'] = []
            obj['area'] = obj['bbox'][-1] * obj['bbox'][-2]
            obj['iscrowd'] = False
            pose = annots['poses'][i][:3].transpose()
            pose[pose[:, -1] >= 2.0, -1] = 2
            pose[pose[:, -1] < 2.0, -1] = 0
            obj['keypoints'] = pose.reshape((-1)).tolist()
            obj['track_id'] = annots['tracks'][i]
            obj['image_id'] = image_id
            obj['category_id'] = 1  # person
            objs.append(obj)
        return objs 
開發者ID:facebookresearch,項目名稱:DetectAndTrack,代碼行數:27,代碼來源:json_dataset.py

示例5: test_bbox_dataset_to_prediction_roundtrip

# 需要導入模塊: from utils import boxes [as 別名]
# 或者: from utils.boxes import xyxy_to_xywh [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:ronghanghu,項目名稱:seg_every_thing,代碼行數:29,代碼來源:test_bbox_transform.py

示例6: test_cython_bbox_iou_against_coco_api_bbox_iou

# 需要導入模塊: from utils import boxes [as 別名]
# 或者: from utils.boxes import xyxy_to_xywh [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:ronghanghu,項目名稱:seg_every_thing,代碼行數:29,代碼來源:test_bbox_transform.py


注:本文中的utils.boxes.xyxy_to_xywh方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。