def IOU(box1, box2):
    """
    Params
        box1 - [x1,y1,x2,y2] which are the coordinates of the top left and bottom right  corners of a box
        box2 - [x1,y1,x2,y2] which are the coordinates of the top left and bottom right  corners of a box
    Returns - Intersection over union of the two bounding boxes
    """
    x_left = max( box1[0], box2[0])
    y_top = max( box1[1], box2[1])
    x_right = min(box1[2], box2[2])
    y_bottom = min(box1[3], box2[3])
    if x_right < x_left or y_bottom < y_top: 
        return 0.0
    intersection_area = (x_right - x_left) * (y_bottom - y_top)
    box1area = (box1[2] - box1[0]) * ( box1[3] - box2[1])
    box2area = (box2[2] - box2[0]) * (box2[3] - box2[1])
    iou = intersection_area / float(box1area + box2area - intersection_area)
    return iou