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

[FEATURE] Early stopping when training #1991

Open
saad-palapa opened this issue Oct 17, 2023 · 1 comment
Open

[FEATURE] Early stopping when training #1991

saad-palapa opened this issue Oct 17, 2023 · 1 comment
Labels
enhancement New feature or request

Comments

@saad-palapa
Copy link

Is your feature request related to a problem? Please describe.
When running the training script, there is no way to stop training early when performance plateaus.

This causes 2 problems:

  • Wasting resources because we continue training as the model does not improve
  • Overfitting since early stopping is a form of regularization

Describe the solution you'd like
I would like to add an early-stopping feature to the training script.

This would involve a few parameters:

  • The metric to monitor
  • Whether to minimize or maximize that metric
  • Number of steps or epochs to wait for an improvement
  • The delta in the metric to determine if it is an improvement

Describe alternatives you've considered
Many other CV training platforms offer early stopping. I would like to have early stopping in TIMM because I prefer this repo over others.

@saad-palapa saad-palapa added the enhancement New feature or request label Oct 17, 2023
@notprime
Copy link

Hi @saad-palapa ,

you could easily modify the train.py script adding your own EarlyStopping method, it's straightforward.
You just have to gather validation losses (eval_metrics, line 813), select the metric you want to monitor (top1 for instance), and use it as a stopping criteria.

You can use this simple yet effective implementation of EarlyStopping:
https://github.com/Bjarten/early-stopping-pytorch/blob/master/pytorchtools.py

There you'll find a simple example on how to use it (in the "Train the Model using Early Stopping" section):
https://github.com/Bjarten/early-stopping-pytorch/blob/master/MNIST_Early_Stopping_example.ipynb

The provided training script in TIMM is just a general script, you have to adapt it to your case :D

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

No branches or pull requests

2 participants