'''
特别关注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, 3
y =
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
anchors = np.asarray([cx, cy, anchor_w, anchor_h])
anchors = np.transpose(anchors, (1, 2, 0))
return anchors