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

Add best_model_monitor to ModelCheckpoint #4368

Closed
carmocca opened this issue Oct 26, 2020 · 6 comments · Fixed by #4383
Closed

Add best_model_monitor to ModelCheckpoint #4368

carmocca opened this issue Oct 26, 2020 · 6 comments · Fixed by #4383
Labels
feature Is an improvement or enhancement help wanted Open to be worked on

Comments

@carmocca
Copy link
Contributor

Motivation

If I have a directory with many checkpoints, possibly belonging to runs with different monitors, I don't know which metric was tracked by each checkpoint.

Pitch

ckpt = torch.load("saved_model.ckpt")
assert hasattr(ckpt, "checkpoint_callback_best_model_monitor"

Alternatives

Guess If I included the monitor in the checkpoint name, I could parse it to know. But seems much more convenient to add the property.

@carmocca carmocca added feature Is an improvement or enhancement help wanted Open to be worked on labels Oct 26, 2020
@rohitgr7
Copy link
Contributor

another alternative: you can also add that to checkpoint itself in on_save_checkpoint.

@carmocca
Copy link
Contributor Author

Do you mean by overriding it in my LightningModule?

It is an ugly solution because it does not know about any ModelCheckpoints used. Only the trainer knows about them.

So I would need to instantiate my LightningModule with an added checkpoint_callback_monitor parameter in order to do:

def on_save_checkpoint(self, checkpoint):
    checkpoint["checkpoint_callback_best_model_monitor"] = self.checkpoint_callback_monitor

@ananthsub
Copy link
Contributor

@carmocca here

@carmocca
Copy link
Contributor Author

If you guys agree with this issue, I can work on the PR

@ananthsub
Copy link
Contributor

I think it makes sense to add monitor especially since best_model_score is already included. Lightning should track what that score actually represents 😃

@rohitgr7
Copy link
Contributor

Do you mean by overriding it in my LightningModule?

na.. not the LightningModule but ModelCheckpoint, I know it's ugly haha..
IMO I think it's good to have the monitor as well. But need to check whether it is required to load it back or not in on_load_checkpoint.

@carmocca carmocca changed the title Add checkpoint_callback_best_model_monitor to ModelCheckpoint Add best_model_monitor to ModelCheckpoint Oct 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Is an improvement or enhancement help wanted Open to be worked on
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants