The IoU is the ratio of the overlapping area of ground truth and predicted area to the total area. Here is a visual explanation of the metric:
The two squares represent the bounding boxes of ground truth and predictions. The IoU is calculated as a ratio of the area of overlap to the area of the union. Here is the script to compute the IoU is given ground truth and prediction bounding boxes:
def calculate_iou(gt_bb, pred_bb): ''' :param gt_bb: ground truth bounding box :param pred_bb: predicted bounding box ''' gt_bb = tf.stack([ gt_bb[:, :, :, :, 0] - gt_bb[:, :, :, :, 2] / 2.0, gt_bb[:, :, :, :, 1] - gt_bb[:, :,