szha commented on a change in pull request #9633: Gluon image-classification
example improvement
URL: https://github.com/apache/incubator-mxnet/pull/9633#discussion_r164932389
##########
File path: example/gluon/image_classification.py
##########
@@ -129,27 +164,39 @@ def test(ctx, val_data):
metric.update(label, outputs)
return metric.get()
+def update_learning_rate(lr, trainer, epoch, ratio, steps):
+ """Set the learning rate to the initial value decayed by ratio every N
epochs."""
+ new_lr = lr * (ratio ** int(np.sum(np.array(steps) < epoch)))
+ trainer.set_learning_rate(new_lr)
+ return trainer
+
+def as_list(x):
+ if not isinstance(x, list):
+ return [x]
+ return x
-def train(epochs, ctx):
- if isinstance(ctx, mx.Context):
- ctx = [ctx]
- net.initialize(mx.init.Xavier(magnitude=2), ctx=ctx)
+def train(opt, ctx):
Review comment:
do you intend to add metric argument here too? this way `train` only
involves using these components, which can make the code look simpler.
----------------------------------------------------------------
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