def _combine_box_and_delta(self, bboxes, deltas):
widths = bboxes[:, 2] - bboxes[:, 0] + 1.0
heights = bboxes[:, 3] - bboxes[:, 1] + 1.0
ctr_x = bboxes[:, 0] + 0.5 * widths
ctr_y = bboxes[:, 1] + 0.5 * heights
# use 0::4 to make it a [-1, 1] matrix, while the columns are 4
dx = deltas[:, 0::4]
dy = deltas[:, 1::4]
dw = deltas[:, 2::4]
dh = deltas[:, 3::4]
# do not understand the transformation
# TF ?????reshape????????????????
pred_ctr_x = tf.reshape(dx * widths[:, tf.newaxis] + ctr_x[:, tf.newaxis], (-1,))
pred_ctr_y = tf.reshape(dy * heights[:, tf.newaxis] + ctr_y[:, tf.newaxis], (-1,))
pred_w = tf.reshape(tf.exp(dw) * widths[:, tf.newaxis], (-1,))
pred_h = tf.reshape(tf.exp(dh) * heights[:, tf.newaxis], (-1,))
pred_boxes = tf.pack(
[pred_ctr_x - 0.5 * pred_w,
pred_ctr_y - 0.5 * pred_h,
pred_ctr_x + 0.5 * pred_w,
pred_ctr_y + 0.5 * pred_h],
axis=1
)
return pred_boxes
评论列表
文章目录