Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change duration compute methods #49

Merged
merged 8 commits into from
Jan 19, 2018
Merged
25 changes: 15 additions & 10 deletions fluid/resnet50.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ def run_benchmark(model, args):
buf_size=5120),
batch_size=args.batch_size)

place = core.CPUPlace() if args.device == 'CPU' else core.CUDAPlace(0)
place = core.CPUPlace() if args.device == 'CPU' else core.GPUPlace(0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I remember CUDAPlace is used in the latest PaddlePaddle. Could you refer to the source codes to confirm this.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

exe = fluid.Executor(place)
exe.run(fluid.default_startup_program())

Expand All @@ -209,14 +209,17 @@ def run_benchmark(model, args):
label = np.array(map(lambda x: x[1], data)).astype('int64')
label = label.reshape([-1, 1])

iter = 0
im_num = 0
for pass_id in range(args.pass_num):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

every_pass_loss = []
every_pass_acc = []
accuracy.reset(exe)
if iter == args.iterations:
break
iter = 0
for batch_id, data in enumerate(train_reader()):
if iter == args.skip_batch_num:
if iter < args.skip_batch_num:
iter += 1
continue
if pass_id == 0 and iter == args.skip_batch_num:
start_time = time.time()
Copy link
Contributor

@ranqiu92 ranqiu92 Jan 15, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For all batches in pass 0, this line will be executed. Is this what you want?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

modified

if iter == args.iterations:
break
Expand All @@ -229,16 +232,18 @@ def run_benchmark(model, args):
feed={'data': image,
'label': label},
fetch_list=[avg_cost] + accuracy.metrics)
every_pass_acc.append(acc)
every_pass_loss.append(loss)
pass_acc = accuracy.eval(exe)
print("Iter: %d, loss: %s, acc: %s, pass_acc: %s" %
(iter, str(loss), str(acc), str(pass_acc)))
print("Pass: %d, Iter: %d, loss: %s, acc: %s, pass_acc: %s" %
(pass_id, iter, str(loss), str(acc), str(pass_acc)))
iter += 1
im_num += label.shape[0]

print("Pass: %d, Loss: %f, Accuray: %f\n" %
(pass_id, np.mean(every_pass_loss), np.mean(every_pass_acc)))
duration = time.time() - start_time
im_num = im_num - args.skip_batch_num * args.batch_size
examples_per_sec = im_num / duration
sec_per_batch = duration / (iter - args.skip_batch_num)
sec_per_batch = duration / (iter - args.skip_batch_num) / args.pass_num

print('\nTotal examples: %d, total time: %.5f' % (im_num, duration))
print('%.5f examples/sec, %.5f sec/batch \n' %
Expand Down