Intersection over Union

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[:, :, 

Get Deep Learning for Computer Vision now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.