@@ -62,7 +62,8 @@ def tpfp_imagenet(det_bboxes,
62
62
gt_bboxes_ignore = None ,
63
63
default_iou_thr = 0.5 ,
64
64
area_ranges = None ,
65
- use_legacy_coordinate = False ):
65
+ use_legacy_coordinate = False ,
66
+ ** kwargs ):
66
67
"""Check if detected bboxes are true positive or false positive.
67
68
68
69
Args:
@@ -170,7 +171,8 @@ def tpfp_default(det_bboxes,
170
171
gt_bboxes_ignore = None ,
171
172
iou_thr = 0.5 ,
172
173
area_ranges = None ,
173
- use_legacy_coordinate = False ):
174
+ use_legacy_coordinate = False ,
175
+ ** kwargs ):
174
176
"""Check if detected bboxes are true positive or false positive.
175
177
176
178
Args:
@@ -275,7 +277,8 @@ def tpfp_openimages(det_bboxes,
275
277
use_legacy_coordinate = False ,
276
278
gt_bboxes_group_of = None ,
277
279
use_group_of = True ,
278
- ioa_thr = 0.5 ):
280
+ ioa_thr = 0.5 ,
281
+ ** kwargs ):
279
282
"""Check if detected bboxes are true positive or false positive.
280
283
281
284
Args:
@@ -585,7 +588,13 @@ def eval_map(det_results,
585
588
area_ranges = ([(rg [0 ]** 2 , rg [1 ]** 2 ) for rg in scale_ranges ]
586
589
if scale_ranges is not None else None )
587
590
588
- pool = Pool (nproc )
591
+ # There is no need to use multi processes to process
592
+ # when num_imgs = 1 .
593
+ if num_imgs > 1 :
594
+ assert nproc > 0 , 'nproc must be at least one.'
595
+ nproc = min (nproc , num_imgs )
596
+ pool = Pool (nproc )
597
+
589
598
eval_results = []
590
599
for i in range (num_classes ):
591
600
# get gt and det bboxes of this class
@@ -603,21 +612,38 @@ def eval_map(det_results,
603
612
if not callable (tpfp_fn ):
604
613
raise ValueError (
605
614
f'tpfp_fn has to be a function or None, but got { tpfp_fn } ' )
606
- args = []
607
- if use_group_of :
608
- # used in Open Images Dataset evaluation
609
- gt_group_ofs = get_cls_group_ofs (annotations , i )
610
- args .append (gt_group_ofs )
611
- args .append ([use_group_of for _ in range (num_imgs )])
612
- if ioa_thr is not None :
613
- args .append ([ioa_thr for _ in range (num_imgs )])
614
- # compute tp and fp for each image with multiple processes
615
- tpfp = pool .starmap (
616
- tpfp_fn ,
617
- zip (cls_dets , cls_gts , cls_gts_ignore ,
618
- [iou_thr for _ in range (num_imgs )],
619
- [area_ranges for _ in range (num_imgs )],
620
- [use_legacy_coordinate for _ in range (num_imgs )], * args ))
615
+
616
+ if num_imgs > 1 :
617
+ # compute tp and fp for each image with multiple processes
618
+ args = []
619
+ if use_group_of :
620
+ # used in Open Images Dataset evaluation
621
+ gt_group_ofs = get_cls_group_ofs (annotations , i )
622
+ args .append (gt_group_ofs )
623
+ args .append ([use_group_of for _ in range (num_imgs )])
624
+ if ioa_thr is not None :
625
+ args .append ([ioa_thr for _ in range (num_imgs )])
626
+
627
+ tpfp = pool .starmap (
628
+ tpfp_fn ,
629
+ zip (cls_dets , cls_gts , cls_gts_ignore ,
630
+ [iou_thr for _ in range (num_imgs )],
631
+ [area_ranges for _ in range (num_imgs )],
632
+ [use_legacy_coordinate for _ in range (num_imgs )], * args ))
633
+ else :
634
+ tpfp = tpfp_fn (
635
+ cls_dets [0 ],
636
+ cls_gts [0 ],
637
+ cls_gts_ignore [0 ],
638
+ iou_thr ,
639
+ area_ranges ,
640
+ use_legacy_coordinate ,
641
+ gt_bboxes_group_of = (get_cls_group_ofs (annotations , i )[0 ]
642
+ if use_group_of else None ),
643
+ use_group_of = use_group_of ,
644
+ ioa_thr = ioa_thr )
645
+ tpfp = [tpfp ]
646
+
621
647
if use_group_of :
622
648
tp , fp , cls_dets = tuple (zip (* tpfp ))
623
649
else :
@@ -660,7 +686,10 @@ def eval_map(det_results,
660
686
'precision' : precisions ,
661
687
'ap' : ap
662
688
})
663
- pool .close ()
689
+
690
+ if num_imgs > 1 :
691
+ pool .close ()
692
+
664
693
if scale_ranges is not None :
665
694
# shape (num_classes, num_scales)
666
695
all_ap = np .vstack ([cls_result ['ap' ] for cls_result in eval_results ])
0 commit comments