Restore the best model #5812
-
What would be the most lightning way to restore the best model? Either directly after training (in the same script) or for later use (in another script)? Thanks in advance ! |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments
-
You can use the checkpont callback to save the only the best model as described here: https://williamfalcon.github.io/pytorch-lightning/Trainer/Checkpointing/ (note that that doc needs to be updated. Use You can then use the |
Beta Was this translation helpful? Give feedback.
-
in the last version, there is also |
Beta Was this translation helpful? Give feedback.
-
I didn't pay attention, I was using Thank you both for you answers, but what if I want to keep my checkpoints, and still restore the best one automatically, how would I do? |
Beta Was this translation helpful? Give feedback.
-
Right now, I don't think the score is saved with the checkpoint. You'd need to take a look at your logs and manually select the best one. |
Beta Was this translation helpful? Give feedback.
You can use the checkpont callback to save the only the best model as described here: https://williamfalcon.github.io/pytorch-lightning/Trainer/Checkpointing/ (note that that doc needs to be updated. Use
save_top_k=1
instead ofsave_best_only
)You can then use the
load_from_checkpoint
method to restore your checkpoint: https://williamfalcon.github.io/pytorch-lightning/LightningModule/methods/#load_from_metrics