Exemplo n.º 1
0
def test_poly_iou():

    # test unsupported type
    with pytest.raises(AssertionError):
        utils.poly_iou([1], [2])

    points = [0, 0, 0, 1, 1, 1, 1, 0]
    points1 = [10, 20, 30, 40, 50, 60, 70, 80]
    points2 = [0, 0, 0, 0, 0, 0, 0, 0]  # Invalid polygon
    points3 = [0, 0, 0, 1, 1, 0, 1, 1]  # Self-intersected polygon

    poly = utils.points2polygon(points)
    poly1 = utils.points2polygon(points1)
    poly2 = utils.points2polygon(points2)
    poly3 = utils.points2polygon(points3)

    assert utils.poly_iou(poly, poly1) == 0

    # test overlapping polygons
    assert utils.poly_iou(poly, poly) == 1

    # test invalid polygons
    assert utils.poly_iou(poly2, poly2) == 0
    assert utils.poly_iou(poly3, poly3, zero_division=1) == 1
    assert utils.poly_iou(poly2, poly3) == 0
Exemplo n.º 2
0
def test_points2boundary():

    points = np.array([[1, 2]])
    text_repr_type = 'quad'
    text_score = None

    # test invalid arguments
    with pytest.raises(AssertionError):
        mask_utils.points2boundary([], text_repr_type, text_score)

    with pytest.raises(AssertionError):
        mask_utils.points2boundary(points, '', text_score)
    with pytest.raises(AssertionError):
        mask_utils.points2boundary(points, '', 1.1)

    # test quad
    points = np.array([[0, 0], [1, 0], [2, 0], [0, 1], [1, 1], [2, 1], [0, 2],
                       [1, 2], [2, 2]])
    text_repr_type = 'quad'
    text_score = None

    result = mask_utils.points2boundary(points, text_repr_type, text_score)
    pred_poly = eval_utils.points2polygon(result)
    target_poly = eval_utils.points2polygon([2, 2, 0, 2, 0, 0, 2, 0])
    assert eval_utils.poly_iou(pred_poly, target_poly) == 1

    # test poly
    text_repr_type = 'poly'
    result = mask_utils.points2boundary(points, text_repr_type, text_score)
    pred_poly = eval_utils.points2polygon(result)
    target_poly = eval_utils.points2polygon([0, 0, 0, 2, 2, 2, 2, 0])
    assert eval_utils.poly_iou(pred_poly, target_poly) == 1
Exemplo n.º 3
0
def test_points2polygon():

    # test unsupported type
    with pytest.raises(AssertionError):
        points = 2
        utils.points2polygon(points)

    # test unsupported size
    with pytest.raises(AssertionError):
        points = [1, 2, 3, 4, 5, 6, 7]
        utils.points2polygon(points)
    with pytest.raises(AssertionError):
        points = [1, 2, 3, 4, 5, 6]
        utils.points2polygon(points)

    # test np.array
    points = np.array([1, 2, 3, 4, 5, 6, 7, 8])
    poly = utils.points2polygon(points)
    i = 0
    for coord in poly.exterior.coords[:-1]:
        assert coord[0] == points[i]
        assert coord[1] == points[i + 1]
        i += 2

    points = [1, 2, 3, 4, 5, 6, 7, 8]
    poly = utils.points2polygon(points)
    i = 0
    for coord in poly.exterior.coords[:-1]:
        assert coord[0] == points[i]
        assert coord[1] == points[i + 1]
        i += 2
Exemplo n.º 4
0
def test_poly_iou():

    # test unsupported type
    with pytest.raises(AssertionError):
        utils.poly_iou([1], [2])

    points = [0, 0, 0, 1, 1, 1, 1, 0]
    points1 = [10, 20, 30, 40, 50, 60, 70, 80]
    poly = utils.points2polygon(points)
    poly1 = utils.points2polygon(points1)

    assert utils.poly_iou(poly, poly1) == 0

    # test overlapping polygons

    assert utils.poly_iou(poly, poly) == 1
Exemplo n.º 5
0
def test_poly_union():

    # test unsupported type
    with pytest.raises(AssertionError):
        utils.poly_union(0, 1)

    # test non-overlapping polygons

    points = [0, 0, 0, 1, 1, 1, 1, 0]
    points1 = [2, 2, 2, 3, 3, 3, 3, 2]
    poly = utils.points2polygon(points)
    poly1 = utils.points2polygon(points1)

    assert utils.poly_union(poly, poly1) == 2

    # test overlapping polygons
    assert utils.poly_union(poly, poly) == 1
Exemplo n.º 6
0
def test_seg2boundary():

    seg = np.array([[]])
    text_repr_type = 'quad'
    text_score = None
    # test invalid arguments
    with pytest.raises(AssertionError):
        mask_utils.seg2boundary([[]], text_repr_type, text_score)
    with pytest.raises(AssertionError):
        mask_utils.seg2boundary(seg, 1, text_score)
    with pytest.raises(AssertionError):
        mask_utils.seg2boundary(seg, text_repr_type, 1.1)

    seg = np.array([[1, 1, 1], [1, 1, 1], [1, 1, 1]])
    result = mask_utils.seg2boundary(seg, text_repr_type, text_score)
    pred_poly = eval_utils.points2polygon(result)
    target_poly = eval_utils.points2polygon([2, 2, 0, 2, 0, 0, 2, 0])
    assert eval_utils.poly_iou(pred_poly, target_poly) == 1
Exemplo n.º 7
0
def test_poly_intersection():

    # test unsupported type
    with pytest.raises(AssertionError):
        utils.poly_intersection(0, 1)

    # test non-overlapping polygons

    points = [0, 0, 0, 1, 1, 1, 1, 0]
    points1 = [10, 20, 30, 40, 50, 60, 70, 80]
    points2 = [0, 0, 0, 0, 0, 0, 0, 0]  # Invalid polygon
    points3 = [0, 0, 0, 1, 1, 0, 1, 1]  # Self-intersected polygon
    points4 = [0.5, 0, 1.5, 0, 1.5, 1, 0.5, 1]
    poly = utils.points2polygon(points)
    poly1 = utils.points2polygon(points1)
    poly2 = utils.points2polygon(points2)
    poly3 = utils.points2polygon(points3)
    poly4 = utils.points2polygon(points4)

    area_inters = utils.poly_intersection(poly, poly1)

    assert area_inters == 0

    # test overlapping polygons
    area_inters = utils.poly_intersection(poly, poly)
    assert area_inters == 1
    area_inters = utils.poly_intersection(poly, poly4)
    assert area_inters == 0.5

    # test invalid polygons
    assert utils.poly_intersection(poly2, poly2) == 0
    assert utils.poly_intersection(poly3, poly3, invalid_ret=1) == 1
    # The return value depends on the implementation of the package
    assert utils.poly_intersection(poly3, poly3, invalid_ret=None) == 0.25

    # test poly return
    _, poly = utils.poly_intersection(poly, poly4, return_poly=True)
    assert isinstance(poly, Polygon)
    _, poly = utils.poly_intersection(
        poly3, poly3, invalid_ret=None, return_poly=True)
    assert isinstance(poly, Polygon)
    _, poly = utils.poly_intersection(
        poly2, poly3, invalid_ret=1, return_poly=True)
    assert poly is None
Exemplo n.º 8
0
def test_compute_recall_precision():

    gt_polys = []
    det_polys = []

    # test invalid arguments.
    with pytest.raises(AssertionError):
        hmean_ic13.compute_recall_precision(1, 1)

    box1 = [0, 0, 1, 0, 1, 1, 0, 1]

    box2 = [0, 0, 10, 0, 10, 1, 0, 1]

    gt_polys = [utils.points2polygon(box1)]
    det_polys = [utils.points2polygon(box2)]
    recall, precision = hmean_ic13.compute_recall_precision(
        gt_polys, det_polys)
    assert recall == 1
    assert precision == 0.1
Exemplo n.º 9
0
def test_poly_intersection():

    # test unsupported type
    with pytest.raises(AssertionError):
        utils.poly_intersection(0, 1)

    # test non-overlapping polygons

    points = [0, 0, 0, 1, 1, 1, 1, 0]
    points1 = [10, 20, 30, 40, 50, 60, 70, 80]
    poly = utils.points2polygon(points)
    poly1 = utils.points2polygon(points1)

    area_inters, _ = utils.poly_intersection(poly, poly1)

    assert area_inters == 0

    # test overlapping polygons
    area_inters, _ = utils.poly_intersection(poly, poly)
    assert area_inters == 1
Exemplo n.º 10
0
def test_poly_union():

    # test unsupported type
    with pytest.raises(AssertionError):
        utils.poly_union(0, 1)

    # test non-overlapping polygons

    points = [0, 0, 0, 1, 1, 1, 1, 0]
    points1 = [2, 2, 2, 3, 3, 3, 3, 2]
    points2 = [0, 0, 0, 0, 0, 0, 0, 0]  # Invalid polygon
    points3 = [0, 0, 0, 1, 1, 0, 1, 1]  # Self-intersected polygon
    points4 = [0.5, 0.5, 1, 0, 1, 1, 0.5, 0.5]
    poly = utils.points2polygon(points)
    poly1 = utils.points2polygon(points1)
    poly2 = utils.points2polygon(points2)
    poly3 = utils.points2polygon(points3)
    poly4 = utils.points2polygon(points4)

    assert utils.poly_union(poly, poly1) == 2

    # test overlapping polygons
    assert utils.poly_union(poly, poly) == 1

    # test invalid polygons
    assert utils.poly_union(poly2, poly2) == 0
    assert utils.poly_union(poly3, poly3, invalid_ret=1) == 1

    # The return value depends on the implementation of the package
    assert utils.poly_union(poly3, poly3, invalid_ret=None) == 0.25
    assert utils.poly_union(poly2, poly3) == 0.25
    assert utils.poly_union(poly3, poly4) == 0.5

    # test poly return
    _, poly = utils.poly_union(poly, poly1, return_poly=True)
    assert isinstance(poly, MultiPolygon)
    _, poly = utils.poly_union(poly3, poly3, return_poly=True)
    assert isinstance(poly, Polygon)
    _, poly = utils.poly_union(poly2, poly3, invalid_ret=0, return_poly=True)
    assert poly is None
Exemplo n.º 11
0
def test_ignore_pred():

    # test invalid arguments
    box = [0, 0, 1, 0, 1, 1, 0, 1]
    det_boxes = [box]
    gt_dont_care_index = [0]
    gt_polys = [utils.points2polygon(box)]
    precision_thr = 0.5

    with pytest.raises(AssertionError):
        det_boxes_tmp = 1
        utils.ignore_pred(det_boxes_tmp, gt_dont_care_index, gt_polys,
                          precision_thr)
    with pytest.raises(AssertionError):
        gt_dont_care_index_tmp = 1
        utils.ignore_pred(det_boxes, gt_dont_care_index_tmp, gt_polys,
                          precision_thr)
    with pytest.raises(AssertionError):
        gt_polys_tmp = 1
        utils.ignore_pred(det_boxes, gt_dont_care_index, gt_polys_tmp,
                          precision_thr)
    with pytest.raises(AssertionError):
        precision_thr_tmp = 1.1
        utils.ignore_pred(det_boxes, gt_dont_care_index, gt_polys,
                          precision_thr_tmp)

    # test ignored cases
    result = utils.ignore_pred(det_boxes, gt_dont_care_index, gt_polys,
                               precision_thr)
    assert result[2] == [0]
    # test unignored cases
    gt_dont_care_index_tmp = []
    result = utils.ignore_pred(det_boxes, gt_dont_care_index_tmp, gt_polys,
                               precision_thr)
    assert result[2] == []

    det_boxes_tmp = [[10, 10, 15, 10, 15, 15, 10, 15]]
    result = utils.ignore_pred(det_boxes_tmp, gt_dont_care_index, gt_polys,
                               precision_thr)
    assert result[2] == []
Exemplo n.º 12
0
def test_points2polygon():

    # test unsupported type
    with pytest.raises(AssertionError):
        points = 2
        utils.points2polygon(points)

    # test unsupported size
    with pytest.raises(AssertionError):
        points = [1, 2, 3, 4, 5, 6, 7]
        utils.points2polygon(points)
    with pytest.raises(AssertionError):
        points = [1, 2, 3, 4, 5, 6]
        utils.points2polygon(points)

    # test np.array
    points = np.array([1, 2, 3, 4, 5, 6, 7, 8])
    poly = utils.points2polygon(points)
    assert poly.nPoints() == 4

    points = [1, 2, 3, 4, 5, 6, 7, 8]
    poly = utils.points2polygon(points)
    assert poly.nPoints() == 4