How can I reuse a trained model?

Posted in General by Jaeju Kim Tue Aug 11 2015 12:17:54 GMT+0000 (Coordinated Universal Time)·9·Viewed 4,208 times

Hello. I'm writing a network that predicts the probabilities of each symbol(character) from the previous context. I've written codes for training, and it seems work well. I want to save the total network settings(including trained weights) then reload and use them later. In other words, I want to separate the training from the part that applies actual data to the trained network. Can I do? If so, what should I do? Thank you for maintaining such a nice project, anyway!
Aug 11, 2015

Hey! Yep, the network configuration get saved in the outputs/model_name/config.pkl file (unless you specified a different path), and parameters are normally saved in outputs/model_name/trained_epoch_xx.pkl files. You can use the model.load_params('/path/to/param_file.pkl') after you initialize the model to load existing weights. To create a new model with the same initialization arguments, just load that config.pkl file and use Python's operator on the loaded dictionary (i.e. model = Model(config_dict)). After you initialize and load the model parameters, you can call to produce outputs.

I have an example character-level NER tagger here if you needed more reference:

Let me know if you have any more questions!

Aug 11, 2015

It appears that the markdown parser made the python '**' operator bold. The section that was affected is:

and use Python's ** operator on the loaded dictionary (i.e. model = Model(**config_dict))

marked this as solved
Aug 13, 2015

Thank you for answering me. The example was helpful to me. I've tried several ways to implement including Caffe, Torch, or using Theano directly. Opendeep seems to be the simplest one, and the live plotting is what exactly I've been finding!

Aug 13, 2015

Thanks! Let me know if you have any more feedback, always trying to make it better :)

Oct 16, 2015

I have a question on this
I tried to resue the trained model and I coded like this

dae = DenoisingAutoencoder()
result = dae.load_params('outputs/dae/bee/trained_epoch_1000.pkl')

result is True when I run
Is this correct ? or Can I use pickle to dump it and load it later

Oct 16, 2015

I tried to dump the dae but I got this error

cPickle.PicklingError: Can't pickle <type 'instancemethod'>: attribute lookup builtin.instancemethod failed

Oct 17, 2015

1) Yes that is the correct way to reuse model parameters. The load_params(filename) function returns a success boolean; the model you use will have loaded the params if it returns True. dae in your case should be using the trained_epoch_1000.pkl params.
2) Are you on the master branch? I just tried the code initializing a DenoisingAutoencoder and calling save_param('test_filename.pkl') on the model and it saved fine.

Oct 17, 2015


Markdown is allowed