roidb.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:fast-rcnn-distillation 作者: xiaolonw 项目源码 文件源码
def _compute_targets(rois, overlaps, labels):
    """Compute bounding-box regression targets for an image."""
    # Ensure ROIs are floats
    rois = rois.astype(np.float, copy=False)

    # Indices of ground-truth ROIs
    gt_inds = np.where(overlaps == 1)[0]
    # 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 = utils.cython_bbox.bbox_overlaps(rois[ex_inds, :],
                                                     rois[gt_inds, :])

    # Find which gt ROI each ex ROI has max overlap with:
    # this will be the ex ROI's gt target
    if ex_inds.shape[0] > 0:
        gt_assignment = ex_gt_overlaps.argmax(axis=1)
        gt_rois = rois[gt_inds[gt_assignment], :]
        ex_rois = rois[ex_inds, :]

        ex_widths = ex_rois[:, 2] - ex_rois[:, 0] + cfg.EPS
        ex_heights = ex_rois[:, 3] - ex_rois[:, 1] + cfg.EPS
        ex_ctr_x = ex_rois[:, 0] + 0.5 * ex_widths
        ex_ctr_y = ex_rois[:, 1] + 0.5 * ex_heights

        gt_widths = gt_rois[:, 2] - gt_rois[:, 0] + cfg.EPS
        gt_heights = gt_rois[:, 3] - gt_rois[:, 1] + cfg.EPS
        gt_ctr_x = gt_rois[:, 0] + 0.5 * gt_widths
        gt_ctr_y = gt_rois[:, 1] + 0.5 * gt_heights

        targets_dx = (gt_ctr_x - ex_ctr_x) / ex_widths
        targets_dy = (gt_ctr_y - ex_ctr_y) / ex_heights
        targets_dw = np.log(gt_widths / ex_widths)
        targets_dh = np.log(gt_heights / ex_heights)

        targets = np.zeros((rois.shape[0], 5), dtype=np.float32)
        targets[ex_inds, 0] = labels[ex_inds]
        targets[ex_inds, 1] = targets_dx
        targets[ex_inds, 2] = targets_dy
        targets[ex_inds, 3] = targets_dw
        targets[ex_inds, 4] = targets_dh

    else:
        targets = np.zeros((rois.shape[0], 5), dtype=np.float32)

    return targets
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号