Skip to content

Commit eb0e59e

Browse files
authored
Merge pull request #8 from pooyadavoodi/speed_metric
Print speed (img/sec) in imagenet example
2 parents ea93767 + dcda3b5 commit eb0e59e

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

examples/imagenet/main.py

+10-2
Original file line numberDiff line numberDiff line change
@@ -310,11 +310,15 @@ def train(train_loader, model, criterion, optimizer, epoch):
310310
if args.rank == 0 and i % args.print_freq == 0 and i > 1:
311311
print('Epoch: [{0}][{1}/{2}]\t'
312312
'Time {batch_time.val:.3f} ({batch_time.avg:.3f})\t'
313+
'Speed {3:.3f} ({4:.3f})\t'
313314
'Data {data_time.val:.3f} ({data_time.avg:.3f})\t'
314315
'Loss {loss.val:.4f} ({loss.avg:.4f})\t'
315316
'Prec@1 {top1.val:.3f} ({top1.avg:.3f})\t'
316317
'Prec@5 {top5.val:.3f} ({top5.avg:.3f})'.format(
317-
epoch, i, len(train_loader), batch_time=batch_time,
318+
epoch, i, len(train_loader),
319+
args.world_size * args.batch_size / batch_time.val,
320+
args.world_size * args.batch_size / batch_time.avg,
321+
batch_time=batch_time,
318322
data_time=data_time, loss=losses, top1=top1, top5=top5))
319323

320324

@@ -363,10 +367,14 @@ def validate(val_loader, model, criterion):
363367
if args.rank == 0 and i % args.print_freq == 0:
364368
print('Test: [{0}/{1}]\t'
365369
'Time {batch_time.val:.3f} ({batch_time.avg:.3f})\t'
370+
'Speed {2:.3f} ({3:.3f})\t'
366371
'Loss {loss.val:.4f} ({loss.avg:.4f})\t'
367372
'Prec@1 {top1.val:.3f} ({top1.avg:.3f})\t'
368373
'Prec@5 {top5.val:.3f} ({top5.avg:.3f})'.format(
369-
i, len(val_loader), batch_time=batch_time, loss=losses,
374+
i, len(val_loader),
375+
args.world_size * args.batch_size / batch_time.val,
376+
args.world_size * args.batch_size / batch_time.avg,
377+
batch_time=batch_time, loss=losses,
370378
top1=top1, top5=top5))
371379

372380
input, target = prefetcher.next()

0 commit comments

Comments
 (0)