grid_y = K.tile(K.reshape(K.arange(0, stop=grid_shape[0]), [-1, 1, 1, 1]),
[1, grid_shape[1], 1, 1])
grid_x = K.tile(K.reshape(K.arange(0, stop=grid_shape[1]), [1, -1, 1, 1]),
[grid_shape[0], 1, 1, 1])
其中grid为相对于feature map左上角的偏移量。以13*13的feature map为例来说明box 中心点x,y以及宽高w,h的计算过程。
K.arange(0, stop=grid_shape[0]) ---->[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
K.reshape(K.arange(0, stop=grid_shape[0]), [-1, 1, 1, 1]) ----> -1表示为变化的维度,放在第一维度表示第一位维是变化的则 shape=[13,1,1,1] 一共包含13行值分别为0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12。
具体形式如下:[ [ [ [ 0 ] ] ]
..........
[ [ [12 ] ] ] ]
grid_y = K.tile(K.reshape(K.arange(0, stop=grid_shape[0]), [-1, 1, 1, 1]), [1, grid_shape[1], 1, 1]) ----> 表示在第二个维度重复13次 shape=[13,13,1,1]
具体形式如下:[ [ [ [ 0 ] ]
...........
[ [ 0 ] ] 重复13次
[ [ [ 1 ] ]
............
[ [ 1 ] ] 重复13次
.............
.............
[ [ [ 12 ] ]
...............
[ [12 ] ] ] ]
同理可得到grid_x的具体形式:[ [ [ [ 0 ] ] shape=[13,13,1,1]
[ [ 1 ] ]
............
[ [12 ] ] ]
.............
.............
[ [ [ [ 0 ] ] 蓝色部分共重复了13次
[ [ 1 ] ]
............
[ [ 12 ] ] ]
grid最终形式为 [ [ [ [ 0 0 ] ] shape=[13,13,1,2]
[ [ 1 0 ] ]
................
[ [12 1 ] ] ]
[ [ [ 0 1 ] ]
[ [ 1 1 ] ]
................
[ [12 1] ] ]
..................
..................
[ [ [ 0 12 ] ]
[ [ 1 12 ] ]
................
[ [12 12] ] ]