【Faster RCNN】RPN中bbox的回归操作

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/wangdongwei0/article/details/88197548

代码来自

github: https://github.com/smallcorgi/Faster-RCNN_TF

# ex_roi 用来回归的anchor
# gt_roi 每个anchor对应的ground truth
# 在进行回归前,保证每个需要回归的anchor都有一个gtbox作为回归的目标
def bbox_transform(ex_rois, gt_rois):
    #计算dx,dy时,使用的是anchor和gtbox的中心点,比如中心点x方向距离/anchor的w
    #计算dw,dh时,使用的是对数log形式 np.log(gt_widths / ex_widths)
    ex_widths = ex_rois[:, 2] - ex_rois[:, 0] + 1.0
    ex_heights = ex_rois[:, 3] - ex_rois[:, 1] + 1.0
    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] + 1.0
    gt_heights = gt_rois[:, 3] - gt_rois[:, 1] + 1.0
    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.vstack(
        (targets_dx, targets_dy, targets_dw, targets_dh)).transpose()
    return targets

猜你喜欢

转载自blog.csdn.net/wangdongwei0/article/details/88197548