def iou(bbox_1, bbox_2):
"""Compute iou of a box with another box. Box format '[y_min, x_min, y_max, x_max]'.
Args:
bbox_1: 1-D with shape `[4]`.
bbox_2: 1-D with shape `[4]`.
Returns:
IOU
"""
lr = tf.minimum(bbox_1[3], bbox_2[3]) - tf.maximum(bbox_1[1], bbox_2[1])
tb = tf.minimum(bbox_1[2], bbox_2[2]) - tf.maximum(bbox_1[0], bbox_2[0])
lr = tf.maximum(lr, lr * 0)
tb = tf.maximum(tb, tb * 0)
intersection = tf.multiply(tb, lr)
union = tf.subtract(
tf.multiply((bbox_1[3] - bbox_1[1]), (bbox_1[2] - bbox_1[0])) +
tf.multiply((bbox_2[3] - bbox_2[1]), (bbox_2[2] - bbox_2[0])),
intersection
)
iou = tf.div(intersection, union)
return iou
评论列表
文章目录