@@ -23,36 +23,37 @@ def pretty_print(bbox_results):
23
23
))
24
24
25
25
26
- parser = argparse .ArgumentParser (description = "FCOS Object Detector" )
27
- parser .add_argument (
28
- "input_image" ,
29
- help = "path or url to an input image" ,
30
- )
31
- args = parser .parse_args ()
26
+ if __name__ == "__main__" :
27
+ parser = argparse .ArgumentParser (description = "FCOS Object Detector" )
28
+ parser .add_argument (
29
+ "input_image" ,
30
+ help = "path or url to an input image" ,
31
+ )
32
+ args = parser .parse_args ()
32
33
33
- fcos = FCOS (
34
- model_name = "fcos_syncbn_bs32_c128_MNV2_FPN_1x" ,
35
- nms_thresh = 0.6 ,
36
- cpu_only = not torch .cuda .is_available () # if you do not have GPUs, please set cpu_only as True
37
- )
34
+ fcos = FCOS (
35
+ model_name = "fcos_syncbn_bs32_c128_MNV2_FPN_1x" ,
36
+ nms_thresh = 0.6 ,
37
+ cpu_only = not torch .cuda .is_available () # if you do not have GPUs, please set cpu_only as True
38
+ )
38
39
39
- im = io .imread (args .input_image )
40
- assert im .shape [- 1 ] == 3 , "only 3-channel images are supported"
40
+ im = io .imread (args .input_image )
41
+ assert im .shape [- 1 ] == 3 , "only 3-channel images are supported"
41
42
42
- # convert from RGB to BGR because fcos assumes the BRG input image
43
- im = im [..., ::- 1 ].copy ()
43
+ # convert from RGB to BGR because fcos assumes the BRG input image
44
+ im = im [..., ::- 1 ].copy ()
44
45
45
- # resize image to have its shorter size == 800
46
- f = 800.0 / float (min (im .shape [:2 ]))
47
- im = cv2 .resize (im , (0 , 0 ), fx = f , fy = f )
46
+ # resize image to have its shorter size == 800
47
+ f = 800.0 / float (min (im .shape [:2 ]))
48
+ im = cv2 .resize (im , (0 , 0 ), fx = f , fy = f )
48
49
49
- start_time = time .time ()
50
+ start_time = time .time ()
50
51
51
- bbox_results = fcos .detect (im )
52
+ bbox_results = fcos .detect (im )
52
53
53
- inference_time = time .time () - start_time
54
+ inference_time = time .time () - start_time
54
55
55
- pretty_print (bbox_results )
56
- print ("Predicted in {:.2f} seconds." .format (inference_time ))
57
- print ("Press any key to exit..." )
58
- fcos .show_bboxes (im , bbox_results )
56
+ pretty_print (bbox_results )
57
+ print ("Predicted in {:.2f} seconds." .format (inference_time ))
58
+ print ("Press any key to exit..." )
59
+ fcos .show_bboxes (im , bbox_results )
0 commit comments