seglink代码之 generate_anchors_one layer

来源:互联网 发布:宜兴俊知集团工资高吗 编辑:程序博客网 时间:2024/05/22 21:23
'''特别关注np.mgrid函数,例如 x, y = np.mgrid[0:4, 0:4]x =    0, 1, 2, 3    0, 1, 2, 3    0, 1, 2, 3    0, 1, 2, 3y =    0, 0, 0, 0    1, 1, 1, 1    2, 2, 2, 2    3, 3, 3, 3利用这个函数的性质就能很方便的计算anchor_box的坐标值此外,anchor_scale不是单纯的图像比,还是有一个尺度系数,在此设为1.5'''def _generate_anchors_one_layer(h_I, w_I, h_l, w_l):    """    generate anchors on on layer    return a ndarray with shape (h_l, w_l, 4), and the last dimmension in the order:[cx, cy, w, h]    """    y, x = np.mgrid[0: h_l, 0:w_l]    cy = (y + config.anchor_offset) / h_l * h_I    cx = (x + config.anchor_offset) / w_l * w_I    anchor_scale = _get_scale(w_I, w_l)    anchor_w = np.ones_like(cx) * anchor_scale    anchor_h = np.ones_like(cx) * anchor_scale # cx.shape == cy.shape    anchors = np.asarray([cx, cy, anchor_w, anchor_h])    anchors = np.transpose(anchors, (1, 2, 0))    return anchors
原创粉丝点击