使用if-else时的判断条件出了问题

出现的错误为:line 188,if np.logical_or(Y_bottom>box1_height,Y_bottom>box2_height):
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all() 

def bboxes_iou(box1, box2):
    box1 = np.transpose(box1)
    box2 = np.transpose(box2)

    xi1 = np.maximum(box1[0], box2[0])
    # yi1 = np.maximum(box1[1], box2[1])
    xi2 = np.minimum(box1[2], box2[2])
    # yi2 = np.maximum(box1[3], box2[3])
    X_overlap = np.maximum(xi2 - xi1, 0)
    # Y_bottom = np.maximum(yi2 - box1[3], 0)

    X = X_overlap / (box1[2] - box1[0])
    # Y = Y_bottom / (box1[3] - box1[1])
    box1_height = box1[3] - box1[1]
    box2_height = box2[3] - box2[1]
    Y_bottom = np.abs(box1[3] - box2[3])

    if Y_bottom > box1_height or Y_bottom > box2_height:
        Y = 0
    else:
        Y = Y_bottom / (box1[3] - box1[1])

    bep = X * (1 - Y)

    return bep
# 非最大值抑制
def bboxes_nms(classes, scores, bboxes, nms_threshold=0.5):
    keep_bboxes = np.ones(scores.shape, dtype=np.bool)
    for i in range(scores.size - 1):
        if keep_bboxes[i]:
            overlap = bboxes_iou(bboxes[i], bboxes[(i + 1):])
            # 逻辑或,小于门限值或者类别不相同就保留这个框
            keep_overlap = np.logical_or(overlap < nms_threshold, classes[(i + 1):] != classes[i])
            # 选取下一个
            keep_bboxes[(i + 1):] = np.logical_and(keep_bboxes[(i + 1):], keep_overlap)
    # np.where返回索引值
    idxes = np.where(keep_bboxes)
    return classes[idxes], scores[idxes], bboxes[idxes]

 

不知道你这个问题是否已经解决, 如果还没有解决的话:

如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 以帮助更多的人 ^-^