def test_transform4():
    # Test w/ 1 overlapping boxes
    boxes, confidences, labels, bbids = setup_tests.setup_test_case()

    boxes, confidences, labels, bbids = setup_tests.jitter_boxes(
        bounding_boxes=boxes,
        confidences=confidences,
        labels=labels,
        bbids=bbids,
        range_n_new_boxes=(5, 5))

    bb = od.BoundingBoxArray(bounding_boxes=boxes,
                             confidences=confidences,
                             labels=labels,
                             bounding_box_ids=bbids)

    metric, selector = setup_tests.get_default_sector_suppressor_components()
    suppressor = od.nms.suppression.CartesianProductSuppression(
        metric=metric, selector=selector)

    resulting_bb = suppressor.transform(bb)
    assert len(resulting_bb.bounding_box_ids) == 2
    assert resulting_bb.bounding_boxes.shape[0] == 2

    resulting_box1 = resulting_bb.bounding_boxes[0, :, :]
    resulting_box2 = resulting_bb.bounding_boxes[1, :, :]
    assert not metric.overlap(resulting_box1, resulting_box2)
def test_evaluate_overlap3():
    # Test method 5 overlapping boxes each
    boxes, confidences, labels, bbids = setup_tests.setup_test_case()

    boxes, confidences, labels, bbids = setup_tests.jitter_boxes(
        bounding_boxes=boxes,
        confidences=confidences,
        labels=labels,
        bbids=bbids,
        range_n_new_boxes=(5, 5))

    bb = od.BoundingBoxArray(bounding_boxes=boxes,
                             confidences=confidences,
                             labels=labels,
                             bounding_box_ids=bbids)
    bbid_cp = itertools.product(bb.bounding_box_ids.tolist(),
                                bb.bounding_box_ids.tolist())

    metric, selector = setup_tests.get_default_sector_suppressor_components()
    suppressor = od.nms.suppression.CartesianProductSuppression(
        metric=metric, selector=selector)

    selected_bids, _ = suppressor._evaluate_overlap(bb,
                                                    bbid_cp,
                                                    symmetric=True)
    assert len(selected_bids) == 2

    resulting_box1 = bb.lookup_box(int(selected_bids[0]))
    resulting_box2 = bb.lookup_box(int(selected_bids[1]))
    assert not metric.overlap(resulting_box1, resulting_box2)
def test_handle_boundaries7():
    # Handle boundaries - two sets of boxes (5 overlap each) on boundaries w/ 2 division
    boxes, confidences, labels, bbids = setup_tests.setup_test_case_on_boundary()

    boxes, confidences, labels, bbids = setup_tests.jitter_boxes(
        bounding_boxes=boxes,
        confidences=confidences,
        labels=labels,
        bbids=bbids,
        range_n_new_boxes=(5, 5)
    )

    bb = od.BoundingBoxArray(
        bounding_boxes=boxes,
        confidences=confidences,
        labels=labels,
        bounding_box_ids=bbids
    )
    bb.check()

    sector_divisions = 2
    metric, selector = setup_tests.get_default_sector_suppressor_components()
    suppressor = od.nms.suppression.SectorSuppression(metric=metric, selector=selector,
                                                      sector_divisions=sector_divisions)
    _, dividing_lines = suppressor._create_sectors()
    result = suppressor._handle_boundaries(bb, dividing_lines)
    assert len(result) == 2
def test_evaluate_overlap1():
    # Tests method without any overlapping boxes
    boxes, confidences, labels, bbids = setup_tests.setup_test_case()
    bb = od.BoundingBoxArray(bounding_boxes=boxes,
                             confidences=confidences,
                             labels=labels,
                             bounding_box_ids=bbids)
    bbid_cp = itertools.product(bb.bounding_box_ids.tolist(),
                                bb.bounding_box_ids.tolist())

    metric, selector = setup_tests.get_default_sector_suppressor_components()
    suppressor = od.nms.suppression.CartesianProductSuppression(
        metric=metric, selector=selector)

    selected_bids, _ = suppressor._evaluate_overlap(bb, bbid_cp)
    assert len(selected_bids) == 2
def test_handle_boundaries2():
    # Handle boundaries - two non-overlapping boxes on boundaries w/ 1 division.
    boxes, confidences, labels, bbids = setup_tests.setup_test_case_on_boundary()
    bb = od.BoundingBoxArray(
        bounding_boxes=boxes,
        confidences=confidences,
        labels=labels,
        bounding_box_ids=bbids
    )

    sector_divisions = 1
    metric, selector = setup_tests.get_default_sector_suppressor_components()
    suppressor = od.nms.suppression.SectorSuppression(metric=metric, selector=selector, sector_divisions=sector_divisions)
    _, dividing_lines = suppressor._create_sectors()
    result = suppressor._handle_boundaries(bb, dividing_lines)
    assert len(result) == 1
def test_handle_boundaries1():
    # Handle boundaries - no boxes on boundaries.
    boxes, confidences, labels, bbids = setup_tests.setup_test_case()
    bb = od.BoundingBoxArray(
        bounding_boxes=boxes,
        confidences=confidences,
        labels=labels,
        bounding_box_ids=bbids
    )

    sector_divisions = 1
    metric, selector = setup_tests.get_default_sector_suppressor_components()
    suppressor = od.nms.suppression.SectorSuppression(metric=metric, selector=selector, sector_divisions=sector_divisions)
    _, dividing_lines = suppressor._create_sectors()
    result = suppressor._handle_boundaries(bb, dividing_lines)
    assert result is None
Пример #7
0
def test_consensus_aggregator():
    bboxes = [od.BoundingBoxArray(*x) for x in setup_test_case_multi()]

    suppressor_metric = od.nms.metrics.DefaultIntersectionOverTheUnion(
        threshold=0.05, direction="gte")
    suppressor_selector = od.nms.selection.RandomSelector()
    suppressor = od.nms.suppression.CartesianProductSuppression(
        metric=suppressor_metric, selector=suppressor_selector)

    aggregator_metric = od.nms.metrics.DefaultIntersectionOverTheUnion(
        threshold=0.05, direction="gte")
    aggregator = od.nms.aggregators.ConsensusAggregator(
        suppressor=suppressor, metric=aggregator_metric)
    result = aggregator.transform(bboxes)

    assert result.shape[0] == 2
Пример #8
0
def run_test_end_to_end(n_boxes: int,
                        suppressor: od.nms.suppression.Suppressor):
    bounding_boxes, confidences, labels, bbids = setup_test_case()
    n = copy(bounding_boxes.shape[0])

    bounding_boxes, confidences, labels, _ = jitter_boxes(
        bounding_boxes,
        confidences,
        labels,
        bbids,
        range_n_new_boxes=(n_boxes, n_boxes),
    )

    data_payload = od.BoundingBoxArray(bounding_boxes=bounding_boxes,
                                       confidences=confidences,
                                       labels=labels)

    filtered_boxes = suppressor.transform(bounding_box_array=data_payload)
    assert len(filtered_boxes) == n