Coder Social home page Coder Social logo

lrfinder's People

Contributors

idroz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

lrfinder's Issues

Some thoughts

Hey Lr_Finder Team,

First let me say great implementation of the lr range finder algorithm, it helped me a lot, but let me allow to share some issues I had with it.

Since you adapt the learning rate after each batch the structure of the dataset has a huge impact on the loss-learning rate curve. In my case even with a shuffled dataset I got this periodic loss pattern (when I disabled the early stopping condition:

#if batch > 5 and (math.isnan(loss) or loss > self.best_loss * 4):

I show you what I mean:

here with 100 epochs
image

and here with your default value of 5 epochs
image

It gets even worser if I increase the search interval:
image

When I searched for the best lr it resulted always in a huge different best_learning rates with some exponential factor to the power of 10.

But when I use the the whole epoch not only a subset of batch for loss calculation this results in that smoothed learning rate loss graph:

image

I also reseted the weights after each epoch, since the weights are getting better and better adapted to the problem over time and also influence the loss and this would result that the loss values might not be comparable.

in find method:
self.lr_mult = float(end_lr) / float(start_lr) ** (float(1) / float(epochs)) self.initial_weights = self.model.get_weights() callback = LambdaCallback(on_epoch_end=lambda epoch, logs: self.on_epoch_end(epoch, logs))

`
def on_epoch_end(self, epoch, logs):
# use the whole epoch instead of a small(er) batch since the
# subsequential selection of data might have an influence on the loss
# lr = K.get_value(self.model.optimizer.lr)

    self.curr_lr = self.model.optimizer.lr.warm_lr.initial_learning_rate

    loss = logs['loss']
    self.losses.append(loss)

    # if batch > 5 and (math.isnan(loss) or loss > self.best_loss * 4):
    #     print("stop training")
    #     self.model.stop_training = True
    #     return

    if loss < self.best_loss:
        self.best_loss = loss

    self.curr_lr *= self.lr_mult
    # lr.warm_lr.initial_learning_rate = self.curr_lr
    self.learning_rates.append(self.curr_lr)

    self.model.optimizer.lr.warm_lr.initial_learning_rate = self.curr_lr
    # K.set_value(self.model.optimizer.lr, lr)

    # reset weights after each epoch to erase the influence of better weights on the loss value
    self.model.set_weights(self.initial_weights)

`
please note that I use a custom learning rate scheduler class, therefore my learning rate adaption code differs a little from yours.

Cheers.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.