@@ -123,32 +123,32 @@ def run_benchmark(model, args):
123123 train_reader = paddle .batch (
124124 paddle .dataset .mnist .train (), batch_size = args .batch_size )
125125
126- place = core .CPUPlace ()
126+ place = core .CPUPlace () if args . device == 'CPU' else core . CUDAPlace ( 0 )
127127 exe = fluid .Executor (place )
128128
129129 exe .run (fluid .default_startup_program ())
130130
131131 for pass_id in range (args .pass_num ):
132132 accuracy .reset (exe )
133- pass_start = time .clock ()
133+ pass_start = time .time ()
134134 for batch_id , data in enumerate (train_reader ()):
135135 img_data = np .array (
136136 map (lambda x : x [0 ].reshape ([1 , 28 , 28 ]), data )).astype (DTYPE )
137137 y_data = np .array (map (lambda x : x [1 ], data )).astype ("int64" )
138138 y_data = y_data .reshape ([len (y_data ), 1 ])
139139
140- start = time .clock ()
140+ start = time .time ()
141141 outs = exe .run (fluid .default_main_program (),
142142 feed = {"pixel" : img_data ,
143143 "label" : y_data },
144144 fetch_list = [avg_cost ] + accuracy .metrics )
145- end = time .clock ()
145+ end = time .time ()
146146 loss = np .array (outs [0 ])
147147 acc = np .array (outs [1 ])
148148 print ("pass=%d, batch=%d, loss=%f, error=%f, elapse=%f" %
149149 (pass_id , batch_id , loss , 1 - acc , (end - start ) / 1000 ))
150150
151- pass_end = time .clock ()
151+ pass_end = time .time ()
152152 test_avg_acc = eval_test (exe , accuracy , avg_cost )
153153 pass_acc = accuracy .eval (exe )
154154 print ("pass=%d, test_avg_acc=%f, test_avg_acc=%f, elapse=%f" %
0 commit comments