def _clip_boxes(self, boxes, image):
height = tf.shape(image)[1]
width = tf.shape(image)[2]
# TODO: what TF will do with tensors that will not be used anymore?
x1_over_0 = tf.reshape(tf.maximum(tf.minimum(boxes[:, 0::4], tf.cast(width - 1, tf.float32)), 0), (-1,))
y1_over_0 = tf.reshape(tf.maximum(tf.minimum(boxes[:, 1::4], tf.cast(height - 1, tf.float32)), 0), (-1,))
x2_below_width = tf.reshape(tf.maximum(tf.minimum(boxes[:, 2::4], tf.cast(width - 1, tf.float32)), 0), (-1,))
y2_below_height = tf.reshape(tf.maximum(tf.minimum(boxes[:, 3::4], tf.cast(height - 1, tf.float32)), 0), (-1,))
boxes = tf.pack(
[x1_over_0, # x1 >= 0
y1_over_0, # y1 >= 0
x2_below_width, # x2 < im_shape[1]
y2_below_height], # y2 < im_shape[0]
axis=1
)
return boxes
# bbox_transform_inv
评论列表
文章目录