def bbox_IOU(bbox1, bbox2):
    """
    Calculate IOU of 2 bboxes. bboxes are in SSD format (7 elements)  
    bbox = [id, cls, prob, x1, y1, x2, y2]  
    Args:
        bbox1 (bbox)
        bbox2 (bbox)
    Returns:
        IOU value
    """
    _xmin, _ymin, _xmax, _ymax = 3, 4, 5, 6
    width_of_overlap_area  = min(bbox1[_xmax], bbox2[_xmax]) - max(bbox1[_xmin], bbox2[_xmin])
    height_of_overlap_area = min(bbox1[_ymax], bbox2[_ymax]) - max(bbox1[_ymin], bbox2[_ymin])
    if width_of_overlap_area < 0 or height_of_overlap_area < 0:
        area_of_overlap = 0
    else:
        area_of_overlap = width_of_overlap_area * height_of_overlap_area
    bbox1_area = (bbox1[_ymax] - bbox1[_ymin]) * (bbox1[_xmax] - bbox1[_xmin])
    bbox2_area = (bbox2[_ymax] - bbox2[_ymin]) * (bbox2[_xmax] - bbox2[_xmin])
    area_of_union = bbox1_area + bbox2_area - area_of_overlap
    if area_of_union == 0:
        return 0
    return area_of_overlap / area_of_union