def get_tiled_anchors_for_shape(self, width, height):
""" creates/tiles anchors for a width x height image/feature map,
producing coordinates from [0, width) and [0, height) for the
resulting bounding boxes, according to the feature stride
of the last conv layer """
anchors = tf.expand_dims(self.anchors, axis=0)
feat_height = tf.cast(tf.ceil(height/self.feat_stride), tf.int32)
feat_width = tf.cast(tf.ceil(width/self.feat_stride), tf.int32)
anchor_shape = [feat_height * feat_width, 1, 1]
anchors = tf.tile(anchors, tf.stack(anchor_shape))
x = tf.range(0.0, feat_width * self.feat_stride, self.feat_stride)
y = tf.range(0.0, feat_height * self.feat_stride, self.feat_stride)
X, Y = tf.meshgrid(x, y)
X = tf.expand_dims(X, 2)
Y = tf.expand_dims(Y, 2)
shift = tf.reshape(tf.concat([Y, X, tf.zeros_like(X), tf.zeros_like(X)], 2), [-1, 1, 4])
shift = tf.tile(shift, [1, self.num_anchors, 1])
anchors = tf.cast(anchors, tf.float32) + shift
return tf.reshape(anchors, [-1, 4])
评论列表
文章目录