ZFTurbo / Weighted-Boxes-Fusion

Set of methods to ensemble boxes from different object detection models, including implementation of "Weighted boxes fusion (WBF)" method.
MIT License
1.72k stars 238 forks source link

Why does my ensemble still have so many repetitive (IoU > thresh I set) bboxes? #7

Closed RainbowSun11Q2H closed 4 years ago

RainbowSun11Q2H commented 4 years ago

Thank you for your code.

However, when I use this method, I have so many repetitive bboxes. Do you have some advices?

Code is following: boxes, score12, label = example_nms_2_models(boxes_list, labels_list, scores_list, draw_image=False, method=3, iou_thr=0.5, thresh=0.1, sigma=0.5)

I just use nms method because the limitation of running time. An example of results is following: (Pdb) boxes array([[0.73385417, 0.34259259, 0.81041667, 0.45648148], [0.74930206, 0.36653722, 0.79911662, 0.45000624]]) The labels are same. Obviously, the IoU of these two boxes should be over than 0.5. Looks like NMS doen not work in ensemble. Right?

ZFTurbo commented 4 years ago

Can you provide more deatils? For example, 2 boxes with large IoU can be present together in case they have different labels (classes).

ZFTurbo commented 4 years ago
def bb_intersection_over_union(A, B):
    xA = max(A[0], B[0])
    yA = max(A[1], B[1])
    xB = min(A[2], B[2])
    yB = min(A[3], B[3])

    # compute the area of intersection rectangle
    interArea = max(0, xB - xA) * max(0, yB - yA)

    if interArea == 0:
        return 0.0

    # compute the area of both the prediction and ground-truth rectangles
    boxAArea = (A[2] - A[0]) * (A[3] - A[1])
    boxBArea = (B[2] - B[0]) * (B[3] - B[1])

    iou = interArea / float(boxAArea + boxBArea - interArea)
    return iou

iou = bb_intersection_over_union(
        (0.73385417, 0.34259259, 0.81041667, 0.45648148),
        (0.74930206, 0.36653722, 0.79911662, 0.45000624),
)
print(iou)

It gives me 0.476852 < 0.5

shonenkov commented 4 years ago

@ZFTurbo I have found the same problem, maybe this example can help

def bb_intersection_over_union(A, B):
    xA = max(A[0], B[0])
    yA = max(A[1], B[1])
    xB = min(A[2], B[2])
    yB = min(A[3], B[3])

    # compute the area of intersection rectangle
    interArea = max(0, xB - xA) * max(0, yB - yA)

    if interArea == 0:
        return 0.0

    # compute the area of both the prediction and ground-truth rectangles
    boxAArea = (A[2] - A[0]) * (A[3] - A[1])
    boxBArea = (B[2] - B[0]) * (B[3] - B[1])

    iou = interArea / float(boxAArea + boxBArea - interArea)
    return iou

iou = bb_intersection_over_union(
        (0.99804688, 0.58007812, 0.81835938, 0.43554688),
        (0.94726562, 0.55078125, 0.77734375, 0.4140625),
)
print(iou)
>>> 0.0

Без названия

ZFTurbo commented 4 years ago

You have y2 less than y1 and x2 less than x1. I probably need to fix it in code.

ZFTurbo commented 4 years ago

I fixed problem. Earlier method works incorrect if x2 (or y2) was less than x1 (or y1), now it's automatically fixed with warning message. So latest version must be totally ok.