Skip to content

EarlyStopping - Torch Handler #654

Answered by Nic-Ma
HripsimeS asked this question in Q&A
Apr 11, 2022 · 2 comments · 23 replies
Discussion options

You must be logged in to vote

Hi @HripsimeS ,

Here are 2 simple examples for the usage of EarlyStopping handler:

  1. How can I apply “EarlyStop” logic based on the loss value or validation metrics during model training?
    To use loss value to execute EarlyStop, attach the handler to trainer, added “-” negative value because smaller loss is better:
handler = EarlyStopHandler(
    trainer=trainer,
    patience=100,
    score_function=lambda x: -x.state.output['loss'],
    epoch_level=False,
)
  1. To use validation metrics(for example: MeanDice) to execute EarlyStop, just attach the handler to the evaluator:
handler = EarlyStopHandler(
    trainer=trainer,
    patience=1,
    score_function=lambda x: x.state.metrics['val_mean_…

Replies: 2 comments 23 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
23 replies
@Nic-Ma
Comment options

@HripsimeS
Comment options

@Nic-Ma
Comment options

@HripsimeS
Comment options

@Nic-Ma
Comment options

Answer selected by HripsimeS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants