def nms(dets, thresh):
    'Apply classic DPM-style greedy NMS.'
    if (dets.shape[0] == 0):
        return dets[[], :]
    scores = dets[:, 0]
    x1 = dets[:, 1]
    y1 = dets[:, 2]
    x2 = dets[:, 3]
    y2 = dets[:, 4]
    areas = (((x2 - x1) + 1) * ((y2 - y1) + 1))
    order = scores.argsort()[::(- 1)]
    ndets = dets.shape[0]
    suppressed = np.zeros(ndets, dtype=np.int)
    for _i in range(ndets):
        i = order[_i]
        if (suppressed[i] == 1):
            continue
        ix1 = x1[i]
        iy1 = y1[i]
        ix2 = x2[i]
        iy2 = y2[i]
        iarea = areas[i]
        for _j in range((_i + 1), ndets):
            j = order[_j]
            if (suppressed[j] == 1):
                continue
            xx1 = max(ix1, x1[j])
            yy1 = max(iy1, y1[j])
            xx2 = min(ix2, x2[j])
            yy2 = min(iy2, y2[j])
            w = max(0.0, ((xx2 - xx1) + 1))
            h = max(0.0, ((yy2 - yy1) + 1))
            inter = (w * h)
            ovr = (inter / ((iarea + areas[j]) - inter))
            if (ovr >= thresh):
                suppressed[j] = 1
    keep = np.where((suppressed == 0))[0]
    dets = dets[keep, :]
    return dets
Apply classic DPM-style greedy NMS.
def nms(dets, thresh):
    
    if (dets.shape[0] == 0):
        return dets[[], :]
    scores = dets[:, 0]
    x1 = dets[:, 1]
    y1 = dets[:, 2]
    x2 = dets[:, 3]
    y2 = dets[:, 4]
    areas = (((x2 - x1) + 1) * ((y2 - y1) + 1))
    order = scores.argsort()[::(- 1)]
    ndets = dets.shape[0]
    suppressed = np.zeros(ndets, dtype=np.int)
    for _i in range(ndets):
        i = order[_i]
        if (suppressed[i] == 1):
            continue
        ix1 = x1[i]
        iy1 = y1[i]
        ix2 = x2[i]
        iy2 = y2[i]
        iarea = areas[i]
        for _j in range((_i + 1), ndets):
            j = order[_j]
            if (suppressed[j] == 1):
                continue
            xx1 = max(ix1, x1[j])
            yy1 = max(iy1, y1[j])
            xx2 = min(ix2, x2[j])
            yy2 = min(iy2, y2[j])
            w = max(0.0, ((xx2 - xx1) + 1))
            h = max(0.0, ((yy2 - yy1) + 1))
            inter = (w * h)
            ovr = (inter / ((iarea + areas[j]) - inter))
            if (ovr >= thresh):
                suppressed[j] = 1
    keep = np.where((suppressed == 0))[0]
    dets = dets[keep, :]
    return dets