def f_inter_box(top_left_a, bot_right_a, top_left_b, bot_right_b):
"""Computes intersection area with boxes.
Args:
top_left_a: [B, T, 2] or [B, 2]
bot_right_a: [B, T, 2] or [B, 2]
top_left_b: [B, T, 2] or [B, 2]
bot_right_b: [B, T, 2] or [B, 2]
Returns:
area: [B, T]
"""
top_left_max = tf.maximum(top_left_a, top_left_b)
bot_right_min = tf.minimum(bot_right_a, bot_right_b)
ndims = tf.shape(tf.shape(top_left_a))
# Check if the resulting box is valid.
overlap = tf.to_float(top_left_max < bot_right_min)
overlap = tf.reduce_prod(overlap, ndims - 1)
area = tf.reduce_prod(bot_right_min - top_left_max, ndims - 1)
area = overlap * tf.abs(area)
return area
评论列表
文章目录