-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
Adding a Metric to LightningModule prevents loading of a checkpoint / weights #4361
Comments
Adding model2 = BoringModel2.load_from_checkpoint(checkpoint_path="example.ckpt", strict=False) does allow to load the weights (thank you @ananthsub ), but this will increase the risk of improper variables in your .ckpt's that would have been noticed if Since the metric Accuracy uses default values, I have no idea what |
Using class BoringModelTransfer(LightningModule):
def __init__(self):
super().__init__()
self.boring = BoringModel()
def forward(self, x):
return self.boring(x) You would need to copy all the other functions, such as Also, |
Best approach might be to modify the old checkpoints to make them compatible to a common format. checkpoint = torch.load(path_checkpoint, map_location='cpu')
checkpoint['epoch'] = 0
checkpoint['total_iter_num'] = 0
torch.save(checkpoint, path_new_checkpoint) |
Metrics are simple |
As @SkafteNicki said, this comes down to more of a limitation of If you do not want this behavior when implementing your own metric, you can simply pass Do people think every metric should have a |
🐛 Bug
Adding a Metric like Accuracy prevents the loading of a .ckpt due to missing keys:
Please reproduce using the BoringModel and post here
https://colab.research.google.com/drive/1km0SE2TVRuif6R4uF8vihqUl-FshXu_u?usp=sharing
To Reproduce
Expected behavior
Being able to add new metrics to a model without changing the layers (e.g. in transfer learning settings), but still be able to load the weights of a model without those metrics.
Actual behavior
Environment
Note:
Bugs with code
are solved faster !Colab Notebook
should be madepublic
!IDE
: Please, use our python bug_report_model.py template.Colab Notebook
: Please copy and paste the output from our environment collection script (or fill out the checklist below manually).You can get the script and run it with:
Colab:
Additional context
The text was updated successfully, but these errors were encountered: