Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request: return best LR without plotting #89

Open
BagelOrb opened this issue Jun 20, 2023 · 1 comment
Open

Request: return best LR without plotting #89

BagelOrb opened this issue Jun 20, 2023 · 1 comment

Comments

@BagelOrb
Copy link

Please make it possible to return the best learning rate without making a plot.

I suggest you refactor some code and pull the calculation of statistics out of the plotting function.

I think all of the statistics should be computed in the range_test function and I think the range_test function should return the optimal learning rate.

@ManuelZ
Copy link

ManuelZ commented Jan 28, 2024

To get the suggested LR:

lrs = np.array(lr_finder.history["lr"])
losses = np.array(lr_finder.history["loss"])

min_grad_idx = None
try:
    min_grad_idx = (np.gradient(np.array(losses))).argmin()
except ValueError:
    print("Failed to compute the gradients, there might not be enough points.")
if min_grad_idx is not None:
    best_lr = lrs[min_grad_idx]

print(f"Best lr:", best_lr)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants