1111from sklearn .metrics import matthews_corrcoef as mcc
1212
1313#Data for figure 6a testing of assignment and average precision
14- ref6c1 = np .asarray ([3 ,2 ,7 ,5 ])
15- ref6c2 = np .asarray ([7 ,9 ,8 ,11 ])
16- ref6c3 = np .asarray ([1 ,16 ,3 ,18 ])
17- ref6c4 = np .asarray ([14 ,14 ,16 ,18 ])
14+ ref6a1 = np .asarray ([3 ,2 ,7 ,5 ])
15+ ref6a2 = np .asarray ([7 ,9 ,8 ,11 ])
16+ ref6a3 = np .asarray ([1 ,16 ,3 ,18 ])
17+ ref6a4 = np .asarray ([14 ,14 ,16 ,18 ])
1818
19- pred6c1 = np .asarray ([2 ,3 ,6 ,6 ])
20- pred6c2 = np .asarray ([2 ,15 ,4 ,17 ])
21- pred6c3 = np .asarray ([13 ,13 ,15 ,17 ])
22- pred6c4 = np .asarray ([16 ,7 ,19 ,10 ])
23- pred6c5 = np .asarray ([12 ,2 ,15 ,4 ])
19+ pred6a1 = np .asarray ([2 ,3 ,6 ,6 ])
20+ pred6a2 = np .asarray ([2 ,15 ,4 ,17 ])
21+ pred6a3 = np .asarray ([13 ,13 ,15 ,17 ])
22+ pred6a4 = np .asarray ([16 ,7 ,19 ,10 ])
23+ pred6a5 = np .asarray ([12 ,2 ,15 ,4 ])
2424
25- pred_proba_6c = [[0.05 , 0.95 ],[0.30 ,0.70 ],[0.20 ,0.80 ],[0.20 ,0.80 ],[0.10 ,0.90 ]]
25+ pred_proba_6a = [[0.05 , 0.95 ],[0.30 ,0.70 ],[0.20 ,0.80 ],[0.20 ,0.80 ],[0.10 ,0.90 ]]
2626
27- pred_boxes_6c = [pred6c1 , pred6c2 , pred6c3 , pred6c4 , pred6c5 ]
28- ref_boxes_6c = [ref6c1 , ref6c2 , ref6c3 , ref6c4 ]
27+ pred_boxes_6a = [pred6a1 , pred6a2 , pred6a3 , pred6a4 , pred6a5 ]
28+ ref_boxes_6a = [ref6a1 , ref6a2 , ref6a3 , ref6a4 ]
2929
30+ #Data from Panoptic Quality - 3.51 p96
31+ #Figure 3.51 p96
32+ pq_pred1 = np .zeros ([18 , 18 ])
33+ pq_pred1 [ 3 :7 ,1 :3 ] = 1
34+ pq_pred1 [3 :6 ,3 :7 ]= 1
35+ pq_pred2 = np .zeros ([18 , 18 ])
36+ pq_pred2 [13 :16 ,4 :6 ] = 1
37+ pq_pred3 = np .zeros ([18 , 18 ])
38+ pq_pred3 [7 :12 ,13 :17 ] = 1
39+ pq_pred4 = np .zeros ([18 , 18 ])
40+ pq_pred4 [13 :15 ,13 :17 ] = 1
41+ pq_pred4 [15 ,15 ] = 1
42+
43+ pq_ref1 = np .zeros ([18 , 18 ])
44+ pq_ref1 [2 :7 , 1 :3 ] = 1
45+ pq_ref1 [2 :5 ,3 :6 ] = 1
46+ pq_ref2 = np .zeros ([18 , 18 ])
47+ pq_ref2 [6 :12 ,12 :17 ] = 1
48+ pq_ref3 = np .zeros ([18 , 18 ])
49+ pq_ref3 [14 :15 :,7 :10 ] = 1
50+ pq_ref3 [13 :16 ,8 :9 ] = 1
51+
52+ ref_351 = [pq_ref1 , pq_ref2 , pq_ref3 ]
53+ pred_351 = [pq_pred1 , pq_pred2 , pq_pred3 ,pq_pred4 ]
3054
3155
3256## Data for figure 59 and testing of localisation
4165f59_pred2 [4 :8 , 5 :9 ] = 1
4266
4367def test_assignment_6c ():
44- asm1 = AssignmentMapping (pred_loc = pred_boxes_6c , ref_loc = ref_boxes_6c , pred_prob = pred_proba_6c , thresh = 0.1 ,localization = 'box_iou' )
68+ asm1 = AssignmentMapping (pred_loc = pred_boxes_6a , ref_loc = ref_boxes_6a , pred_prob = pred_proba_6a , thresh = 0.1 ,localization = 'box_iou' )
4569 df_matching , df_fn , df_fp , list_valid = asm1 .initial_mapping ()
4670 print (asm1 .matrix , df_matching , df_fp , df_fn , list_valid )
4771 numb_fn = df_fn .shape [0 ]
@@ -52,6 +76,7 @@ def test_assignment_6c():
5276 assert expected_fp == numb_fp
5377 assert_array_almost_equal (np .asarray (list_valid ),np .asarray ([0 ,1 ,2 ]))
5478
79+
5580def test_check_localization ():
5681 ref_box = [[2 ,2 ,4 ,4 ]]
5782 ref_com = [[3 ,3 ]]
@@ -209,6 +234,84 @@ def test_pairwise_pointcomdist():
209234 expected_matrix = np .asarray ([[0 , 9.22 ],[8.49 , 1 ]])
210235 assert_allclose (am .matrix , expected_matrix ,atol = 0.01 )
211236
237+ def test_pairwise_boxiou_6a ():
238+ """
239+ Using figure 6a p14 pitfalls as illustration for boxiou pairwise example
240+ """
241+ asm1 = AssignmentMapping (pred_loc = pred_boxes_6a , ref_loc = ref_boxes_6a , pred_prob = pred_proba_6a , thresh = 0.1 ,localization = 'box_iou' )
242+ df_matching , df_fn , df_fp , list_valid = asm1 .initial_mapping ()
243+ expected_matrix = np .asarray ([[0.42857143 , 0. , 0. , 0. ],
244+ [0. , 0. , 0.28571429 , 0. ],
245+ [0. , 0. , 0. , 0.36363636 ],
246+ [0. , 0. , 0. , 0. ],
247+ [0. , 0. , 0. , 0. ]])
248+ assert_array_almost_equal (expected_matrix , asm1 .matrix )
249+
250+ def test_com_from_refbox_6a ():
251+ """
252+ Using figure 6a as illustration
253+ """
254+
255+ asm1 = AssignmentMapping (pred_loc = pred_boxes_6a , ref_loc = ref_boxes_6a , pred_prob = pred_proba_6a , thresh = 0.1 ,localization = 'box_iou' )
256+ asm1 .com_fromrefbox ()
257+ test_com = asm1 .ref_loc_mod
258+ expected_ref_com = [[5 ,3.5 ],[7.5 ,10 ],[2 ,17 ],[15 ,16 ]]
259+ assert_array_almost_equal (np .asarray (expected_ref_com ), test_com )
260+
261+ def test_com_from_predbox_6a ():
262+ """
263+ Using figure 6a as illustration
264+ """
265+ asm1 = AssignmentMapping (pred_loc = pred_boxes_6a , ref_loc = ref_boxes_6a , pred_prob = pred_proba_6a , thresh = 0.1 ,localization = 'box_iou' )
266+ asm1 .com_frompredbox ()
267+ test_com = asm1 .pred_loc_mod
268+ print (test_com )
269+ expected_pred_com = [[4 ,4.5 ],[3 ,16 ],[14 ,15 ],[17.5 ,8.5 ],[13.5 ,3 ]]
270+ assert_array_almost_equal (np .asarray (expected_pred_com ), test_com ,decimal = 2 )
271+
272+ def test_comfrompredmask_351 ():
273+ """
274+ Using figure 3.51 (p96 Panoptic quality) as illustration
275+ """
276+ asm = AssignmentMapping (pred_loc = pred_351 , ref_loc = ref_351 ,pred_prob = np .asarray ([1 ,1 ,1 ,1 ]), thresh = 0.1 ,localization = 'mask_iou' )
277+ expected_predcom = [[4.2 ,3.3 ],[14 ,4.5 ],[9 ,14.5 ],[13.66 ,14.55 ]]
278+ asm .com_frompredmask ()
279+ test_com = asm .pred_loc_mod
280+ assert_array_almost_equal (np .asarray (expected_predcom ),test_com ,decimal = 2 )
281+
282+ def test_comfromrefmask_351 ():
283+ """
284+ Using figure 3.51 (p96 Panoptic quality) as illustrative example
285+ """
286+ asm = AssignmentMapping (pred_loc = pred_351 , ref_loc = ref_351 ,pred_prob = np .asarray ([1 ,1 ,1 ,1 ]), thresh = 0.1 ,localization = 'mask_iou' )
287+ expected_refcom = [[3.53 ,2.68 ],[8.5 ,14 ],[14 ,8 ]]
288+ asm .com_fromrefmask ()
289+ test_com = asm .ref_loc_mod
290+ assert_array_almost_equal (np .asarray (expected_refcom ),test_com ,decimal = 2 )
291+
292+ def test_box_fromrefmask ():
293+ """
294+ Using fig 3.51 p96 as illustrative example
295+ """
296+ asm = AssignmentMapping (pred_loc = pred_351 , ref_loc = ref_351 ,pred_prob = np .asarray ([1 ,1 ,1 ,1 ]), thresh = 0.1 ,localization = 'mask_iou' )
297+ asm .box_fromrefmask ()
298+ test_box = asm .ref_loc_mod
299+ expected_box = [[2 ,1 ,6 ,5 ],[6 ,12 ,11 ,16 ],[13 ,7 ,15 ,9 ]]
300+ assert_array_almost_equal (np .asarray (expected_box ),test_box )
301+
302+ def test_box_frompredmask ():
303+ """
304+ Using fig 3.51 p96 as illustrative example
305+ """
306+ asm = AssignmentMapping (pred_loc = pred_351 , ref_loc = ref_351 ,pred_prob = np .asarray ([1 ,1 ,1 ,1 ]), thresh = 0.1 ,localization = 'mask_iou' )
307+ asm .box_frompredmask ()
308+ test_box = asm .pred_loc_mod
309+ expected_box = [[3 ,1 ,6 ,6 ],[13 ,4 ,15 ,5 ],[7 ,13 ,11 ,16 ],[13 ,13 ,15 ,16 ]]
310+ assert_array_almost_equal (np .asarray (expected_box ),test_box )
311+
312+
313+
314+
212315
213316def test_localization ():
214317 ref = [f59_ref1 , f59_ref2 ]
0 commit comments