def compute_overlap(bb, objs, label):
    """
    Compute the overlap between predicted bbox and label and gt bbox and label.

    Args:
        bb: List, contains predicted bounding box coordinates for an image.
        objs: dict, contains ground truth bounding boxes for all objects
            in an image.
        label: String, predicted label for an image.

    Returns:
        ov_vector: List, contains percentile overlap for each object.
    """
    assert(len(bb) == 4)
    ov_vector = []
    for k in objs.keys():
        if k != label:
            continue
        for i in range(len(objs[k])):
            bbgt = objs[k][i]
            bi=[max(bb[0],bbgt[0]), max(bb[1],bbgt[1]),
                min(bb[2],bbgt[2]), min(bb[3],bbgt[3])]
            iw=bi[2]-bi[0]+1
            ih=bi[3]-bi[1]+1
            ov = -1
            if iw>0 and ih>0:
                # Compute overlap as area of intersection / area of union.
                ua=((bb[2]-bb[0]+1)*(bb[3]-bb[1]+1)
                       +(bbgt[2]-bbgt[0]+1)*(bbgt[3]-bbgt[1]+1)
                       -iw*ih)
                ov=iw*ih/float(ua)
            ov_vector.append(ov)
    return ov_vector