예제 #1
0
def test_boundary_iou():
    points = [0, 0, 0, 1, 1, 1, 1, 0]
    points1 = [10, 20, 30, 40, 50, 60, 70, 80]

    assert utils.boundary_iou(points, points1) == 0

    # test overlapping boundaries
    assert utils.boundary_iou(points, points) == 1
예제 #2
0
def test_boundary_iou():
    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

    assert utils.boundary_iou(points, points1) == 0

    # test overlapping boundaries
    assert utils.boundary_iou(points, points) == 1

    # test invalid boundaries
    assert utils.boundary_iou(points2, points2) == 0
    assert utils.boundary_iou(points3, points3, zero_division=1) == 1
    assert utils.boundary_iou(points2, points3) == 0
예제 #3
0
def test_ocr_mask_rcnn(cfg_file):
    model = _get_detector_cfg(cfg_file)
    model['pretrained'] = None

    from mmocr.models import build_detector
    detector = build_detector(model)

    input_shape = (1, 3, 224, 224)
    mm_inputs = _demo_mm_inputs(0, input_shape)

    imgs = mm_inputs.pop('imgs')
    img_metas = mm_inputs.pop('img_metas')
    gt_labels = mm_inputs.pop('gt_labels')
    gt_masks = mm_inputs.pop('gt_masks')

    # Test forward train
    gt_bboxes = mm_inputs['gt_bboxes']
    losses = detector.forward(
        imgs,
        img_metas,
        gt_bboxes=gt_bboxes,
        gt_labels=gt_labels,
        gt_masks=gt_masks)
    assert isinstance(losses, dict)

    # Test forward test
    with torch.no_grad():
        img_list = [g[None, :] for g in imgs]
        batch_results = []
        for one_img, one_meta in zip(img_list, img_metas):
            result = detector.forward([one_img], [[one_meta]],
                                      return_loss=False)
            batch_results.append(result)

    # Test get_boundary
    results = ([[[1]]], [[
        np.array([[1, 1, 0, 0, 0], [1, 1, 0, 0, 0], [0, 0, 0, 0, 0],
                  [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]])
    ]])

    boundaries = detector.get_boundary(results)
    assert utils.boundary_iou(boundaries['boundary_result'][0][:-1],
                              [1, 1, 0, 1, 0, 0, 1, 0]) == 1

    # Test show_result

    results = {'boundary_result': [[0, 0, 1, 0, 1, 1, 0, 1, 0.9]]}
    img = np.random.rand(5, 5)
    detector.show_result(img, results)
예제 #4
0
파일: wrapper.py 프로젝트: RangiLyu/mmocr
def poly_nms(polygons, threshold):
    assert isinstance(polygons, list)

    polygons = np.array(sorted(polygons, key=lambda x: x[-1]))

    keep_poly = []
    index = [i for i in range(polygons.shape[0])]

    while len(index) > 0:
        keep_poly.append(polygons[index[-1]].tolist())
        A = polygons[index[-1]][:-1]
        index = np.delete(index, -1)

        iou_list = np.zeros((len(index), ))
        for i in range(len(index)):
            B = polygons[index[i]][:-1]

            iou_list[i] = boundary_iou(A, B)
        remove_index = np.where(iou_list > threshold)
        index = np.delete(index, remove_index)

    return keep_poly