-
Notifications
You must be signed in to change notification settings - Fork 27
Open
Description
When I try to save a trained model, then re-load the saved state so I can apply the model to new data, I get a size mismatch error for the noise in the dropout layer.
I can reproduce the error in your example of fitting a sine function in the sin_x.ipynb notebook. Start from the end of that notebook and do the following:
torch.save(model.state_dict(), 'bnn_model.pth')
model2 = bayesian_model(X.shape[1], 2 * Y.shape[1], [200, 200])
model2.load_state_dict(torch.load('bnn_model.pth'))
This will reproduce the error, which should look like this:
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
<ipython-input-16-0537a1e1603f> in <module>()
----> 1 model2.load_state_dict(torch.load('bnn_model.pth'))
/opt/anaconda36/lib/python3.6/site-packages/torch/nn/modules/module.py in load_state_dict(self, state_dict, strict)
717 if len(error_msgs) > 0:
718 raise RuntimeError('Error(s) in loading state_dict for {}:\n\t{}'.format(
--> 719 self.__class__.__name__, "\n\t".join(error_msgs)))
720
721 def parameters(self):
RuntimeError: Error(s) in loading state_dict for BSequential:
size mismatch for drop_0.noise: copying a param of torch.Size([]) from checkpoint, where the shape is torch.Size([100, 100, 200]) in current model.
size mismatch for drop_1.noise: copying a param of torch.Size([]) from checkpoint, where the shape is torch.Size([100, 100, 200]) in current model.
Is there an alternative method for re-loading a saved model state?
Metadata
Metadata
Assignees
Labels
No labels