dataiku-research / lr_finder_keras_fastai

Experiments comparing keras and fastai implementations of the learning rate finder.
Apache License 2.0
8 stars 0 forks source link

LRRT w/ Validation #7

Closed phelps-matthew closed 3 years ago

phelps-matthew commented 3 years ago

Hi there, very much enjoyed the blog article. I was wondering if you may be able to share the Keras implementations of the LR finder w/ the validation curve as well. Understandably this will take much longer to compute, but based on https://arxiv.org/pdf/1803.09820v2.pdf, the validation loss provides some valuable clues in identifying behavior and for setting the bounds in CLR.

Thank you!

simonamaggio commented 3 years ago

Hi @phelps-matthew, thank you for your interest. I will include this option later in this code, after some cleaning, but in the meanwhile what you need to modify to have the validation curve is:

loss = logs.get('val_loss')
acc = logs.get('val_accuracy')
model.fit_generator(data_gen,
                    steps_per_epoch=NUM_ITERATIONS_PER_EPOCH,
                    epochs=NUM_EPOCHS,
                    callbacks=[lr_finder],
                    shuffle=rnd_batch,
                    validation_steps=NUM_ITERATIONS_PER_EPOCH) # **HERE**
phelps-matthew commented 3 years ago

Thank you kindly! I was able to implement by adding in a model.evaluate portion within on_train_batch_end. As expected, the validation steps is a multiplier on how much longer the learning rate finding takes, but I have found it to be helpful for selecting the best lr range.