def iou(box_a, box_b):
    """ Calculates Intersection over Union (IoU) metric.

    :param box_a: First bbox
    :param box_b: Second bbox
    :return: Scalar value of metric
    """

    intersect_top_left_x = max(box_a.xmin, box_b.xmin)
    intersect_top_left_y = max(box_a.ymin, box_b.ymin)
    intersect_width = max(0.0, min(box_a.xmax, box_b.xmax) - intersect_top_left_x)
    intersect_height = max(0.0, min(box_a.ymax, box_b.ymax) - intersect_top_left_y)

    box_a_area = (box_a.xmax - box_a.xmin) * (box_a.ymax - box_a.ymin)
    box_b_area = (box_b.xmax - box_b.xmin) * (box_b.ymax - box_b.ymin)
    intersect_area = float(intersect_width * intersect_height)

    union_area = float(box_a_area + box_b_area - intersect_area)

    return intersect_area / union_area if union_area > 0.0 else 0.0