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

Error loading weights in old format #214

Closed
tambetm opened this Issue Mar 11, 2016 · 4 comments

Comments

Projects
None yet
2 participants
@tambetm

tambetm commented Mar 11, 2016

When loading pre-trained weights in my DQN implementation I get following error:

2016-03-11 08:21:53,475 Loading weights from snapshots/breakout_77.pkl
2016-03-11 08:21:53,475 Calling deprecated load_weights function.  Use load_params instead
2016-03-11 08:21:53,478 Using old model serialization format. Serialized the model into new format
Traceback (most recent call last):
  File "src/main.py", line 99, in <module>
    net.load_weights(args.load_weights)
  File "/home/tambet/simple_dqn_test/src/deepqnetwork.py", line 178, in load_weights
    self.model.load_weights(load_path)
  File "/home/tambet/neon_test/neon/models/model.py", line 330, in load_weights
    self.load_params(weight_path)
  File "/home/tambet/neon_test/neon/models/model.py", line 320, in load_params
    self.deserialize(load_obj(param_path), load_states=load_states)
  File "/home/tambet/neon_test/neon/models/model.py", line 362, in deserialize
    l.set_params(ps)
  File "/home/tambet/neon_test/neon/layers/layer.py", line 528, in set_params
    if not hasattr(self, key):
TypeError: hasattr(): attribute name must be string

I haven't had time to adapt the code to new API, but even when I do this, I still would like to convert old models into new format. Re-training them would take almost a week.

To reproduce you need to install https://github.com/tambetm/simple_dqn and run ./play.sh snapshots/breakout_77.pkl.

@nervetumer nervetumer self-assigned this Mar 11, 2016

@nervetumer

This comment has been minimized.

Show comment
Hide comment
@nervetumer

nervetumer Mar 11, 2016

Contributor

@tambetm which SHA of neon are you getting this problem with? Also, any chance you know which commit sha the file was created on?

Contributor

nervetumer commented Mar 11, 2016

@tambetm which SHA of neon are you getting this problem with? Also, any chance you know which commit sha the file was created on?

@nervetumer nervetumer added bug and removed bug labels Mar 11, 2016

@nervetumer

This comment has been minimized.

Show comment
Hide comment
@nervetumer

nervetumer Mar 11, 2016

Contributor

@tambetm, it looks like your files are from a very old version of neon which was deprecated and then with the new serialization changes in January, was removed. If you run the script below, it should update your files to the currently deprecated serialization, then you should be able to create current files by loading the weights and serializing the model.

import pickle
with open('breakout_77.pkl', 'r') as fid:
    model_param = pickle.load(fid)

for lay_param in model_param['layer_params_states']:
    w = lay_param['params']
    lay_param['params'] = {'W': w}

with open('breakout_77_new.pkl', 'w') as fid:
    pickle.dump(model_param, fid)

I'm getting a core dump when I try to run ./play.sh snapshots/breakout_77.pkl
so I could not test this.

Contributor

nervetumer commented Mar 11, 2016

@tambetm, it looks like your files are from a very old version of neon which was deprecated and then with the new serialization changes in January, was removed. If you run the script below, it should update your files to the currently deprecated serialization, then you should be able to create current files by loading the weights and serializing the model.

import pickle
with open('breakout_77.pkl', 'r') as fid:
    model_param = pickle.load(fid)

for lay_param in model_param['layer_params_states']:
    w = lay_param['params']
    lay_param['params'] = {'W': w}

with open('breakout_77_new.pkl', 'w') as fid:
    pickle.dump(model_param, fid)

I'm getting a core dump when I try to run ./play.sh snapshots/breakout_77.pkl
so I could not test this.

@tambetm

This comment has been minimized.

Show comment
Hide comment
@tambetm

tambetm Mar 11, 2016

Thanks a lot @nervetumer, that did the trick! I would be happy to update my code, once #153 gets fixed. Any news with this?

tambetm commented Mar 11, 2016

Thanks a lot @nervetumer, that did the trick! I would be happy to update my code, once #153 gets fixed. Any news with this?

@tambetm tambetm closed this Mar 11, 2016

@nervetumer

This comment has been minimized.

Show comment
Hide comment
@nervetumer

nervetumer Mar 11, 2016

Contributor

We had some changes coming that would make the offending lines unnecessary. I'll check to see if we can remove that lines so we can retest your model.

Contributor

nervetumer commented Mar 11, 2016

We had some changes coming that would make the offending lines unnecessary. I'll check to see if we can remove that lines so we can retest your model.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment