首先,以左上角的[0,0,15,15]为基准框,在保证面积不变的前提下,把框的宽和高分别做成0.5:1,1:1,1:2三种模式,得到三个anchor(是一个3*4矩阵);
第二步,把上一步得到的三个anchor分别放大8倍、16倍、32倍。原图在vgg16网络中经过4个池化层,所以feature map 的大小是原图的1/16。
通过以上两步得到左上角那个feature的9个anchor。
由于anchor是在原图上面画框,所以接下来,用meshgrid方法构造出feature map的点在原图上的相对位置,再把这个矩阵reshape成shape=[K, 1, 4],K是所有特征点的个数,等于feature map的width*height;
把生成的anchor reshape成[1, A, 4],通过numpy 广播把feature map和anchor加起来得[K, A, 4] ,再reshape成 [K*A, 4] ,得到所有anchor。
anchors_tf = tf.reshape(tf.add(anchor_constant, shifts), shape=(length, 4))