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

Cannot load saved model #1

Open
mansdell opened this issue Jun 10, 2019 · 0 comments
Open

Cannot load saved model #1

mansdell opened this issue Jun 10, 2019 · 0 comments

Comments

@mansdell
Copy link

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant