havakv / pycox

Survival analysis with PyTorch
BSD 2-Clause "Simplified" License
781 stars 180 forks source link

How to save the best model during training #85

Closed chingheng113 closed 3 years ago

chingheng113 commented 3 years ago

Hi, According to this closed issue(https://github.com/havakv/pycox/issues/29), I am able to save the final model after taining. My question is how to save the best model during training (like a callback mechanism), is there any examples? Thank you,

havakv commented 3 years ago

Hi, In the example notebook on the front page 01_introduction.ipynb, we use an EarlyStopping callback that does something like this. As stated in the notebook right above cell 21:

"After termination, the EarlyStopping callback loads the best performing model (in terms of validation loss)."

Alternatively, you can use torchtuples.callbacks.BestWeights (code here) which works the same way as EarlyStopping, just without a stopping criteria.

Does this answer your question?

chingheng113 commented 3 years ago

Yes! Thank you!