def test_get_hit_rank_match_topn(): """It tests the cases that it overlaps some box but the results depends on the choice of topn. """ # Test the case that it overlaps some box but # the matched label is of the rank not covered by topn. actual = p.get_hit_rank(test_box_pred, test_boxes_truth, topn=1, iou_th=0.1) expected = { 'max_iou': 1 / (4 * 2), 'is_box_detected': True, 'rank': -1, 'label': '', } assert actual == expected # Test the case that it overlaps some box and # it returns the rank of label predicted. actual = p.get_hit_rank(test_box_pred, test_boxes_truth, topn=3, iou_th=0.1) expected = { 'max_iou': 1 / (4 * 2), 'is_box_detected': True, 'rank': 1, 'label': 'angela', } assert actual == expected # Test the case that it overlaps some box and # the topn input is too large. actual = p.get_hit_rank(test_box_pred, test_boxes_truth, topn=100, iou_th=0.1) expected = { 'max_iou': 1 / (4 * 2), 'is_box_detected': True, 'rank': 1, 'label': 'angela', } assert actual == expected
def test_get_hit_rank_no_overlap(): """It tests the case that no box overlaps the ground truth. """ actual = p.get_hit_rank(test_box_pred, [test_box_no_overlap], topn=10, iou_th=0.9) expected = { 'max_iou': 0.0, 'is_box_detected': False, 'rank': -1, 'label': '', } assert actual == expected
def test_get_hit_rank_iou_too_low(): """It tests the case that the iou of all the boxes are lower than the threshold. """ actual = p.get_hit_rank(test_box_pred, test_boxes_truth, topn=10, iou_th=0.9) # The candidate is the test_box_high_iou with iou 1 / (4 * 2) expected = { 'max_iou': 1 / (4 * 2), 'is_box_detected': False, 'rank': 1, 'label': 'angela', } assert actual == expected
def test_get_hit_rank_wrong_label(): """It tests the case that it overlaps to some box but no label matches. """ boxes_truth = [ Box(label='no_one_matches', upper_left=test_upper_left, width=test_width, height=test_height) ] actual = p.get_hit_rank(test_box_pred, boxes_truth, topn=4, iou_th=0.9) expected = { 'max_iou': 1.0, 'is_box_detected': True, 'rank': -1, 'label': '', } assert actual == expected
data[idx]['prediction'] = img print('>> Number of boxes predicted:', sum([len(x['prediction'].boxes) for x in data])) print('-' * 40) is_match = is_match_type(args['--match']) results = {} for idx, datum in enumerate(data): box_list = [] for box in datum['prediction'].boxes: print('>> Prediction Box:', box) print('>> Ground Truth :', datum['truth'].boxes) result = get_hit_rank(box, datum['truth'].boxes, 5, is_match=is_match) print('>> Result:', result) box_list.append(result) datum['results'] = box_list results[datum['prediction'].fname] = box_list print('---------------------------------------') for k, v in results.items(): print('Key:', k) print('>> Values:') for x in v: print(x) print('-' * 40)