|
51 | 51 | ref_351 = [pq_ref1, pq_ref2, pq_ref3] |
52 | 52 | pred_351 = [pq_pred1, pq_pred2, pq_pred3,pq_pred4] |
53 | 53 |
|
| 54 | +pred_com_351 = [np.asarray([4.5,2]), np.asarray([14,5]), np.asarray([9,14.5]), np.asarray([13.5,14.5])] |
| 55 | + |
54 | 56 |
|
55 | 57 | ## Data for figure 59 and testing of localisation |
56 | 58 | f59_ref1 = np.zeros([15, 15]) |
|
63 | 65 | f59_pred2 = np.zeros([15, 15]) |
64 | 66 | f59_pred2[4:8, 5:9] = 1 |
65 | 67 |
|
| 68 | +def test_pixdim_info(): |
| 69 | + asm = AssignmentMapping(pred_loc = pred_351, ref_loc=ref_351, pred_prob=[0.4, 0.6, 0.3, 0.9]) |
| 70 | + asm2 = AssignmentMapping(pred_loc=[], ref_loc=ref_351, pred_prob=[]) |
| 71 | + assert_allclose(asm.pixdim,[1,1]) |
| 72 | + assert_allclose(asm2.pixdim,[1,1]) |
| 73 | + |
| 74 | +def test_not_suitable_localisation(): |
| 75 | + asm = AssignmentMapping(pred_loc=pred_com_351, ref_loc=ref_351, pred_prob=[0.4, 0.6, 0.3, 0.9], localization='box_iou') |
| 76 | + assert not asm.flag_usable |
| 77 | + assert asm.df_matching is None |
| 78 | + |
| 79 | +def test_emptyref_flags(): |
| 80 | + asm = AssignmentMapping(pred_loc=pred_351, ref_loc=[], pred_prob=[0.4, 0.6, 0.3, 0.9]) |
| 81 | + assert asm.flag_usable |
| 82 | + |
| 83 | +def test_not_good_localisation_option(): |
| 84 | + asm = AssignmentMapping(pred_loc = pred_351, ref_loc=ref_351, pred_prob=[0.4, 0.6, 0.3, 0.9], localization='mask_iop') |
| 85 | + assert not asm.flag_usable |
| 86 | + |
| 87 | +def test_boundaryiou_loc(): |
| 88 | + asm = AssignmentMapping(pred_loc = pred_351, ref_loc=ref_351, pred_prob=[0.4, 0.6, 0.3, 0.9], localization='boundary_iou') |
| 89 | + assert asm.matrix[0,1] == 0 |
| 90 | + |
| 91 | +def test_input_boxcom_maskcom(): |
| 92 | + asm1 = AssignmentMapping(pred_loc=pred_boxes_6a, ref_loc=ref_boxes_6a, pred_prob=pred_proba_6a, localization='box_com') |
| 93 | + asm2 = AssignmentMapping(pred_loc = pred_351, ref_loc=ref_351, pred_prob=[0.4, 0.6, 0.3, 0.9], localization='box_com') |
| 94 | + assert asm1.flag_refmod |
| 95 | + assert asm1.flag_predmod |
| 96 | + assert asm2.flag_refmod |
| 97 | + assert asm2.flag_predmod |
| 98 | + |
| 99 | +def test_input_pim_maskmask(): |
| 100 | + asm2 = AssignmentMapping(pred_loc = pred_351, ref_loc=ref_351, pred_prob=[0.4, 0.6, 0.3, 0.9], localization='point_in_mask') |
| 101 | + assert not asm2.flag_usable |
| 102 | + |
| 103 | +def test_input_pib_pm(): |
| 104 | + asm = AssignmentMapping(pred_loc=pred_com_351, ref_loc=ref_351, pred_prob=[0.4, 0.6, 0.3, 0.9], localization='point_in_box') |
| 105 | + matrix_pib = asm.pairwise_pointinbox() |
| 106 | + assert asm.flag_refmod |
| 107 | + assert matrix_pib[0,0] == 1 |
| 108 | + |
| 109 | + |
66 | 110 | def test_assignment_6c(): |
67 | 111 | asm1 = AssignmentMapping(pred_loc=pred_boxes_6a, ref_loc=ref_boxes_6a, pred_prob=pred_proba_6a, thresh=0.1,localization='box_iou') |
68 | 112 | df_matching, df_fn, df_fp, list_valid = asm1.initial_mapping() |
@@ -222,6 +266,11 @@ def test_pairwise_pointinbox(): |
222 | 266 | expected_matrix = np.asarray([[1,0],[0,0]]) |
223 | 267 | assert_allclose(am.matrix, expected_matrix) |
224 | 268 |
|
| 269 | +def test_pairwise_pointinbox_pm(): |
| 270 | + asm = AssignmentMapping(pred_com_351, ref_351,[1,1,1,1],'point_in_box') |
| 271 | + assert asm.matrix[0,0] == 1 |
| 272 | + |
| 273 | + |
225 | 274 | def test_pairwise_pointcomdist(): |
226 | 275 | ref1 = [3,4] |
227 | 276 | ref2 = [10,10] |
@@ -257,6 +306,11 @@ def test_com_from_refbox_6a(): |
257 | 306 | expected_ref_com = [[5,3.5],[7.5,10],[2,17],[15,16]] |
258 | 307 | assert_array_almost_equal(np.asarray(expected_ref_com), test_com) |
259 | 308 |
|
| 309 | +def test_pairwise_boxior_mm(): |
| 310 | + asm = AssignmentMapping(pred_351, ref_351,[1,1,1,1],'box_ior') |
| 311 | + assert asm.matrix[0,0] == 0.8 |
| 312 | + |
| 313 | + |
260 | 314 | def test_com_from_predbox_6a(): |
261 | 315 | """ |
262 | 316 | Using figure 6a as illustration |
@@ -308,6 +362,23 @@ def test_box_frompredmask(): |
308 | 362 | expected_box = [[3,1,6,6],[13,4,15,5],[7,13,11,16],[13,13,15,16]] |
309 | 363 | assert_array_almost_equal(np.asarray(expected_box),test_box) |
310 | 364 |
|
| 365 | +def test_matching_ambiguity(): |
| 366 | + ref_box = np.asarray([2,3,10,11]) |
| 367 | + pred_box1 = np.asarray([1,1,8,8]) |
| 368 | + pred_box2 = np.asarray([2,8,11,11]) |
| 369 | + ref = [ref_box] |
| 370 | + pred = [pred_box1, pred_box2] |
| 371 | + asm = AssignmentMapping(pred, ref,[0.5,1],thresh=0.1,localization='box_iou') |
| 372 | + asm_h = AssignmentMapping(pred, ref,[0.5,1],thresh=0.1,localization='box_iou',assignment='hungarian') |
| 373 | + asm_p = AssignmentMapping(pred, ref,[0.5,1],thresh=0.1,localization='box_iou',assignment='greedy_performance') |
| 374 | + df_match, list_val = asm.resolve_ambiguities_matching() |
| 375 | + df_match_h, list_val_h = asm_h.resolve_ambiguities_matching() |
| 376 | + df_match_p, list_val_p = asm_p.resolve_ambiguities_matching() |
| 377 | + print(df_match, df_match_h, df_match_p) |
| 378 | + assert df_match.shape[0] == 2 |
| 379 | + assert df_match_h.shape[0] == 2 |
| 380 | + assert df_match_p.shape[0] == 2 |
| 381 | + |
311 | 382 |
|
312 | 383 | def test_localization(): |
313 | 384 | ref = [f59_ref1, f59_ref2] |
@@ -349,3 +420,9 @@ def test_localization(): |
349 | 420 | np.asarray(m12[m12["pred"] == 0]["ref"])[0] == 0 |
350 | 421 | and np.asarray(m21[m21["pred"] == 0]["ref"])[0] == -1 |
351 | 422 | ) |
| 423 | + |
| 424 | + |
| 425 | + |
| 426 | + |
| 427 | + |
| 428 | + |
0 commit comments