mirror of
https://github.com/RustyRaptor/incubator-mxnet.git
synced 2026-12-06 01:05:16 -07:00
* python -> Python (fixed capitalization typo) * flavours -> flavors for internal consistency with American spellings. Changed 'good flabors' to specify imperative and symbolic programming, better not to tease the reader * Improved writing of 'History' section * Improved writing of 'History' section * fixed symbol.md doc which previously used deprecated / incorrect mxnet.sym.var instead of the real/working mxnet.sym.Variable * fixed typos and readability in parts of the README.md * removed awkward phrasing about 'flavours' * typo cleanup * Update NEWS.md Fixed typos * adding eval function for combining with , makes for quicker introspection in interactive interpreters * fixed docstrig * fixed docstring, cleaned up whitespace * clean up * Changed code to work with **kwargs, doesn't require dictionary explicitly. This also removes need for clumsy code to handle the case where there are no arguments * fixed too-long lines in the docstring * Update symbol.py * heavily revised docs in symbol.py * lightly revised content in ndarray.py * Update symbol.py * heavier pass for language on ndarray.py * fixed docstring line lengths per lint * fixed string continuation error * Improved docs for (alphabetically) model.py through visualization.py * fixing line-too-long pylint bugs * fixes pylint line length error * improved documentation further by making cosmetic edits to all other files in the Python API
64 lines
1.7 KiB
Python
64 lines
1.7 KiB
Python
# pylint: disable=invalid-name
|
|
"""Learning rate scheduler."""
|
|
|
|
import math
|
|
import logging
|
|
|
|
class LearningRateScheduler(object):
|
|
"""Base class of learning rate scheduler."""
|
|
def __init__(self):
|
|
self.base_lr = 0.01
|
|
|
|
def __call__(self, iteration):
|
|
"""
|
|
Call to schedule current learning rate.
|
|
|
|
Parameters
|
|
----------
|
|
iteration: int
|
|
Current iteration count.
|
|
"""
|
|
raise NotImplementedError("must override this")
|
|
|
|
|
|
class FactorScheduler(LearningRateScheduler):
|
|
"""Reduce learning rate in factor.
|
|
|
|
Parameters
|
|
----------
|
|
step: int
|
|
Schedule learning rate after every round.
|
|
factor: float
|
|
Reduce learning rate factor.
|
|
"""
|
|
def __init__(self, step, factor=0.1):
|
|
super(FactorScheduler, self).__init__()
|
|
if step < 1:
|
|
raise ValueError("Schedule step must be greater or equal than 1 round")
|
|
if factor >= 1.0:
|
|
raise ValueError("Factor must be less than 1 to make lr reduce")
|
|
self.step = step
|
|
self.factor = factor
|
|
self.old_lr = self.base_lr
|
|
self.init = False
|
|
|
|
def __call__(self, iteration):
|
|
"""
|
|
Call to schedule current learning rate.
|
|
|
|
Parameters
|
|
----------
|
|
iteration: int
|
|
Current iteration count.
|
|
"""
|
|
|
|
if not self.init:
|
|
self.init = True
|
|
self.old_lr = self.base_lr
|
|
lr = self.base_lr * math.pow(self.factor, int(iteration / self.step))
|
|
if lr != self.old_lr:
|
|
self.old_lr = lr
|
|
logging.info("At Iteration [%d]: Swith to new learning rate %.5f",
|
|
iteration, lr)
|
|
return lr
|