5050def parse_args ():
5151 parser = argparse .ArgumentParser (description = 'paddle-rec run' )
5252 parser .add_argument ("-m" , "--config_yaml" , type = str )
53+ parser .add_argument ("-o" , "--opt" , nargs = '*' , type = str )
5354 args = parser .parse_args ()
5455 args .abs_dir = os .path .dirname (os .path .abspath (args .config_yaml ))
5556 args .config_yaml = get_abs_model (args .config_yaml )
@@ -62,20 +63,28 @@ def main(args):
6263 config = load_yaml (args .config_yaml )
6364 dy_model_class = load_dy_model_class (args .abs_dir )
6465 config ["config_abs_dir" ] = args .abs_dir
66+ # modify config from command
67+ if args .opt :
68+ for parameter in args .opt :
69+ parameter = parameter .strip ()
70+ key , value = parameter .split ("=" )
71+ config [key ] = value
72+
6573 # tools.vars
6674 use_gpu = config .get ("runner.use_gpu" , True )
6775 use_visual = config .get ("runner.use_visual" , False )
6876 test_data_dir = config .get ("runner.test_data_dir" , None )
6977 print_interval = config .get ("runner.print_interval" , None )
78+ infer_batch_size = config .get ("runner.infer_batch_size" , None )
7079 model_load_path = config .get ("runner.infer_load_path" , "model_output" )
7180 start_epoch = config .get ("runner.infer_start_epoch" , 0 )
7281 end_epoch = config .get ("runner.infer_end_epoch" , 10 )
7382
7483 logger .info ("**************common.configs**********" )
7584 logger .info (
76- "use_gpu: {}, use_visual: {}, test_data_dir: {}, start_epoch: {}, end_epoch: {}, print_interval: {}, model_load_path: {}" .
77- format (use_gpu , use_visual , test_data_dir , start_epoch , end_epoch ,
78- print_interval , model_load_path ))
85+ "use_gpu: {}, use_visual: {}, infer_batch_size: {}, test_data_dir: {}, start_epoch: {}, end_epoch: {}, print_interval: {}, model_load_path: {}" .
86+ format (use_gpu , use_visual , infer_batch_size , test_data_dir ,
87+ start_epoch , end_epoch , print_interval , model_load_path ))
7988 logger .info ("**************common.configs**********" )
8089
8190 place = paddle .set_device ('gpu' if use_gpu else 'cpu' )
@@ -105,12 +114,20 @@ def main(args):
105114 model_path = os .path .join (model_load_path , str (epoch_id ))
106115 load_model (model_path , dy_model )
107116 dy_model .eval ()
117+ infer_reader_cost = 0.0
118+ infer_run_cost = 0.0
119+ reader_start = time .time ()
120+
108121 for batch_id , batch in enumerate (test_dataloader ()):
122+ infer_reader_cost += time .time () - reader_start
123+ infer_start = time .time ()
109124 batch_size = len (batch [0 ])
110125
111126 metric_list , tensor_print_dict = dy_model_class .infer_forward (
112127 dy_model , metric_list , batch , config )
113128
129+ infer_run_cost += time .time () - infer_start
130+
114131 if batch_id % print_interval == 0 :
115132 tensor_print_str = ""
116133 if tensor_print_dict is not None :
@@ -133,13 +150,19 @@ def main(args):
133150 tag = "infer/" + metric_list_name [metric_id ],
134151 step = step_num ,
135152 value = metric_list [metric_id ].accumulate ())
136- logger .info ("epoch: {}, batch_id: {}, " .format (
137- epoch_id , batch_id ) + metric_str + tensor_print_str +
138- " speed: {:.2f} ins/s" .format (
139- print_interval * batch_size / (time .time (
140- ) - interval_begin )))
153+ logger .info (
154+ "epoch: {}, batch_id: {}, " .format (
155+ epoch_id , batch_id ) + metric_str + tensor_print_str +
156+ " avg_reader_cost: {:.5f} sec, avg_batch_cost: {:.5f} sec, avg_samples: {:.5f}, ips: {:.2f} ins/s" .
157+ format (infer_reader_cost / print_interval , (
158+ infer_reader_cost + infer_run_cost ) / print_interval ,
159+ infer_batch_size , print_interval * batch_size / (
160+ time .time () - interval_begin )))
141161 interval_begin = time .time ()
162+ infer_reader_cost = 0.0
163+ infer_run_cost = 0.0
142164 step_num = step_num + 1
165+ reader_start = time .time ()
143166
144167 metric_str = ""
145168 for metric_id in range (len (metric_list_name )):
0 commit comments