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


Python mask.iou方法代码示例

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


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

示例1: _filter_crowd_proposals

# 需要导入模块: from pycocotools import mask [as 别名]
# 或者: from pycocotools.mask import iou [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:yihui-he,项目名称:KL-Loss,代码行数:20,代码来源:json_dataset.py

示例2: _filter_crowd_proposals

# 需要导入模块: from pycocotools import mask [as 别名]
# 或者: from pycocotools.mask import iou [as 别名]
def _filter_crowd_proposals(roidb, crowd_thresh):
    """
    Finds proposals that are inside crowd regions and marks them with
    overlap = -1 (for all gt rois), which means they will be excluded from
    training.
    """
    for ix, entry in enumerate(roidb):
        overlaps = entry['gt_overlaps'].toarray()
        crowd_inds = np.where(overlaps.max(axis=1) == -1)[0]
        non_gt_inds = np.where(entry['gt_classes'] == 0)[0]
        if len(crowd_inds) == 0 or len(non_gt_inds) == 0:
            continue
        iscrowd = [int(True) for _ in xrange(len(crowd_inds))]
        crowd_boxes = ds_utils.xyxy_to_xywh(entry['boxes'][crowd_inds, :])
        non_gt_boxes = ds_utils.xyxy_to_xywh(entry['boxes'][non_gt_inds, :])
        ious = COCOmask.iou(non_gt_boxes, crowd_boxes, iscrowd)
        bad_inds = np.where(ious.max(axis=1) > crowd_thresh)[0]
        overlaps[non_gt_inds[bad_inds], :] = -1
        roidb[ix]['gt_overlaps'] = scipy.sparse.csr_matrix(overlaps)
    return roidb 
开发者ID:playerkk,项目名称:face-py-faster-rcnn,代码行数:22,代码来源:coco.py

示例3: match_dt_gt

# 需要导入模块: from pycocotools import mask [as 别名]
# 或者: from pycocotools.mask import iou [as 别名]
def match_dt_gt(e, imgid, target_dt_boxes, gt_boxes, eval_target):
  for target_class in eval_target.keys():
    #if len(gt_boxes[target_class]) == 0:
    #  continue
    target_dt_boxes[target_class].sort(key=operator.itemgetter(1), reverse=True)
    d = [box for box, prob in target_dt_boxes[target_class]]
    dscores = [prob for box, prob in target_dt_boxes[target_class]]
    g = gt_boxes[target_class]

    # len(D), len(G)
    dm, gm = match_detection(d, g, cocomask.iou(
        d, g, [0 for _ in range(len(g))]), iou_thres=0.5)

    e[target_class][imgid] = {
        "dscores": dscores,
        "dm": dm,
        "gt_num": len(g)}


# for activity boxes 
开发者ID:JunweiLiang,项目名称:Object_Detection_Tracking,代码行数:22,代码来源:utils.py

示例4: computeIoU

# 需要导入模块: from pycocotools import mask [as 别名]
# 或者: from pycocotools.mask import iou [as 别名]
def computeIoU(self, imgId, catId):
        p = self.params
        if p.useCats:
            gt = self._gts[imgId, catId]
            dt = self._dts[imgId, catId]
        else:
            gt = [_ for cId in p.catIds for _ in self._gts[imgId, cId]]
            dt = [_ for cId in p.catIds for _ in self._dts[imgId, cId]]
        if len(gt) == 0 and len(dt) == 0:
            return []
        inds = np.argsort([-d['score'] for d in dt], kind='mergesort')
        dt = [dt[i] for i in inds]
        if len(dt) > p.maxDets[-1]:
            dt = dt[0:p.maxDets[-1]]

        if p.iouType == 'segm':
            g = [g['segmentation'] for g in gt]
            d = [d['segmentation'] for d in dt]
        elif p.iouType == 'bbox':
            g = [g['bbox'] for g in gt]
            d = [d['bbox'] for d in dt]
        else:
            raise Exception('unknown iouType for iou computation')

        # compute iou between each dt and gt region
        iscrowd = [int(o['iscrowd']) for o in gt]
        ious = maskUtils.iou(d, g, iscrowd)
        return ious 
开发者ID:soeaver,项目名称:Parsing-R-CNN,代码行数:30,代码来源:densepose_cocoeval.py

示例5: np_iou

# 需要导入模块: from pycocotools import mask [as 别名]
# 或者: from pycocotools.mask import iou [as 别名]
def np_iou(A, B):
  def to_xywh(box):
    box = box.copy()
    box[:, 2] -= box[:, 0]
    box[:, 3] -= box[:, 1]
    return box

  ret = iou(
    to_xywh(A), to_xywh(B),
    np.zeros((len(B),), dtype=np.bool))
  return ret 
开发者ID:lambdal,项目名称:lambda-deep-learning-demo,代码行数:13,代码来源:detection_common.py

示例6: iou

# 需要导入模块: from pycocotools import mask [as 别名]
# 或者: from pycocotools.mask import iou [as 别名]
def iou(gt, pred):
    gt[gt > 0] = 1.
    pred[pred > 0] = 1.
    intersection = gt * pred
    union = gt + pred
    union[union > 0] = 1.
    intersection = np.sum(intersection)
    union = np.sum(union)
    if union == 0:
        union = 1e-09
    return intersection / union 
开发者ID:neptune-ai,项目名称:open-solution-salt-identification,代码行数:13,代码来源:metrics.py

示例7: compute_ious

# 需要导入模块: from pycocotools import mask [as 别名]
# 或者: from pycocotools.mask import iou [as 别名]
def compute_ious(gt, predictions):
    gt_ = get_segmentations(gt)
    predictions_ = get_segmentations(predictions)

    if len(gt_) == 0 and len(predictions_) == 0:
        return np.ones((1, 1))
    elif len(gt_) != 0 and len(predictions_) == 0:
        return np.zeros((1, 1))
    else:
        iscrowd = [0 for _ in predictions_]
        ious = cocomask.iou(gt_, predictions_, iscrowd)
        if not np.array(ious).size:
            ious = np.zeros((1, 1))
        return ious 
开发者ID:neptune-ai,项目名称:open-solution-salt-identification,代码行数:16,代码来源:metrics.py

示例8: intersection_over_union

# 需要导入模块: from pycocotools import mask [as 别名]
# 或者: from pycocotools.mask import iou [as 别名]
def intersection_over_union(y_true, y_pred):
    ious = []
    for y_t, y_p in tqdm(list(zip(y_true, y_pred))):
        iou = compute_ious(y_t, y_p)
        iou_mean = 1.0 * np.sum(iou) / len(iou)
        ious.append(iou_mean)
    return np.mean(ious) 
开发者ID:neptune-ai,项目名称:open-solution-salt-identification,代码行数:9,代码来源:metrics.py

示例9: test_bbox_dataset_to_prediction_roundtrip

# 需要导入模块: from pycocotools import mask [as 别名]
# 或者: from pycocotools.mask import iou [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

示例10: test_cython_bbox_iou_against_coco_api_bbox_iou

# 需要导入模块: from pycocotools import mask [as 别名]
# 或者: from pycocotools.mask import iou [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

示例11: calculate_association_similarities

# 需要导入模块: from pycocotools import mask [as 别名]
# 或者: from pycocotools.mask import iou [as 别名]
def calculate_association_similarities(detections_t, last_tracks, flow_tm1_t, tracker_options):
    association_similarities = np.zeros((len(detections_t), len(last_tracks)))
    if tracker_options["reid_weight"] != 0:
        curr_reids = np.array([x[1] for x in detections_t], dtype="float64")
        last_reids = np.array([x.reid for x in last_tracks], dtype="float64")
        reid_dists = cdist(curr_reids, last_reids, "euclidean")
        reid_similarities = tracker_options["reid_euclidean_scale"] * \
                            (tracker_options["reid_euclidean_offset"] - reid_dists)
        association_similarities += tracker_options["reid_weight"] * reid_similarities
    if tracker_options["mask_iou_weight"] != 0:
        masks_t = [v[2] for v in detections_t]
        masks_tm1 = [v.mask for v in last_tracks]
        masks_tm1_warped = [warp_flow(mask, flow_tm1_t) for mask in masks_tm1]
        mask_ious = cocomask.iou(masks_t, masks_tm1_warped, [False] * len(masks_tm1_warped))
        association_similarities += tracker_options["mask_iou_weight"] * mask_ious
    if tracker_options["bbox_center_weight"] != 0:
        centers_t = [v[0][0:2] + (v[0][2:4] - v[0][0:2]) / 2 for v in detections_t]
        centers_tm1 = [v.box[0:2] + (v.box[2:4] - v.box[0:2]) / 2 for v in last_tracks]
        box_dists = cdist(np.array(centers_t), np.array(centers_tm1), "euclidean")
        box_similarities = tracker_options["box_scale"] * \
                           (tracker_options["box_offset"] - box_dists)
        association_similarities += tracker_options["bbox_center_weight"] * box_similarities
    if tracker_options["bbox_iou_weight"] != 0:
        bboxes_t = [v[0] for v in detections_t]
        bboxes_tm1 = [v.box for v in last_tracks]
        bboxes_tm1_warped = [warp_box(box, flow_tm1_t) for box in bboxes_tm1]
        bbox_ious = np.array([[bbox_iou(box1, box2) for box1 in bboxes_tm1_warped] for box2 in bboxes_t])
        assert (0 <= bbox_ious).all() and (bbox_ious <= 1).all()
        association_similarities += tracker_options["bbox_iou_weight"] * bbox_ious
    return association_similarities 
开发者ID:tobiasfshr,项目名称:MOTSFusion,代码行数:32,代码来源:segmentation_utils.py


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