File size: 1,551 Bytes
2366e36
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# Copyright (c) OpenMMLab. All rights reserved.
"""Test hmean_iou."""
import pytest

import mmocr.core.evaluation.hmean_iou as hmean_iou


def test_eval_hmean_iou():

    pred_boxes = []
    gt_boxes = []
    gt_ignored_boxes = []
    iou_thr = 0.5
    precision_thr = 0.5

    # test invalid arguments.

    with pytest.raises(AssertionError):
        hmean_iou.eval_hmean_iou([1], gt_boxes, gt_ignored_boxes, iou_thr,
                                 precision_thr)
    with pytest.raises(AssertionError):
        hmean_iou.eval_hmean_iou(pred_boxes, [1], gt_ignored_boxes, iou_thr,
                                 precision_thr)
    with pytest.raises(AssertionError):
        hmean_iou.eval_hmean_iou(pred_boxes, gt_boxes, [1], iou_thr,
                                 precision_thr)
    with pytest.raises(AssertionError):
        hmean_iou.eval_hmean_iou(pred_boxes, gt_boxes, gt_ignored_boxes, 1.1,
                                 precision_thr)
    with pytest.raises(AssertionError):
        hmean_iou.eval_hmean_iou(pred_boxes, gt_boxes, gt_ignored_boxes,
                                 iou_thr, 1.1)

    pred_boxes = [[[0, 0, 1, 0, 1, 1, 0, 1], [2, 0, 3, 0, 3, 1, 2, 1]]]
    gt_boxes = [[[0, 0, 1, 0, 1, 1, 0, 1], [2, 0, 3, 0, 3, 1, 2, 1]]]
    gt_ignored_boxes = [[]]
    results = hmean_iou.eval_hmean_iou(pred_boxes, gt_boxes, gt_ignored_boxes,
                                       iou_thr, precision_thr)
    assert results[1][0]['recall'] == 1
    assert results[1][0]['precision'] == 1
    assert results[1][0]['hmean'] == 1