szha commented on a change in pull request #9633: Gluon image-classification
example improvement
URL: https://github.com/apache/incubator-mxnet/pull/9633#discussion_r164932515
##########
File path: example/gluon/image_classification.py
##########
@@ -160,23 +207,34 @@ def train(epochs, ctx):
# on all GPUs for better speed on multiple GPUs.
Ls.append(L)
outputs.append(z)
- for L in Ls:
- L.backward()
+ ag.backward(Ls)
trainer.step(batch.data[0].shape[0])
metric.update(label, outputs)
if opt.log_interval and not (i+1)%opt.log_interval:
name, acc = metric.get()
- logging.info('Epoch[%d] Batch [%d]\tSpeed: %f
samples/sec\t%s=%f'%(
- epoch, i, batch_size/(time.time()-btic), name,
acc))
+ msg = ','.join(['%s=%f'%(n, a) for n, a in zip(as_list(name),
as_list(acc))])
+ logger.info('Epoch[%d] Batch [%d]\tSpeed: %f samples/sec\t%s'%(
+ epoch, i, batch_size/(time.time()-btic), msg))
btic = time.time()
name, acc = metric.get()
- logging.info('[Epoch %d] training: %s=%f'%(epoch, name, acc))
- logging.info('[Epoch %d] time cost: %f'%(epoch, time.time()-tic))
- name, val_acc = test(ctx, val_data)
- logging.info('[Epoch %d] validation: %s=%f'%(epoch, name, val_acc))
+ msg = ','.join(['%s=%f'%(n, a) for n, a in zip(as_list(name),
as_list(acc))])
+ logger.info('[Epoch %d] training: %s'%(epoch, msg))
+ logger.info('[Epoch %d] time cost: %f'%(epoch, time.time()-tic))
+ name, val_acc = test(ctx, metric, val_data)
+ val_msg = ','.join(['%s=%f'%(n, a) for n, a in zip(as_list(name),
as_list(val_acc))])
+ logger.info('[Epoch %d] validation: %s'%(epoch, val_msg))
+ top1 = val_acc[0] if isinstance(val_acc, list) else val_acc
Review comment:
can be refactored
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services