def batch_iou_tf(proposals, gt):
bboxes = tf.reshape(tf.transpose(proposals), [4, -1, 1])
bboxes_x1 = bboxes[0]
bboxes_x2 = bboxes[0]+bboxes[2]
bboxes_y1 = bboxes[1]
bboxes_y2 = bboxes[1]+bboxes[3]
gt = tf.reshape(tf.transpose(gt), [4, 1, -1])
gt_x1 = gt[0]
gt_x2 = gt[0]+gt[2]
gt_y1 = gt[1]
gt_y2 = gt[1]+gt[3]
widths = tf.maximum(0.0, tf.minimum(bboxes_x2, gt_x2) -
tf.maximum(bboxes_x1, gt_x1))
heights = tf.maximum(0.0, tf.minimum(bboxes_y2, gt_y2) -
tf.maximum(bboxes_y1, gt_y1))
intersection = widths*heights
union = bboxes[2]*bboxes[3] + gt[2]*gt[3] - intersection
return (intersection / union)
评论列表
文章目录