1010import cv2
1111from models .faceboxes import FaceBoxes
1212from utils .box_utils import decode
13+ from utils .timer import Timer
1314
1415parser = argparse .ArgumentParser (description = 'FaceBoxes' )
1516
@@ -92,6 +93,8 @@ def load_model(model, pretrained_path):
9293 elif args .dataset == "AFW" :
9394 resize = 1
9495
96+ _t = {'forward_pass' : Timer (), 'misc' : Timer ()}
97+
9598 # testing begin
9699 for i , img_name in enumerate (test_dataset ):
97100 image_path = testset_folder + img_name + '.jpg'
@@ -107,7 +110,10 @@ def load_model(model, pretrained_path):
107110 img = img .cuda ()
108111 scale = scale .cuda ()
109112
113+ _t ['forward_pass' ].tic ()
110114 out = net (img ) # forward pass
115+ _t ['forward_pass' ].toc ()
116+ _t ['misc' ].tic ()
111117 priorbox = PriorBox (cfg , out [2 ], (im_height , im_width ), phase = 'test' )
112118 priors = priorbox .forward ()
113119 if args .cuda :
@@ -136,6 +142,7 @@ def load_model(model, pretrained_path):
136142
137143 # keep top-K faster NMS
138144 dets = dets [:args .keep_top_k , :]
145+ _t ['misc' ].toc ()
139146
140147 # save dets
141148 if args .dataset == "FDDB" :
@@ -159,5 +166,5 @@ def load_model(model, pretrained_path):
159166 ymin += 0.2 * (ymax - ymin + 1 )
160167 score = dets [k , 4 ]
161168 fw .write ('{:s} {:.3f} {:.1f} {:.1f} {:.1f} {:.1f}\n ' .format (img_name , score , xmin , ymin , xmax , ymax ))
162- print ('im_detect: {:d}/{:d}' .format (i + 1 , num_images ))
169+ print ('im_detect: {:d}/{:d} forward_pass_time: {:.4f}s misc: {:.4f}s ' .format (i + 1 , num_images , _t [ 'forward_pass' ]. average_time , _t [ 'misc' ]. average_time ))
163170 fw .close ()
0 commit comments